示例#1
0
文件: ls.c 项目: kolen/radare2
SDB_API SdbList *ls_newf(SdbListFree freefn) {
	SdbList *list = ls_new ();
	if (list) {
		list->free = freefn;
	}
	return list;
}
示例#2
0
文件: sdb.c 项目: assarbad/radare2
// TODO: use mmap instead of read.. much faster!
SDB_VISIBLE Sdb* sdb_new (const char *dir, int lock) {
	Sdb* s;
	if (lock && !sdb_lock (sdb_lockfile (dir)))
		return NULL;
	s = malloc (sizeof (Sdb));
	if (dir && *dir) {
		s->dir = strdup (dir);
		s->fd = open (dir, O_RDONLY|O_BINARY);
		// if (s->fd == -1) // must fail if we cant open for write in sync
	} else {
		s->dir = NULL;
		s->fd = -1;
	}
	s->fdump = -1;
	s->ndump = NULL;
	s->ns = ls_new ();
	s->ht = ht_new ();
	s->lock = lock;
	s->expire = 0LL;
	//s->ht->list->free = (SdbListFree)sdb_kv_free;
	// if open fails ignore
	cdb_init (&s->db, s->fd);
	cdb_findstart (&s->db);
	return s;
}
示例#3
0
文件: ht.c 项目: ericfode/radare2
SdbHash* ht_new(void) {
	SdbHash *ht = R_NEW (SdbHash);
	if (!ht) return NULL;
	// TODO: use slices here
	ht->list = ls_new ();
	ht->size = hash_sizes[0].size;
	ht->table = calloc (ht->size, sizeof (*ht->table));
	if (!ht->table) {
		free (ht);
		return NULL;
	}
	ht->size_index = 0;
	ht->entries = 0;
	ht->deleted_entries = 0;
	ht->rehash = hash_sizes[ht->size_index].rehash;
	ht->max_entries = hash_sizes[ht->size_index].max_entries;
	return ht;
}
示例#4
0
void new_insert_exists_destroy(void){
    /* our simple hash set */
    struct ls_set *set = 0;

    /* some keys */
    char *key_1 = "bbbbb";
    char *key_2 = "aaaaa";
    char *key_3 = "ccccc";

    puts("\ntesting basic functionality");

    puts("testing new");
    set = ls_new();
    assert(set);
    assert( 32 == set->size );
    assert( 0 == ls_nelems(set) );
    assert( 0 == ls_load(set) );


    puts("testing insert and get");
    puts("one");
    assert( ls_insert(set, key_1) );
    assert( 1 == ls_nelems(set) );
    assert( 0 == ls_exists(set, key_2) );
    assert( 0 == ls_exists(set, key_3) );
    assert(ls_exists(set, key_1) );


    puts("two");
    assert( ls_insert(set, key_2) );
    assert( 2 == ls_nelems(set) );
    assert( 0 == ls_exists(set, key_3) );
    assert( ls_exists(set, key_2) );


    puts("three");
    assert( ls_insert(set, key_3) );
    assert( 3 == ls_nelems(set) );
    assert( ls_exists(set, key_3) );


    assert( ls_destroy(set, 1) );
    puts("success!");
}
示例#5
0
    puts("success!");
}

void delete(void){
    /* our simple hash set */
    struct ls_set *set = 0;

    /* some keys */
    char *key_1 = "bacon";
    char *key_2 = "chicken";
    char *key_3 = "pork";

    puts("\ntesting delete functionality ");

    puts("creating a set");
    set = ls_new();
    assert(set);
    assert( 32 == set->size );
    assert( 0 == ls_nelems(set) );


    puts("inserting some data");
    assert( ls_insert(set, key_1) );
    assert( 1 == ls_nelems(set) );
    assert( 0 == ls_exists(set, key_2) );
    assert( 0 == ls_exists(set, key_3) );
    assert( ls_exists(set, key_1) );


    assert( ls_insert(set, key_2) );
    assert( 2 == ls_nelems(set) );