コード例 #1
0
ファイル: lsh_dfe.cpp プロジェクト: Terranlee/LSH
    void LSH_DFE::lsh_main_function(){
        // add this if you want to use LMEM
        //load_to_LMEM();

        cout<<"----------check accuracy of LSH using dfe----------"<<endl;
        // compare the result of LSH using CPU and DFE
        hash_generate();
        rehash_data_projection();
        rehash_data_projection_dfe();
        compare_hash_result();
        cout<<"----------end of check accuracy----------"<<endl;

        cout<<"----------test performance of LSH using dfe----------"<<endl;
        // continuesly do locality sensitive hashing for num_iter times to increase recall rate
        int num_iter = 20;
        
        float begin = get_clock();
        for(int i=0; i<num_iter; i++){
            hash_generate();
            rehash_data_projection_dfe();
        }
        cout<<get_clock() - begin<<endl;

        begin = get_clock();
        for(int i=0; i<num_iter; i++){
            //hash_generate();
            rehash_data_projection();
        }
        cout<<get_clock() - begin<<endl; 
        cout<<"----------end test performance of LSH using dfe----------"<<endl;   
    }
コード例 #2
0
ファイル: task.c プロジェクト: PeterJohansson/speedy
/*!
 * Creates a task which encapsulates a service.
 * The reason for this is to make it possible to observe services and to track
 * dependencies. A task can be both an observer and a subject since it uses
 * C inheritance from the \c struct \c subject_t.
 *
 * \param service - A service that is going to be encapsulated into a task.
 *
 * \return A task which encapsulates a service.
 */
task_t * task_create(struct service_t *service, struct task_handler_t *handler)
{
    if (service->name != NULL) {
        task_t * this_ptr = (task_t*) malloc(sizeof(task_t));

        if (this_ptr != NULL) {
            this_ptr->task_id = hash_generate(service->name);
            this_ptr->dependency_queue = NULL;
            this_ptr->service = service;
            this_ptr->task_handler = handler;
            this_ptr->counter = 0;
            subject_init((subject_t*) this_ptr);
            observer_set_notify((observer_t*) this_ptr, task_notify);

            /* Check if there is a provides string, if there isn't any provides
             * string, use the task name instead for the generated id. */
            if (service->provides != NULL) {
                this_ptr->provides_id = hash_generate(service->provides);
            } else {
                this_ptr->provides_id = this_ptr->task_id;
            }

            if (service->dependency != NULL) {
                char **dependency_arg = (char**) service->dependency;
                task_dependency_t *dependency;

                this_ptr->dependency_queue = queue_create();

                while (*dependency_arg != NULL) {

                    printf("%s dep: %s\n",service->name, *dependency_arg);
                    dependency = (task_dependency_t*) malloc(sizeof(
                                  task_dependency_t));

                    dependency->name = *dependency_arg;
                    dependency->id = hash_generate(dependency->name);
                    dependency->task = NULL;

                    queue_push(this_ptr->dependency_queue, dependency);

                    dependency_arg++;
                }
            }
        }
        return this_ptr;
    }
    return NULL;
}
コード例 #3
0
ファイル: str.c プロジェクト: OS2World/DEV-UNIX-UTIL-Cook
string_ty *
str_n_from_c(const char *s, size_t length)
{
    str_hash_ty     hash;
    str_hash_ty     idx;
    string_ty       *p;

    hash = hash_generate(s, length);

#ifdef DEBUG
    if (!hash_table)
	fatal_raw("you must call str_initialize early in main()");
#endif
    idx = hash & hash_mask;
    assert(idx < hash_modulus);

    for (p = hash_table[idx]; p; p = p->str_next)
    {
	if
	(
	    p->str_hash == hash
	&&
	    p->str_length == length
	&&
	    0 == memcmp(p->str_text, s, length)
	)
	{
	    p->str_references++;
	    return p;
	}
    }

    p = mem_alloc(sizeof(string_ty) + length);
    p->str_hash = hash;
    p->str_length = length;
    p->str_references = 1;
    p->str_next = hash_table[idx];
    hash_table[idx] = p;
#if 0
    /* silence purify */
    {
	    /*
	     * probably sizeof(int) bytes,
	     * but is compiler dependent
	     */
	    size_t n = sizeof(string_ty) - offsetof(string_ty, str_text);
	    memset(p->str_text, 0, n);
    }
#endif
    memcpy(p->str_text, s, length);
    p->str_text[length] = 0;

    hash_load++;
    if (hash_load * 10 > hash_modulus * 8)
	split();
    return p;
}
コード例 #4
0
ファイル: str.c プロジェクト: OS2World/DEV-UNIX-UTIL-Cook
int
str_valid(string_ty *s)
{
return
(
    s->str_references > 0
&&
    strlen(s->str_text) == s->str_length
&&
    s->str_hash == hash_generate(s->str_text, s->str_length)
);
}