Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	char opt;
	char mode = 0;
	char *filename = NULL;
	char *key = NULL;
	
	while ((opt = getopt_long(argc, argv, "odsw", options, NULL))
		       != -1) {
		switch (opt) {
			case 'o':
				mode = 'o';
				break;
			case 'd':
				mode = 'd';
				break;
			case 's':
				mode = 's';
				break;
			case 'w':
				mode = 'w';
				break;
			default:
				print_usage(argv[0]);
		}
	}
	if (!mode)
		print_usage(argv[0]);
	
	if (optind >= argc)
		print_usage(argv[0]);
	filename = argv[optind];
	
	if (mode == 's' || mode == 'w') {
		if (optind+1 >= argc)
			print_usage(argv[0]);
		key = argv[optind+1];
	}
	
	switch(mode) {
		case 'o':
			write_index(filename);
			break;
		case 'd':
			dump_index(filename);
			break;
		case 's':
			search_index(filename, key);
			break;
		case 'w':
			searchwild_index(filename, key);
			break;
	}
	
	return 0;
}
Ejemplo n.º 2
0
int qqwry_get_location_by_long(char *addr1,char *addr2,const uint32_t ip,FILE *qqwry_file) {
    //printf("%u",ip);
    unsigned char data_index_bytes[3];
    uint32_t data_index;
    uint32_t addr2_offset;
    unsigned char c;

    if (!qqwry_file) {
        return 0;
    }
    fseek(qqwry_file,0,SEEK_SET);
    data_index = search_index(ip,qqwry_file);
    //fprintf(stderr,"index:%u:%u\n",ftell(qqwry_file),data_index);

    /*ip 4 + mode byte 1*/
    fseek(qqwry_file,data_index+4,SEEK_SET);
    c=fgetc(qqwry_file);
    if (c==REDIRECT_TYPE_1) {
        fread(data_index_bytes,3,1,qqwry_file);
        data_index=LE_24(&data_index_bytes[0]);
        fseek(qqwry_file,data_index,SEEK_SET);
        c=fgetc(qqwry_file);
        /*制造一个假的4bytes位移,抵充ip*/
        data_index-=4;
    }

    if (c==REDIRECT_TYPE_2) {
        /*
         * ip 4 + mode byte 1 + addr1 offset 3
         * 这里ip的4个bytes不一定是真的,有可能是上一条注释里提到的情况
         */
        addr2_offset=data_index+8;
        fread(data_index_bytes,3,1,qqwry_file);

        data_index=LE_24(&data_index_bytes[0]);
        fseek(qqwry_file,data_index,SEEK_SET);
        while ((c=fgetc(qqwry_file))) {
            addr1[strlen(addr1)]=c;
        }
        readOrJumpRead(addr2,qqwry_file,addr2_offset);
    } else {
        addr1[strlen(addr1)]=c;
        while ((c=fgetc(qqwry_file))) {
            addr1[strlen(addr1)]=c;
        }
        readOrJumpRead(addr2,qqwry_file,0);
    }
    if (is_cz88(addr1)) {
        addr1[0]='\0';
    }
    if (is_cz88(addr2)) {
        addr2[0]='\0';
    }
    return 1;
}
Ejemplo n.º 3
0
int		main(void)
{
	t_node		*tree;
	int			val;

	tree = init_node();
	val = build_index(&tree);
	if (val)
		search_index(tree);
	free_tree(&tree);
	return (0);
}
Ejemplo n.º 4
0
static void
make_field(struct hpack_field *fld, const char *line)
{
	const char *sep, *val;
	char *nam, *tmp;
	size_t idx;

	memset(fld, 0, sizeof *fld);

	sep = strchr(line + 1, ':');
	val = sep + 1;
	while (*val == ' ' || *val == '\t')
		val++;

	fld->nam = strndup(line, sep - line);
	fld->val = strdup(val);

	nam = fld->nam;
	while (*nam) {
		*nam = tolower(*nam);
		nam++;
	}

	tmp = strchr(fld->val, '\n');
	*tmp = '\0';

	idx = search_index(fld->nam, fld->val);

	if (idx == 0) {
		/* not in the cache? insert it */
		fld->flg = HPACK_FLG_TYP_DYN;
		return;
	}

	if (strcmp(fld->val, dumb_idx[idx].val)) {
		/* only the name is in the cache? use it */
		fld->flg = HPACK_FLG_TYP_DYN | HPACK_FLG_NAM_IDX;
		fld->nam_idx = idx;
		return;
	}

	fld->flg = HPACK_FLG_TYP_IDX;
	fld->idx = idx;
}
Ejemplo n.º 5
0
int main(int argc, void *argv) {
    load_stopwords();
    index_p index = load_index();

    int exit = 0;
    while (!exit) {
        printf(" > ");
        char *command = read_line(stdin);

        if (!strcmp(command, "exit")) {
            // exit command
            exit = 1;
            printf("Exit requested..\n");

		} else if (!strcmp(command, "rebuild index")) {
            // rebuild index command
            rebuild_index(index);
		} else if (starts_with(command, "search for ")) {
            // search for <search_query> command
            char *query = (char *) malloc(strlen(command) - 10);
            memcpy(query, command+11, strlen(command) - 10);

            index_p result = search_index(&index, query);

            printf("Results (showing no more than 10, there might be more):\n");
            if (result) {
                // print result
                int count = 0;
                indexed_word_p w = result->words;
                if (!w) {
                    printf("No documents found for search term %s\n", query);
                }

                while (w) {
                    printf("Documents containing %s:\n", w->stem);

                    int i;
                    for (i = 0; i < w->nr_docs; i++, count++) {
                        printf(" [%d] %s\n", count, result->documents[w->documents[i].id].name);
                    }

                    w = w->next;
                }

                close_index(result);
            } else {
                printf("No documents found for search term %s\n", query);
            }

            free(query);

        } else if (starts_with(command, "add file ")) {
            // add file <file> command
            char *file = (char*) malloc(strlen(command) - 8);
            memcpy(file, command+9, strlen(command) - 8);

			index = add_file(index, file);
            free(file);

        } else if (starts_with(command, "remove file ")) {
            // remove file <file> command
            char *file = (char*) malloc(strlen(command) - 11);
            memcpy(file, command+12, strlen(command) - 11);

            // obtain document id a.k.a. index in filebase
            int doc_id = find_str(&index->documents[0].name, sizeof(indexed_document_t), file, 0, index->nr_docs - 1);

            if (doc_id < 0) {
                printf("Error: %s is not in the filebase!\n", file);
            } else {
                remove_file(index, doc_id);
            }

            free(file);
        }

        free(command);
    }

    // release memory
    release_stopwords();
    close_index(index);

    return 0;
}
Ejemplo n.º 6
0
  return sym_id;
}


//================================================================
/*! constructor

  @param  vm	pointer to VM.
  @param  str	String
  @return 	symbol object
*/
mrbc_value mrbc_symbol_new(struct VM *vm, const char *str)
{
  mrbc_value ret = {.tt = MRBC_TT_SYMBOL};
  uint16_t h = calc_hash(str);
  mrbc_sym sym_id = search_index(h, str);

  if( sym_id >= 0 ) {
    ret.i = sym_id;
    return ret;		// already exist.
  }

  // create symbol object dynamically.
  int size = strlen(str) + 1;
  char *buf = mrbc_raw_alloc(size);
  if( buf == NULL ) return ret;		// ENOMEM raise?

  memcpy(buf, str, size);
  ret.i = add_index( h, buf );

  return ret;
int EBGM_FaceComparison(int total_trainface,int train_feature_count[], double train_gabor_feature[][500][41][2], 
						int probe_feature_count,double Probe_feature_Vectors[][41][2], int candidate_index[])
{
	int i,j,k,m;
	int MaxSimilarity_count[Total_train_face]={0};
	double OveralSimilarity[Total_train_face]={0.0};
	double temp_max_similarity=0.0;
	double point_peak_similarity=0.0;
	int max_similarity_index=0;

	double similarity=0.0;
	double similarity_matrix[500][Total_train_face]={0.0};
	double temp_MaxSimilarity_count=0.0,temp_feature_count=0.0;

	double thresh_distance=8.0;
	double probe_xcoordiante;
	double probe_ycoordiante;
	double train_xcoordiante;
	double train_ycoordiante;
	double distance=0.0;
	double last_similarity=0.0;
	double dotproduct=0.0;
	double train_feature_sqr=0.0;
	double probe_feature_sqr=0.0;
	int temp_index,real_index;
	int new_candidate_index[Total_train_face];
	double copy_OveralSimilarity[Total_train_face]={0.0};
	double temp_OveralSimilarity;

	double temp_Similarity;
	double copy_Similarity[Total_train_face]={0.0};
	double index_Similarity[Total_train_face]={0.0};


	for (i=0;i<probe_feature_count;i++)
	{
		probe_xcoordiante=Probe_feature_Vectors[i][0][0];
		probe_ycoordiante=Probe_feature_Vectors[i][0][1];
		for (j=0;j<total_trainface;j++)
		{
			last_similarity=0.0;
			for (k=0;k<train_feature_count[j];k++)
			{
				similarity=0.0;
				train_xcoordiante=train_gabor_feature[j][k][0][0];
				train_ycoordiante=train_gabor_feature[j][k][0][1];
				distance=sqrt((train_xcoordiante-probe_xcoordiante)*(train_xcoordiante-probe_xcoordiante)+(train_ycoordiante-probe_ycoordiante)*(train_ycoordiante-probe_ycoordiante));
				if (distance<=thresh_distance)
				{
					dotproduct=0.0;
					train_feature_sqr=0.0;
					probe_feature_sqr=0.0;
					for (m=1;m<41;m++)  //the first one is position information
					{
						dotproduct=dotproduct+sqrt(complex_modulus(train_gabor_feature[j][k][m]))*sqrt(complex_modulus(Probe_feature_Vectors[i][m]));
						train_feature_sqr = train_feature_sqr + complex_modulus(train_gabor_feature[j][k][m]);
						probe_feature_sqr = probe_feature_sqr + complex_modulus(Probe_feature_Vectors[i][m]);
					}
					similarity=dotproduct/sqrt(train_feature_sqr*probe_feature_sqr);
					if (similarity>last_similarity)
					{
						similarity_matrix[i][j]=similarity;
						last_similarity=similarity;
					}
				}
			}
		}
	}

	for (i=0;i<probe_feature_count;i++)
	{
		memcpy(copy_Similarity,similarity_matrix[i],total_trainface*sizeof(double));
		memcpy(index_Similarity,similarity_matrix[i],total_trainface*sizeof(double));
		for (j=total_trainface;j>total_trainface-1;j--)
		{
			temp_Similarity=randomized_selection(copy_Similarity,0,total_trainface-1,j-1);
			temp_index=search_index(index_Similarity,total_trainface,temp_Similarity);
			MaxSimilarity_count[temp_index]++;
		}
	}

	for (i=0;i<total_trainface;i++)
	{
		temp_MaxSimilarity_count=MaxSimilarity_count[i];
		temp_feature_count=train_feature_count[i];
		OveralSimilarity[i]= temp_MaxSimilarity_count/temp_feature_count;
	}

	memcpy(copy_OveralSimilarity,OveralSimilarity,Total_train_face*sizeof(double));

 	for (i=total_trainface;i>0;i--) //Only find the active rankings
	{
		temp_OveralSimilarity=randomized_selection(copy_OveralSimilarity,0,total_trainface-1,i-1);
		temp_index=search_index(OveralSimilarity,total_trainface,temp_OveralSimilarity);
		real_index=candidate_index[temp_index];
		new_candidate_index[total_trainface-i]=real_index;
	}
	memcpy(candidate_index,new_candidate_index,total_trainface*sizeof(int));

	max_similarity_index=new_candidate_index[0]; //The first one is the index of the max
	return max_similarity_index;
}