Ejemplo n.º 1
0
void test_hashset_remove_all()
{
    HashSet *hs = hashset_new();

    char *a = "foo";
    char *b = "bar";
    char *c = "baz";
    char *d = "foo";

    hashset_add(hs, a);
    hashset_add(hs, b);
    hashset_add(hs, c);
    hashset_add(hs, d);

    hashset_remove_all(hs);

    size_t size = hashset_size(hs);

    cc_assert(size == 0,
              cc_msg("hashset_add: Expected size was 0, but got %d",
                     size));

    cc_assert(!hashset_contains(hs, "bar") &&
              !hashset_contains(hs, c),
              cc_msg("hashset_add: HashSet not empty after removing"
                     " all elements"));

    hashset_destroy(hs);
}
Ejemplo n.º 2
0
void hashset_destroy(hashset_p set)
{
	if (set) {
		void hashset_remove_all(hashset_p set);

		hashset_remove_all(set);

		free(set->slotlists);
		set->slotlists = NULL;

		free(set);
	}
}