static void test_copy(void **state) { CfAssoc *ap = NewAssoc("hello", (Rval) { "world", CF_SCALAR }, cf_str); CfAssoc *ap2 = CopyAssoc(ap); assert_string_equal(ap->lval, ap2->lval); assert_string_equal(ap->rval.item, ap2->rval.item); assert_int_equal(ap->rval.rtype, ap2->rval.rtype); assert_int_equal(ap->dtype, ap2->dtype); DeleteAssoc(ap); DeleteAssoc(ap2); }
static bool HugeHashDeleteElement(AssocHashTable *hashtable, const char *element) { int bucket = GetHash(element); int i = bucket; do { /* End of allocated chunk */ if (hashtable->buckets[i] == NULL) { break; } /* Keep looking */ if (hashtable->buckets[i] == HASH_ENTRY_DELETED) { i = (i + 1) % CF_HASHTABLESIZE; continue; } /* Element is found */ if (strcmp(element, hashtable->buckets[i]->lval) == 0) { DeleteAssoc(hashtable->buckets[i]); hashtable->buckets[i] = NULL; return true; } i = (i + 1) % CF_HASHTABLESIZE; } while (i != bucket); /* Either looped through hashtable or found a NULL */ return false; }
static void TinyHashClear(AssocHashTable *hashtable) { int i; for (i = 0; i < hashtable->array.size; ++i) { DeleteAssoc(hashtable->array.values[i]); } hashtable->array.size = 0; }
static void HugeHashClear(AssocHashTable *hashtable) { int i; for (i = 0; i < CF_HASHTABLESIZE; i++) { if (hashtable->buckets[i] != NULL) { if (hashtable->buckets[i] != HASH_ENTRY_DELETED) { DeleteAssoc(hashtable->buckets[i]); } } } memset(hashtable->buckets, 0, sizeof(CfAssoc *) * CF_HASHTABLESIZE); }
static bool TinyHashDeleteElement(AssocHashTable *hashtable, const char *element) { int i; for (i = 0; i < hashtable->array.size; ++i) { if (strcmp(hashtable->array.values[i]->lval, element) == 0) { int j; DeleteAssoc(hashtable->array.values[i]); for (j = i; j < hashtable->array.size - 1; ++j) { hashtable->array.values[j] = hashtable->array.values[j + 1]; } hashtable->array.size--; return true; } } return false; }
static void test_create_destroy(void) { CfAssoc *ap = NewAssoc("hello", (Rval) { "world", RVAL_TYPE_SCALAR }, DATA_TYPE_STRING); DeleteAssoc(ap); }
static void test_create_destroy(void **state) { CfAssoc *ap = NewAssoc("hello", (Rval) { "world", CF_SCALAR }, cf_str); DeleteAssoc(ap); }