Ejemplo n.º 1
0
void test_set_operations(){
	set_t *even1 = new_set(10);
	set_t *even2 = new_set(10);
	set_t *odd  = new_set(10);
	
	int i;
	for (i=0; i < 10; i++){
		set_put(even1, 2*i);
		set_put(even2, 2*i);
		set_put(odd, 2*i+1);
	}
	
	set_union(even1, odd);
	assert(set_size(even1) == 20);
	
	set_difference(even2, odd);
	assert(set_size(even2) == 10);
	
	set_intersection(even2, odd);
	assert(set_size(even2) == 0);
	
	set_print(even1); printf("\n");
	set_optimize(even1);
	set_print(even1); printf("\n");
	
	set_print(even2); printf("\n");
	set_print(odd); printf("\n");
	
	delete_set(even1);
	delete_set(even2);
	delete_set(odd);
}
Ejemplo n.º 2
0
Archivo: aoi.c Proyecto: ChowZenki/aoi
void 
aoi_release(struct aoi_space *space) {
	map_foreach(space->object, delete_object, space);
	map_delete(space, space->object);
	delete_pair_list(space);
	delete_set(space,space->watcher_static);
	delete_set(space,space->marker_static);
	delete_set(space,space->watcher_move);
	delete_set(space,space->marker_move);
	space->alloc(space->alloc_ud, space, sizeof(*space));
}
Ejemplo n.º 3
0
/**
 * Called as part of the hashmap callback
 * to cleanup the sets.
 */
static int set_map_delete_cb(void *data, const char *key, uint32_t key_len, void *value) {
    (void)data;
    (void)key;
    (void)key_len;
    hlld_set_wrapper *set = value;
    delete_set(set);
    return 0;
}
Ejemplo n.º 4
0
void fill_predict_set(void)
{
     GRAMMAR *G_ptr;
     TOKEN   *ptr , *first , *follow , *predict;
     SET     *set_ptr , *set_srtat , *set_end;
	 predict = (TOKEN*) malloc(sizeof(TOKEN));
     predict->set = NULL;
     predict->next = NULL;
     strncpy( predict->string , "predict" , strlen("predict")+1 );
     
     for ( G_ptr = G_start ; G_ptr != NULL ; G_ptr = G_ptr->next )     
     {
         set_srtat = NULL;
         set_end = NULL;
         //predict = search_token( predict_set_start , G_ptr->lhs );
         for ( ptr = G_ptr->rhs_string ; ptr != NULL ; ptr = ptr->next )
         {
             first = search_token( first_set_start , ptr->string );

             if ( first == NULL )
             {
                 continue;
             }
             else if ( search_set( first , "£f" ) == TRUE )
             {
                 add_set( predict , first );
                 delete_set( &(predict->set) , "£f" );
                 continue;
             } 
             else
             {
                 add_set( predict , first );
                 break;
             }
         }
         
         if ( ptr == NULL )
         {
             follow = search_token( follow_set_start , G_ptr->lhs );
             add_set( predict , follow );
         }
         
         
         for( set_ptr = predict->set ; set_ptr != NULL ; set_ptr = set_ptr->next )
         {
             insert_predict( &set_srtat , &set_end , set_ptr->string );
             //printf("%s ",set_ptr->string);
         }
         G_ptr->set = set_srtat;
                  
         //printf("\n");
         //view_token(predict);
         free_set(&(predict->set));
         
     }
}
Ejemplo n.º 5
0
void test_basic(){
	set_t *set = new_set(10);
	
	int i, j;
	for (i=0; i < 10; i++){
		for (j=0; j < 10; j++){
			set_put(set, i);
		}
	}
	assert(set_size(set) == 10);
	delete_set(set);
}
Ejemplo n.º 6
0
/**
 * Deletes old versions from the delta lists, and calls
 * delete_set on the sets in the destroyed list.
 *
 * Safety: Same as remove_delta_versions
 */
static void delete_old_versions(hlld_setmgr *mgr, unsigned long long min_vsn) {
    // Get the merged in pending ops, lock to avoid a race
    pthread_mutex_lock(&mgr->write_lock);
    set_list *old = remove_delta_versions(mgr->delta, &mgr->delta, min_vsn);
    pthread_mutex_unlock(&mgr->write_lock);

    // Delete the sets now that we have merged into both trees
    set_list *next, *current = old;
    while (current) {
        if (current->type == DELETE) delete_set(current->set);
        next = current->next;
        free(current);
        current = next;
    }
}
Ejemplo n.º 7
0
void test_removing(){
	set_t *set = new_set(0);
	
	int i;
	for (i=0; i < 1000; i++){ set_put(set, i); }
	assert(set_size(set) == 1000);
	
	set_optimize(set);
	
	for (i=0; i < 1000; i += 2){ set_remove(set, i); }
	assert(set_size(set) == 500);
	
	for (i=0; i < 1000; i += 2){ set_put(set, i); }
	assert(set_size(set) == 1000);
	
	delete_set(set);
}
Ejemplo n.º 8
0
void test_picking(){
	int n = 10000;
	set_t *set = new_set(0);
	int i;
	for (i=0; i < n; i++){
		set_put(set, i);
	}
	assert(set_size(set) == n);
	
	set_entry_t *p = set_head(set);
	for (i=0; i < n; i++){
		assert(p->key == i);
		p = p->next;
	}
	
	for (i=0; i < 3*n; i++){
		int v = set_get_random(set);
		assert(v < n);
	}
	
	delete_set(set);
}
Ejemplo n.º 9
0
/**
 * Cleanup
 * @arg mgr The manager to destroy
 * @return 0 on success.
 */
int destroy_set_manager(hlld_setmgr *mgr) {
    // Stop the vacuum thread
    mgr->should_run = 0;
    if (mgr->vacuum_thread) pthread_join(mgr->vacuum_thread, NULL);

    // Nuke all the keys in the current version.
    art_iter(mgr->set_map, set_map_delete_cb, mgr);

    // Handle any delta operations
    set_list *next, *current = mgr->delta;
    while (current) {
        // Only delete pending creates, pending
        // deletes are still in the primary tree
        if (current->type == CREATE)
            delete_set(current->set);
        next = current->next;
        free(current);
        current = next;
    }

    // Free the clients
    setmgr_client *cl_next, *cl = mgr->clients;
    while (cl) {
        cl_next = cl->next;
        free(cl);
        cl = cl_next;
    }

    // Destroy the ART trees
    destroy_art_tree(mgr->set_map);
    destroy_art_tree(mgr->alt_set_map);
    free((mgr->set_map < mgr->alt_set_map) ? mgr->set_map : mgr->alt_set_map);

    // Free the manager
    free(mgr);
    return 0;
}
Ejemplo n.º 10
0
int comput_first_f( TOKEN *alpha , TOKEN *dst , char *dst_name )
{
    int change = FALSE;
    TOKEN *ptr , *ptr2 , *ptr3 , *ptr_end;
    TOKEN *tmp;
    is_lambda = FALSE;
	tmp = (TOKEN*) malloc(sizeof(TOKEN));
    strncpy( tmp->string , "tmp" , 4 );
    tmp->set = NULL;
    tmp->next = NULL;

    if( alpha == NULL )
    {
        is_lambda = TRUE;
        return FALSE;
    }
    
    if ( strcmp( alpha->string , "£f" ) == 0 )
    {
        //ptr = search_token( dst , dst_name );
        //if ( insert_set( ptr , "£f" ) == TRUE )
        is_lambda = TRUE;
        change = TRUE;
    }
    else
    {
        ptr = search_token( dst , dst_name );
        ptr2 = search_token( first_set_start , alpha->string );
        
        add_set( tmp , ptr2 );
        delete_set( &(tmp->set) , "£f" );
        if ( add_set( ptr , tmp ) == TRUE ) 
            change = TRUE;
        free_set( &(tmp->set) );
        
        for( ptr3 = alpha ; ptr3 != NULL  ; ptr3 = ptr3->next )
        {
            ptr2 = search_token( first_set_start , ptr3->string );
            if( search_set( ptr2 , "£f" ) != TRUE )
                break;
            
            if ( ptr3->next == NULL )
            {
                ptr_end = ptr3;
                ptr3 = search_token( first_set_start , ptr_end->string );
                if( search_set( ptr3 , "£f" ) == TRUE )
                {
                    if ( insert_set( ptr , "£f" ) == TRUE )
                    {
                        is_lambda = TRUE;
                        change = TRUE;
                    }
                }
                break;
            }

            ptr2 = search_token( first_set_start , ptr3->next->string );
            add_set( tmp , ptr2 );
            delete_set( &(tmp->set) , "£f" );
            if ( add_set( ptr , tmp ) == TRUE )
            {
                delete_set( &(ptr->set) , "£f" );
                change = TRUE;
            }
            free_set( &(tmp->set) );
            
        }

    }
    
    free_token(&tmp);
    return change;
}
Ejemplo n.º 11
0
int propagate( int state , Config_set *A , Config_set *B )
{
    
    STATE *shift_state;
    Config_set *C_ptr , *ptr;
    TOKEN *T_ptr , *first;
    TOKEN *dot;
    TOKEN *L2;
    TOKEN *L1;
    int i;
    
    L1 = A->lookahead;
    dot = A->dot;
    L2 = B->lookahead;
    
    
    //First(£^L)
    for( T_ptr = dot->next ; T_ptr != NULL ; T_ptr = T_ptr->next )
    {
        first = search_token( first_set_start , T_ptr->string );
        if (first == NULL )
            continue;
        if ( search_set(first,"£f") == TRUE )
        {
            add_set(L2,first);
            delete_set( &(L2->set) , "£f" );
            continue;
        }
        else
        {
            if ( add_set(L2,first) == FALSE ) 
                return 0;
            break;
        }
    }
    //First(£^L) ,  £^ is lambda
    if(T_ptr == NULL)
    {
        add_set( L2 , L1 );         
    }
    
    //printf("%d\n", parser_table[state][make_id(dot->string)].go_to );
    if( B->dot == NULL )
        return 0;
    
    i = parser_table[state][make_id(B->dot->string)-1].go_to;
    //printf("%d  %s -> %d\n",state , B->dot->string , i );
    //view_state(state);


    if( i == state )
        return 0;
    // shift state
    for( shift_state = state_start ; i != shift_state->statenum ; shift_state = shift_state->next );
    
    for( C_ptr = shift_state->config_set ; C_ptr != NULL && B->rule != C_ptr->rule ; C_ptr = C_ptr->set_next );
    {
//        if ( i == 105 )
//            printf("hit\n");
        propagate_link( i , B , C_ptr );
    }
    
    //comput lookahead by closue 0
    C_ptr = shift_state->config_set;
    
    
    for( C_ptr = shift_state->config_set ; C_ptr != NULL && C_ptr->set_next != NULL ; C_ptr = C_ptr->set_next )
    {
        for( ptr = shift_state->config_set ; ptr != NULL ; ptr = ptr->set_next )
        {
            if ( C_ptr->dot == NULL ) 
                continue;
            if ( strcmp( C_ptr->dot->string , ptr->rule->lhs ) == 0 )
            {
                propagate( shift_state->statenum , C_ptr , ptr );
            }
        }
    }
	return 0;    
}