Changeset 7799d1d6f07fd24cc0cf0b784340f994374fc5b1
- Timestamp:
- 04/23/08 11:39:11 (9 months ago)
- Parents:
- b39568e8202274e6aed953a924659cef1f971d55
- Children:
- 8f9e905705f715e2dc4745a098e9a1819271873a
- git-committer:
- David Balmain <dbalmain@gmail.com> / 2008-04-23T11:39:11Z+1000
- Location:
- c
- Files:
-
- 4 modified
-
include/hashset.h (modified) (3 diffs)
-
include/internal.h (modified) (1 diff)
-
src/hashset.c (modified) (1 diff)
-
test/test_hashset.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
c/include/hashset.h
r48290f r7799d1 34 34 35 35 /** 36 * Create a new FrtHashSet. The function will allocate a FrtHashSet Struct setting37 * the functions used to hash the objects it will contain and the eq function.38 * This should be used for non-string types.36 * Create a new FrtHashSet. The function will allocate a FrtHashSet Struct 37 * setting the functions used to hash the objects it will contain and the eq 38 * function. This should be used for non-string types. 39 39 * 40 40 * @param hash function to hash objects added to the FrtHashSet … … 49 49 50 50 /** 51 * Create a new FrtHashSet specifically for strings. This will create a FrtHashSet 52 * as if you used frt_hs_new with the standard string hash and eq functions. 51 * Create a new FrtHashSet specifically for strings. This will create a 52 * FrtHashSet as if you used frt_hs_new with the standard string hash and eq 53 * functions. 53 54 * 54 55 * @param free_elem function used to free elements as added to the FrtHashSet … … 57 58 */ 58 59 extern FrtHashSet *frt_hs_new_str(frt_free_ft free_func); 60 61 /** 62 * Create a new FrtHashSet specifically for pointers. Note that the only way 63 * two pointers will be considered equal is if they have the same address. So 64 * you can add the string "key" twice if it is stored at two different 65 * addresses. 66 * 67 * @param free_elem function used to free elements as added to the FrtHashSet 68 * when the FrtHashSet if destroyed or duplicate elements are added to the Set 69 * @return a newly allocated FrtHashSet structure 70 */ 71 extern FrtHashSet *frt_hs_new_ptr(frt_free_ft free_func); 59 72 60 73 /** -
c/include/internal.h
rb39568 r7799d1 546 546 #define hs_merge frt_hs_merge 547 547 #define hs_new frt_hs_new 548 #define hs_new_ptr frt_hs_new_ptr 548 549 #define hs_new_str frt_hs_new_str 549 550 #define hs_orig frt_hs_orig -
c/src/hashset.c
r48290f r7799d1 29 29 HashSet *hs = hs_alloc(free_func); 30 30 hs->ht = h_new_str((free_ft) NULL, NULL); 31 return hs; 32 } 33 34 HashSet *hs_new_ptr(free_ft free_func) 35 { 36 HashSet *hs = hs_alloc(free_func); 37 hs->ht = h_new_ptr(NULL); 31 38 return hs; 32 39 } -
c/test/test_hashset.c
r48290f r7799d1 1 1 #include "hashset.h" 2 #include "intern.h" 2 3 #include "test.h" 3 4 … … 55 56 Aiequal(0, hs->size); 56 57 58 hs_destroy(hs); 59 } 60 61 static void test_hs_ptr(TestCase *tc, void *data) 62 { 63 HashSet *hs = hs_new_ptr(NULL); 64 const char *word1 = intern("one"); 65 const char *word2 = intern("two"); 66 char *word_one = estrdup("one"); 67 (void)data; /* suppress unused argument warning */ 68 69 Aiequal(0, hs->size); 70 71 Aiequal(HASH_KEY_DOES_NOT_EXIST, hs_add(hs, (void *)word1)); 72 Aiequal(1, hs->size); 73 Aiequal(HASH_KEY_SAME, hs_exists(hs, word1)); 74 Aiequal(HASH_KEY_DOES_NOT_EXIST, hs_exists(hs, "one")); 75 Aiequal(HASH_KEY_SAME, hs_add(hs, (void *)word1)); 76 Aiequal(1, hs->size); 77 78 Aiequal(HASH_KEY_DOES_NOT_EXIST, hs_add(hs, (void *)word2)); 79 Aiequal(2, hs->size); 80 Aiequal(HASH_KEY_SAME, hs_exists(hs, word2)); 81 Aiequal(HASH_KEY_DOES_NOT_EXIST, hs_exists(hs, "two")); 82 Aiequal(HASH_KEY_SAME, hs_add(hs, (void *)word2)); 83 Aiequal(2, hs->size); 84 85 Aiequal(HASH_KEY_DOES_NOT_EXIST, hs_add(hs, (void *)word_one)); 86 Aiequal(3, hs->size); 87 Aiequal(HASH_KEY_SAME, hs_exists(hs, word_one)); 88 Aiequal(HASH_KEY_DOES_NOT_EXIST, hs_exists(hs, "one")); 89 Aiequal(HASH_KEY_SAME, hs_add(hs, (void *)word_one)); 90 Aiequal(3, hs->size); 91 92 free(word_one); 57 93 hs_destroy(hs); 58 94 } … … 244 280 245 281 tst_run_test(suite, test_hs, NULL); 282 tst_run_test(suite, test_hs_ptr, NULL); 246 283 tst_run_test(suite, test_hs_add_safe, NULL); 247 284 tst_run_test(suite, test_hs_merge, NULL);
