Example #1
0
/*
 * bc_close() is not thread safe, should stop other threads before call it.
 * */
void bc_close(Bitcask *bc)
{
    int i=0;
    pthread_mutex_lock(&bc->write_lock);
    bc_flush(bc, 0, 0);
    
    if (NULL != bc->curr_tree) {
        uint32_t curr;
        ht_get_hash(bc->curr_tree, "@", &curr);
        if (curr > 0) {
            char name[255], buf[255];
            sprintf(name, HINT_FILE, bc->curr);
            sprintf(buf, "%s/%s", mgr_alloc(bc->mgr, name), name);
            build_hint(bc->curr_tree, buf);
        }else{
            ht_destroy(bc->curr_tree);
        }
        bc->curr_tree = NULL;
    }
    bc->curr = 0;
    ht_destroy(bc->tree);
    mgr_destroy(bc->mgr);
    free(bc->write_buffer);
    free(bc);
}
/* Destroys Natural Neighbours hashing point interpolation.
 *
 * @param nn Structure to be destroyed
 */
void nnhpi_destroy(nnhpi* nn)
{
    ht_destroy(nn->ht_data);
    ht_process(nn->ht_weights, free_nn_weights);
    ht_destroy(nn->ht_weights);
    nnpi_destroy(nn->nnpi);
}
Example #3
0
/**
 * Frees memory for a numerical object
 */
void object_numerical_fini(void) {
    ht_destroy(Object_Numerical_struct.methods);
    ht_destroy(Object_Numerical_struct.properties);

    for (int i=0; i!=NUMERICAL_CACHED_CNT; i++) {
        smm_free(numerical_cache[i]);
    }
}
Example #4
0
File: io.c Project: flijten/saffire
static void _fini(void) {
    // Destroy methods and properties
    ht_destroy(io_struct.methods);
    ht_destroy(io_struct.properties);

    ht_destroy(console_struct.methods);
    ht_destroy(console_struct.properties);

}
Example #5
0
void cerrarTablaSimbolos(ambitos_t *ambitos) {
    if (ambitos->local != NULL){
        ht_destroy(ambitos->local);
        ambitos->local=NULL;
    }
    if (ambitos->global != NULL){
        ht_destroy(ambitos->global);
        ambitos->global=NULL;
    }
    free (ambitos);
}
Example #6
0
/*
 * bc_close() is not thread safe, should stop other threads before call it.
 * */
void bc_close(Bitcask *bc)
{
    char datapath[255], hintpath[255];

    if (bc->optimize_flag > 0)
    {
        bc->optimize_flag = 2;
        while (bc->optimize_flag > 0)
        {
            sleep(1);
        }
    }

    pthread_mutex_lock(&bc->write_lock);

    bc_flush(bc, 0, 0);

    if (NULL != bc->curr_tree)
    {
        if (bc->curr_bytes > 0)
        {
            build_hint(bc->curr_tree, new_path(hintpath, bc->mgr, HINT_FILE, bc->curr));
        }
        else
        {
            ht_destroy(bc->curr_tree);
        }
        bc->curr_tree = NULL;
    }

    if (bc->curr_bytes == 0) bc->curr --;
    if (bc->curr - bc->last_snapshot >= SAVE_HTREE_LIMIT)
    {
        if (ht_save(bc->tree, new_path(datapath, bc->mgr, HTREE_FILE, bc->curr)) == 0)
        {
            mgr_unlink(gen_path(datapath, mgr_base(bc->mgr), HTREE_FILE, bc->last_snapshot));
        }
        else
        {
            fprintf(stderr, "save HTree to %s failed\n", datapath);
        }
    }
    ht_destroy(bc->tree);

    mgr_destroy(bc->mgr);
    free(bc->write_buffer);
    free(bc);
}
/** \brief    Construct the BDD that represent all hitting sets from a ZDD.
 *  \param    f     ZDD
 *  \return   The contructed BDD
 *  \see      hit_z2b_rec
 */
bddp hit_z2b(zddp f)
{
  my_hash *h = ht_create(0);
  ENSURE_TRUE_MSG(h != NULL, "hash table creation failed");

#ifdef SIZE_LOG
  char str[BUFSIZ];
  snprintf(str, BUFSIZ, "%s-hit.log", g_basename);
  sizelog = fopen(str, "w");
  ENSURE_TRUE_MSG(sizelog != NULL, "file open failed");
  maxsize = 0;
#endif /*SIZE_LOG*/

  assert(recdepth == 0);
  bddp r = hit_z2b_rec(f, h);
  ENSURE_TRUE(r != BDD_NULL);
  assert(recdepth == 0);

#ifdef SIZE_LOG
  fclose(sizelog);
  printf("max|bdd|\t%ju\n", maxsize);
#endif /*SIZE_LOG*/

  ht_destroy(h); 
  return r;
}
Example #8
0
/**
 * Destroys the given optin object
 */
void optin_destroy(optin* o)    {
    ht_destroy(o->options);
    if (o->usage)   {
        free(o->usage);
    }
    free(o);
}
Example #9
0
/*
 * This is called at the beginning of a cubist run to clear out
 * all "files" generated on the previous run and to prepare it
 * for the next run.
 */
void rbm_removeall()
{
    /* Check if there actually is anything to remove */
    if (strbufv != NULL) {
        /*
         * Destroy all STRBUF's in the hash table.
         * Note that this loop leaves the hash table full of
         * pointers to deallocated STRBUF's until ht_destroy
         * is called below.
         */
        ht_reset(strbufv);  /* just in case */
        while (1) {
            void *e = ht_next(strbufv);
            if (e == NULL)
                break;
            strbuf_destroy((STRBUF *) ht_value(e));
        }

        /* Destroy the hash table itself */
        ht_destroy(strbufv);
    }

    /* Create/recreate the hash table for subsequent use */
    strbufv = ht_new(HASH_LEN);
}
Example #10
0
void
print_freqs(struct print_freqs_param *param) {
    char *start = param->start;
    int length = param->length;
    int frame = param->frame;
    char *output = param->output;
    int output_size = param->output_size;

    struct ht_ht *ht = ht_create(32);
    char buffer[frame + 1];
    int output_pos = 0;

    generate_seqences(start, length, frame, ht);
    
    struct ht_node *counts = ht_values_as_vector(ht);
    int size = ht->items;

    qsort(counts, size, sizeof(struct ht_node), &key_count_cmp);

    int total_count = 0;
    for (int i = 0; i < size; i++) {
        total_count += counts[i].val;
    }

    for (int i = 0; i < size; i++) {
        unpack_key(counts[i].key, frame, buffer);
        output_pos += snprintf(output + output_pos, output_size - output_pos,
                "%s %.3f\n", buffer, counts[i].val*100.0f/total_count);
    }

    free(counts);
    ht_destroy(ht);
}
Example #11
0
int main(int argc, char** argv) {
    printf("Creating...\n");
    HashTable* t = ht_make(3);
    HashFun h = jenkin1_hash;

    test_table(t, h, 0, 1);

    for (int i = 0; i < sizeof(test_a)/sizeof(test_a[0]); ++i) {
        const char* s = test_a[i];
        unsigned int hash = h(s);
        printf("Add \"%s\" (%u)...\n", s, hash);
        ht_put(t, hash, s);
        test_table(t, h, i+1, 1);
    }

    for (int i = 0; i < sizeof(test_b)/sizeof(test_b[0]); ++i) {
        const char* s = test_b[i];
        unsigned int hash = h(s);
        printf("Remove \"%s\" (%u)...\n", s, hash);
        ht_remove(t, hash, s);
        test_table(t, h, i+1, 0);
    }

    printf("All ok!\n");
    ht_destroy(t);
    return 0;
}
Example #12
0
int test_add_to_same_key(){
  hashtable_t *ht = ht_create( 65536, free_jambo );

  ht_set( ht, "key1", "blorg" );

  ht_set( ht, "key1", "bloff" );
  ht_set( ht, "key1", "gladd" );
  ht_set( ht, "key1", "grutt" );
  ht_set( ht, "key1", "twerky" );
  ht_set( ht, "key1", "lennart" );
  ht_set( ht, "key2", "sverker" );
  ht_set( ht, "key3", "Rogge" );
  ht_set( ht, "key4", "Swutt" );


  check( strcmp( ht_get(ht, "key1"), "lennart") == 0 );
  check( strcmp( ht_get(ht, "key2"), "sverker") == 0);
  check( strcmp( ht_get(ht, "key3"), "Rogge") == 0);
  check( strcmp( ht_get(ht, "key4"), "Swutt") == 0);

  check(ht_size(ht) == 4);

  ht_destroy(ht);

  return 0;
}
Example #13
0
int test_perfomance(){
  hashtable_t *ht = ht_create( 65536, destroy_gv_t );

  char key[10];
  char s1[10];
  char s2[10];

  for(int i=0;i < 50000; i++){

    sprintf(key,"key-%d", i);
    sprintf(s1,"s1-%d", i);
    sprintf(s2,"s2-%d", i);

    ht_set( ht, key, create_gv_t(i, s1, s2) );

    check( strcmp( ((gv_t *) ht_get(ht, key))->s1, s1) == 0 );
    check( strcmp( ((gv_t *) ht_get(ht, key))->s2, s2) == 0 );
    check(((gv_t *) ht_get(ht, key))->i1 == i );

  }
  ht_destroy(ht);
 

  return 0;
}
Example #14
0
/**
 * Test that half fills a moderately sized hash table with
 * entries, then drains it. Hash function used here is the
 * Jenkins hash (which is the default).
 */
TEST(hashy_tests, test_jenkins_hash) {
    size_t ht_size = 1024;
    std::string skey = "key_",
                svalue = "value_";

    std::stringstream sskey, ssvalue;
    skey.append("key_");
    svalue.append("value_");

    hashtable_t *ht = ht_create(ht_size, NULL);


    for(int i = 0; i < ht_size/2; i++) {
        sskey << skey << i;
        ssvalue << svalue << i;

        ht_set(ht, (char *) sskey.str().c_str(),
               (char *) ssvalue.str().c_str());
        sskey.str(std::string());
        ssvalue.str(std::string());
    }

    for(int i = 0; i < ht_size/2; i++) {
        sskey << skey << i;
        ssvalue << svalue << i;

        char * val = ht_rem(ht, (char *) sskey.str().c_str());
        if(val) {free(val);}
        sskey.str(std::string());
    }
    EXPECT_EQ(ht->stored_elements, 0);
    EXPECT_EQ(ht_destroy(ht), 0);
}
Example #15
0
File: nnpi.c Project: epicsdeb/sdds
void nnpi_reset(nnpi* nn)
{
    nn->nvertices = 0;
    nn->ncircles = 0;
    if (nn->bad != NULL) {
        ht_destroy(nn->bad);
        nn->bad = NULL;
    }
}
void
write_count (char *searchFor, char *buffer, long buflen)
{
  struct ht_ht *ht;

  ht = generate_frequencies (strlen (searchFor), buffer, buflen);
  printf ("%d\t%s\n", ht_find_new (ht, searchFor)->val, searchFor);
  ht_destroy (ht);
}
Example #17
0
/*0 si no cierras nada, 1 si cierras local, 2 si cierras global*/
int cerrarAmbito(ambitos_t *ambitos) {

    if (ambitos->local != NULL) {
        /*Destruyo ambito local*/
        ht_destroy(ambitos->local);
        ambitos->local=NULL;
        return 2;
    }

    if (ambitos->global != NULL) {
        /*Destruyo ambito global*/
        ht_destroy(ambitos->global);
        ambitos->global=NULL;
        return 1;
    }

    return 0;
}
Example #18
0
/* Tear down the identifier hash table.  */
void
_cpp_destroy_hashtable (cpp_reader *pfile)
{
  if (pfile->our_hashtable)
    {
      ht_destroy (pfile->hash_table);
      obstack_free (&pfile->hash_ob, 0);
    }
}
Example #19
0
//automatically called at exit
void protocol_cleanup()
{
	_log(LVL_DEBUG, "Protocol cleanup\n");
	if(_proto_init)
	{
		ht_clear(cmd_dict, 0);
		ht_destroy(cmd_dict);
		_proto_init = false;
	}
}
void nnpi_reset(nnpi* nn)
{
    nn->nvertices = 0;
    nn->ncircles = 0;
    memset(nn->d->flags, 0, nn->d->ntriangles * sizeof(int));
    if (nn->bad != NULL) {
        ht_destroy(nn->bad);
        nn->bad = NULL;
    }
}
Example #21
0
void ht_clear(hash_table *table)
{
    ht_destroy(table);

    ht_init(table, table->flags, table->max_load_factor
#ifndef __WITH_MURMUR
    , table->hashfunc_x86_32, table->hashfunc_x86_128, table->hashfunc_x64_128
#endif //__WITH_MURMUR
    );
}
Example #22
0
/**
 * Frees memory for a hash object
 */
static void obj_free(t_object *obj) {
    if (! obj) return;

    t_hash_object *hash_obj = (t_hash_object *)obj;

    if (hash_obj->ht != NULL) {
        ht_destroy(hash_obj->ht);
        hash_obj->ht = NULL;
    }
}
Example #23
0
/* Destroy the given cache. Free all objects which remain in the cache. */
void
arc_destroy(arc_t *cache)
{
    arc_list_destroy(cache, &cache->mrug.head);
    arc_list_destroy(cache, &cache->mru.head);
    arc_list_destroy(cache, &cache->mfu.head);
    arc_list_destroy(cache, &cache->mfug.head);
    ht_destroy(cache->hash);
    refcnt_destroy(cache->refcnt);
    MUTEX_DESTROY(&cache->lock);
    free(cache);
}
Example #24
0
int test_add_custom_struct_as_value(){
  hashtable_t *ht = ht_create( 65536, destroy_gv_t );

  ht_set( ht, "key4", create_gv_t(10,"jamse", "fjamse") );
  check( strcmp( ((gv_t *) ht_get(ht, "key4"))->s1, "jamse") == 0 );
  check( strcmp( ((gv_t *) ht_get(ht, "key4"))->s2, "fjamse") == 0 );
  check(((gv_t *) ht_get(ht, "key4"))->i1 == 10 );
  ht_destroy(ht);
 

  return 0;
}
/** \brief    Construct the ZDD that represents all minimal hitting sets for a ZDD.
 *  \param    f     ZDD
 *  \return   The contructed ZDD
 *  \see      minhit_nonsup_rec, nonsup
 *  \note     pp.669-670 in "The Art of Computer Programming, Volume 4a (2011)" by Knuth
 */
zddp minhit_nonsup(zddp f)
{
  my_hash *h = ht_create(0);
  ENSURE_TRUE_MSG(h != NULL, "hash table creation failed");

  assert(recdepth == 0);
  zddp r = minhit_nonsup_rec(f, h);
  ENSURE_TRUE(r != BDD_NULL);
  assert(recdepth == 0);

  ht_destroy(h);
  return r;
}
Example #26
0
int
r_set_destroy(
    struct r_set* set
) {
    int ret;
    if (set) {
        set_dbg("Destroy set: %p", (void*) set);
        ret = ht_destroy(&set->ht, set->cfg);
        free(set);
    } else {
        return -EEXIST;
    }
    return ret;
}
Example #27
0
// new_size can be smaller than current size (downsizing allowed)
void ht_resize(hash_table *table, unsigned int new_size)
{
    hash_table new_table;

    debug("ht_resize(old=%d, new=%d)\n",table->array_size,new_size);
    new_table.hashfunc_x86_32 = table->hashfunc_x86_32;
    new_table.hashfunc_x86_128 = table->hashfunc_x86_128;
    new_table.hashfunc_x64_128 = table->hashfunc_x64_128;
    new_table.array_size = new_size;
    new_table.array = malloc(new_size * sizeof(hash_entry*));
    new_table.key_count = 0;
    new_table.collisions = 0;
    new_table.flags = table->flags;
    new_table.max_load_factor = table->max_load_factor;
    new_table.max_collisions_index = 0;
    new_table.max_collisions = 0;

    unsigned int i;
    for(i = 0; i < new_table.array_size; i++)
    {
        new_table.array[i] = NULL;
    }

    hash_entry *entry;
    hash_entry *next;
    for(i = 0; i < table->array_size; i++)
    {
        entry = table->array[i];
        while(entry != NULL)
        {
            next = entry->next;
            ht_insert_he(&new_table, entry);
            entry = next;
        }
        table->array[i]=NULL;
    }

    ht_destroy(table);

    table->hashfunc_x86_32 = new_table.hashfunc_x86_32;
    table->hashfunc_x86_128 = new_table.hashfunc_x86_128;
    table->hashfunc_x64_128 = new_table.hashfunc_x64_128;
    table->array_size = new_table.array_size;
    table->array = new_table.array;
    table->key_count = new_table.key_count;
    table->collisions = new_table.collisions;
    table->max_collisions_index = new_table.max_collisions_index;
    table->max_collisions = new_table.max_collisions;
}
Example #28
0
bl destroy_sprite_message_map(Ptr _obj) {
	bl result = TRUE;
	Sprite* spr = (Sprite*)_obj;

	assert(_obj);

	if(!spr->message_map.proc_map) {
		result = FALSE;
	} else {
		ht_destroy(spr->message_map.proc_map);
		spr->message_map.proc_map = 0;
	}

	return result;
}
Example #29
0
bl destroy_canvas_message_map(Ptr _obj) {
	bl result = TRUE;
	Canvas* cvs = (Canvas*)_obj;

	assert(_obj);

	if(!cvs->message_map.proc_map) {
		result = FALSE;
	} else {
		ht_destroy(cvs->message_map.proc_map);
		cvs->message_map.proc_map = 0;
	}

	return result;
}
Example #30
0
/**
 * destroy function
 */
static void destroy(void)
{
	/* sync back to db */
	if(ht_db_url.len>0)
	{
		if(ht_db_init_con()==0)
		{
			if(ht_db_open_con()==0)
			{
				ht_db_sync_tables();
				ht_db_close_con();
			}
		}
	}
	ht_destroy();
}