示例#1
0
void Oec_IdSet_free(T *_this_p) {
    assert(_this_p && *_this_p);
    T _this_ = *_this_p;
    //Set_T s = _this_->members;

    void **array = Set_toArray(_this_->members, NULL);
    for ( int i = 0; array[i]; i++ ) {
        ID_ITEM *titem = (ID_ITEM *) array[i];
        if (titem) {
            Mem_free( titem, __FILE__, __LINE__ );
        }
    }
    Mem_free(array, __FILE__, __LINE__);
    Set_free(&_this_->members);
    Mem_free(_this_, __FILE__, __LINE__);
}
示例#2
0
static void _free_items(Table_T items) {

    assert(items);

    int sz = Table_length(items);
    if (sz > 0) {
        void **array = Table_toArray(items, NULL);
        for ( int i = 0; i < sz && array[i]; i+= 2 ) {
            char *key = (char *) array[i];
            Set_T titem = Table_remove(items, key);
            if (titem) {
                Set_free( &titem );
            }
        }
        Mem_free(array, __FILE__, __LINE__);
    }
}
示例#3
0
static void _remove_item(Table_T items, item_ *rmitem, bool timeout) {

    if (rmitem == NULL) {
        return;
    }
    if (rmitem->group) {
        // get each item from the list, null out the list field and
        // recursively call this until the whole set is removed
        _remove_group(items, rmitem->group, timeout);
        return;
    }

    Set_T s = rmitem->items;
    item_ *item = NULL;
    if (s) {
        item = Set_remove(s, (void *) rmitem); //if this was a dummy item from a timeout, get the real one
    }
    if (!item) return;

    if (item->timer_event) {
        timeout_del(item->timer_event);
        Mem_free(item->timer_event, __FILE__, __LINE__);
    }

    if ( timeout && item->timeout_handler!=NULL ) {
        _process_fun(item->timeout_handler, item->args);
    }
    if (rmitem != item) {
        Mem_free(rmitem, __FILE__, __LINE__); //a clone
    }

    if (item->key_idx) {
        oe_scalar key = item->object[item->key_idx];
        if (s) 
        if (key && Set_length(s) <= 0) {
            if (items) {
                Table_remove(items, key);
            }
            if (s) {
                Set_free( &s );
            }
        }
    }
    Mem_free(item, __FILE__, __LINE__);
}
示例#4
0
void readAll( Table_T fpTable )
{
        Set_T nameSet = Set_new( initSetSize, NULL, NULL ); 


        fpPair pair;

        while( !feof(stdin) )
        {      

                pair = readLine();
                addToTable( nameSet, fpTable, pair );

        }

        Set_free(&nameSet);

}
示例#5
0
 /* prints the sets in the table that have more than 1 value*/
void print_table(Table_T* table)
{
        int table_len = Table_length(*table);
        void **table_array = Table_toArray(*table, NULL);

        int counter = num_fgroups(table);

        for (int i=1; i<(2*table_len); i += 2) {
                if(Set_length((Set_T)table_array[i]) > 1) {
                        print_set((Set_T *)&table_array[i]);
                        counter--;
                        if (counter != 0) {     
                                printf("\n");
                        }
                }
                Set_free((Set_T *)&table_array[i]);
        }
        free(table_array);
}
示例#6
0
void
send_chunk_radius(struct PL_entry *player, int32_t xin, int32_t zin, int radius)
{
  // Get "chunk coords"
  xin /= 16;
  zin /= 16;
  
  LOG(LOG_DEBUG, "Sending new chunks center:(%d, %d)", xin, zin);
  
  Set_T oldchunkset = player->loadedchunks;
  
  // Make a new set containing coordinates of all chunks client should have
  Set_T newchunkset = Set_new(400, chunkcoordcmp, chunkcoordhash);
  for(int x = -radius; x < radius; x++)
  {
    for(int z = -radius; z < radius; z++)
    {
      // Use a circular send pattern based on Bravo/MostAwesomeDude's algo
      if ( x*x + z*z <= radius*radius )
      {
	chunk_coord *coord = Malloc(sizeof(chunk_coord));
	coord->x = x + xin;
	coord->z = z + zin;
	Set_put(newchunkset, coord);
      }
    }
  }
  
  Set_T toremove = Set_minus(oldchunkset, newchunkset);
  Set_T toadd = Set_minus(newchunkset, oldchunkset);
  
  Set_map(toremove, &chunkradiusunload, (void *)player);
  Set_map(toadd, &chunkradiusload, (void *)player);
  
  player->loadedchunks = newchunkset;
  Set_map(oldchunkset, &chunkradiusfree, NULL);
  Set_free(&oldchunkset);
}