-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset.c
55 lines (45 loc) · 1.05 KB
/
set.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// Created by wangzhi on 17-4-29.
//
#include <wchar.h>
#include <assert.h>
#include <malloc.h>
#include "set.h"
HashSet HashSet_create(int hint, int (*cmp)(const void *, const void *), unsigned int (*hash)(const void *))
{
return HashTable_create(hint,cmp,hash,NULL);
}
void HashSet_destory(HashSet *hashSet)
{
HashTable_destory(hashSet);
}
int HashSet_length(HashSet hashSet)
{
return hashSet->length;
}
void *HashSet_insert(HashSet hashSet, void *member)
{
return HashTable_insert(hashSet,member,member);
}
void *HashSet_remove(HashSet hashSet, void *member)
{
return HashTable_remove(hashSet,member);
}
void **HashSet_toArray(HashSet hashSet, void *end)
{
int i, j = 0;
void **array;
HashNode *p;
assert(hashSet);
array = malloc((hashSet->length + 1)*sizeof (*array));
for (i = 0; i < hashSet->size; i++)
for (p = hashSet->bucket[i]; p; p = p->next) {
array[j++] = p->value;
}
array[j] = end;
return array;
}
void HashSet_map(HashSet hashSet, void (*apply)(const void *, void **, void *), void *c1)
{
HashTable_map(hashSet,apply,c1);
}