Skip to content

Commit

Permalink
Ví dụ minh họa sử dụng hset
Browse files Browse the repository at this point in the history
  • Loading branch information
bangoc committed Jan 17, 2022
1 parent 2b5c234 commit 43a5d97
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ add_subdirectory(hfunc)
add_subdirectory(p1w)
add_subdirectory(hmap)
add_subdirectory(gsl)
add_subdirectory(gvec)
add_subdirectory(gvec)
add_subdirectory(hset)
5 changes: 5 additions & 0 deletions examples/hset/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(hset_demo hset_demo.c)

foreach (p hset_demo)
target_link_libraries(${p} bkc)
endforeach()
22 changes: 22 additions & 0 deletions examples/hset/hset_demo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
(C) Nguyen Ba Ngoc 2022
Minh họa sử dụng hset
*/

#include "cgen.h"

int main() {
hset_t s = hset_create(gtype_hash_s, gtype_cmp_s, NULL);
hset_insert(s, gtype_s("aaaaa"));
hset_insert(s, gtype_s("bbbbb"));
hset_insert(s, gtype_s("ccccc"));
hset_insert(s, gtype_s("aaaaa"));
hset_insert(s, gtype_s("ccccc"));
hset_insert(s, gtype_s("bbbbb"));
printf("Số lượng giá trị duy nhất = %ld\n", hset_size(s));
hset_traverse(key, s) {
printf("%s\n", key->s);
}
hset_free(s);
return 0;
}
6 changes: 3 additions & 3 deletions hset.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void hset_gtype_free(gtype value);
#define hset_size(hs) (hs->size)

gtype *hset_next_pkey(hset_t, gtype*);
#define hset_traverse(key, value, map) \
for(gtype *key = hmap_next_pkey(map, NULL); \
key; key = hmap_next_pkey(map, key)) \
#define hset_traverse(key, map) \
for(gtype *key = hset_next_pkey(map, NULL); \
key; key = hset_next_pkey(map, key)) \

#endif // HSET_H_

0 comments on commit 43a5d97

Please sign in to comment.