int test(void) { test_pair_t one = { 1, "one" }; test_pair_t two = { 2, "two" }; test_pair_t three = { 3, "three" }; test_pair_t four = { 4, "four" }; int i; int xid = Tbegin(); jbHashTable_t *ht = jbHtCreate(xid, 79); if( jbHtInsert(xid, ht, &one.key, sizeof(int), one.value, sizeof(char)*4) || jbHtInsert(xid, ht, &two.key, sizeof(int), two.value, sizeof(char)*4) || jbHtInsert(xid, ht, &three.key, sizeof(int), three.value, sizeof(char)*6) || jbHtInsert(xid, ht, &four.key, sizeof(int), four.value, sizeof(char)*5) ) { return -1; } Tcommit(xid); xid = Tbegin(); for( i = 1; i <= 4; i++ ) { char buf[7]; jbHtLookup(xid, ht, &i, sizeof(int), buf); printf("key %u: %s\n", i, buf); } jbHtDelete(xid, ht); Tcommit(xid); return 0; }
int test() { unsigned int i, xid; const unsigned int INSERT_NUM = 10000; /* should be > JB_HASHTABLE_SIZE */ char value[22]; /* should be log(INSERT_NUM)+8 */ jbHashTable_t *ht; xid = Tbegin(); ht = jbHtCreate(xid, 1000); for( i = 0; i < INSERT_NUM; i++ ) { sprintf(value, "value: %u\n", i); jbHtInsert(xid, ht, &i, sizeof(int), value, sizeof(char)*strlen(value)); } Tcommit(xid); xid = Tbegin(); for( i = 0; i < INSERT_NUM; i++ ) { jbHtLookup(xid, ht, &i, sizeof(int), value); printf("%s", value); } jbHtDelete(xid, ht); Tabort(xid); return 0; }