summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--advanced_example.c2
-rw-r--r--advanced_example.md22
-rw-r--r--benchmark.c2
-rw-r--r--demos.c2
-rw-r--r--stc/chash.h (renamed from stc/cmap.h)0
-rw-r--r--stc/coption.h (renamed from stc/copt.h)0
6 files changed, 14 insertions, 14 deletions
diff --git a/advanced_example.c b/advanced_example.c
index b85b433e..6649ab29 100644
--- a/advanced_example.c
+++ b/advanced_example.c
@@ -9,7 +9,7 @@ The difficulty with the hash function is that if your key type consists of sever
Assuming a key-type like this, and want string as value, we define the functions person_make(), person_destroy() and person_compare():
```*/
#include <stdio.h>
-#include "stc/cmap.h"
+#include "stc/chash.h"
#include "stc/cstring.h"
struct Person {
diff --git a/advanced_example.md b/advanced_example.md
index 0206d4a2..031db20d 100644
--- a/advanced_example.md
+++ b/advanced_example.md
@@ -9,7 +9,8 @@ The difficulty with the hash function is that if your key type consists of sever
Assuming a key-type like this, and want string as value, we define the functions person_make(), person_destroy() and person_compare():
```
#include <stdio.h>
-#include <stc/cmap.h>
+
+#include <stc/chash.h>
#include <stc/cstring.h>
struct Person {
@@ -64,27 +65,26 @@ size_t personview_hash(const struct PersonView* pv, size_t ignore) {
```
With this in place, we can declare the map Person -> int:
```
-declare_CMap(ex, struct Person, int, c_noDestroy, person_destroy,
- struct PersonView, personview_hash, personview_compare,
- person_getView, person_fromView);
+declare_CHash(ex, map, struct Person, int, c_emptyDestroy, personview_hash, personview_compare,
+ struct PersonView, person_destroy, person_getView, person_fromView);
```
Note we use struct PersonView to put keys in the map, but keys are stored as struct Person with proper dynamically allocated CStrings to store name and surname.
```
int main()
{
- CMap_ex m6 = cmap_init;
- cmap_ex_put(&m6, (struct PersonView){"John", "Doe", 24}, 1001);
- cmap_ex_put(&m6, (struct PersonView){"Jane", "Doe", 21}, 1002);
- cmap_ex_put(&m6, (struct PersonView){"John", "Travolta", 66}, 1003);
+ CMap_ex m6 = chash_init;
+ chash_ex_put(&m6, (struct PersonView){"John", "Doe", 24}, 1001);
+ chash_ex_put(&m6, (struct PersonView){"Jane", "Doe", 21}, 1002);
+ chash_ex_put(&m6, (struct PersonView){"John", "Travolta", 66}, 1003);
- c_foreach (it, cmap_ex, m6) {
+ c_foreach (it, chash_ex, m6) {
if (cstring_equals(it.item->key.name, "John"))
printf("%s %s %d -> %d\n", it.item->key.name.str, it.item->key.surname.str, it.item->key.age,
it.item->value);
}
- cmap_ex_destroy(&m6);
+ chash_ex_destroy(&m6);
}
```
-CMap uses personview_hash() for hash value calculations, and the personview_compare() for equality checks. The cmap_ex_destroy() function will free CStrings name, surname and the value for each item in the map, in addition to the CMap hash table itself.
+CMap uses personview_hash() for hash value calculations, and the personview_compare() for equality checks. The chash_ex_destroy() function will free CStrings name, surname and the value for each item in the map, in addition to the CMap hash table itself.
diff --git a/benchmark.c b/benchmark.c
index 72e47699..7d0c9e48 100644
--- a/benchmark.c
+++ b/benchmark.c
@@ -1,6 +1,6 @@
#include "stc/crandom.h"
#include "stc/cstring.h"
-#include "stc/cmap.h"
+#include "stc/chash.h"
#include "others/khash.h"
#include <stdio.h>
diff --git a/demos.c b/demos.c
index 18be0e00..5735a900 100644
--- a/demos.c
+++ b/demos.c
@@ -1,6 +1,6 @@
#include "stc/cvector.h"
#include "stc/clist.h"
-#include "stc/cmap.h"
+#include "stc/chash.h"
#include "stc/cstring.h"
diff --git a/stc/cmap.h b/stc/chash.h
index a53f7d75..a53f7d75 100644
--- a/stc/cmap.h
+++ b/stc/chash.h
diff --git a/stc/copt.h b/stc/coption.h
index 78500210..78500210 100644
--- a/stc/copt.h
+++ b/stc/coption.h