di_rpl_instance_t * rpl_instance_dup(const di_rpl_instance_t * rpl_instance) { di_rpl_instance_t *new_instance; new_instance = malloc(sizeof(di_rpl_instance_t)); memcpy(new_instance, rpl_instance, sizeof(di_rpl_instance_t)); new_instance->dodags = hash_dup(rpl_instance->dodags); return new_instance; }
int main(int argc, char *argv[]) { char buf[32]; char buf2[32]; int i; int len; hash_t *ht, *htcpy; hash_iter_t *iter; srand(time(NULL)); ht = hash_create(16); HASH_SET_KEYCPY(ht, _demo_dup); HASH_SET_VALCPY(ht, _demo_dup); HASH_SET_FREE_KEY(ht, _demo_destructor); HASH_SET_FREE_VAL(ht, _demo_destructor); HASH_SET_KEYCMP(ht, _demo_cmp); for (i = 0; i < 100000; ++i) { len = randstring(buf, 1, sizeof(buf) - 1); buf[len] = '\0'; len = randstring(buf2, 1, sizeof(buf2) - 1); buf2[len] = '\0'; hash_insert(ht, buf, buf2); } hash_dump(ht); htcpy = hash_dup(ht); hash_free(ht); printf("================================\n\n\n"); iter = hash_iter_new(htcpy); assert(iter); do { printf("%s=>%s\n", (char *)iter->key, (char *)iter->value); } while (hash_iter_next(iter) == 0); hash_free(htcpy); exit(0); }