Пример #1
0
	bool CompareLines(const std::string& message, const std::string& historyline, unsigned int trigger)
	{
		if (message == historyline)
			return true;
		else if (trigger)
			return (Levenshtein(message, historyline) <= trigger);

		return false;
	}
Пример #2
0
int main(int argc, char *argv[])
{
    FILE *fp;
    int i = 0;
    char line[MAX_LAST_NAME_SIZE];
    struct timespec start, end;
    double cpu_time1, cpu_time2=0;

    /* check file opening */
    fp = fopen(DICT_FILE, "r");
    if (fp == NULL) {
        printf("cannot open the file\n");
        return -1;
    }

    /* build the entry */
    PHONEBOOK.initialize();

    printf("size of entry : %lu bytes\n", sizeof(entry));

#if defined(__GNUC__)
    __builtin___clear_cache((char *) pHead, (char *) pHead + sizeof(entry));
#endif
    clock_gettime(CLOCK_REALTIME, &start);
    while (fgets(line, sizeof(line), fp)) {
        while (line[i] != '\0')
            i++;
        line[i - 1] = '\0';
        i = 0;
        PHONEBOOK.addNode(line,e);
    }

    clock_gettime(CLOCK_REALTIME, &end);
    cpu_time1 = diff_in_second(start, end);

    /* close file as soon as possible */
    fclose(fp);

    /* the givn last name to find */
    char input[INPUT_SIZE][MAX_LAST_NAME_SIZE] = {"uninvolved","zyxel","whiteshank",
                                                  "odontomous", "pungoteague",
                                                  "reweighted", "xiphisternal", "yakattalo"
                                                 };

    for( i = 0; i < INPUT_SIZE; i++ ) {

        char in[MAX_LAST_NAME_SIZE];
        PHONEBOOK.get_cmp_buf(input[i],in);
        PHONEBOOK.moveNode();

        /*Get compress input value*/
        assert(PHONEBOOK.findName(input[i], e) &&
               "Did you implement findName() in " IMPL "?");

#ifndef FUZZY_SEARCH
        assert(0 == strcmp(PHONEBOOK.findName(input[i], e)->lastName, in));
#endif

#if defined(__GNUC__)
        __builtin___clear_cache((char *) pHead, (char *) pHead + sizeof(entry));
#endif
        /* compute the execution time */
        clock_gettime(CLOCK_REALTIME, &start);
        entry *result = PHONEBOOK.findName(input[i], e);

#ifdef SHOW_RESULT
        if(0 == strcmp(result -> lastName,in)) {
            //printf("Find %s\n",input[i]);
        } else {
            char output[MAX_LAST_NAME_SIZE];
            int count = 0;
            int input_len = strlen(in);
            int result_len,max_len,r;
            float radio;
            while (result != NULL) {
                decompress(result->lastName,output);
                result_len = strlen(output);
                if(abs(result_len - input_len) <= STRING_COMPARISON_LENGTH) {
                    max_len = (result_len < input_len) ? input_len : result_len;
                    r = Levenshtein(output,in);
                    radio = 1.0 - ((float)r) / max_len;
                    if(radio > STRING_COMPARISON_THRESHOLD) {
                        //printf("Simular Result : %s \t result : %d \t radio : %.2f \n",result->lastName,r,radio);
                        count++;
                    }
                }
                result = result -> pNext;
            }
            //printf("Candidate count is %d \n",count);
        }
#endif
        clock_gettime(CLOCK_REALTIME, &end);
        cpu_time2 += diff_in_second(start, end);
    }
    printf("execution time of append() : %lf sec\n", cpu_time1);
    printf("execution time of findName() : %lf sec\n", cpu_time2);

    /* FIXME: release all allocated entries */
    PHONEBOOK.release();

    return 0;
}