summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md12
-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
7 files changed, 20 insertions, 20 deletions
diff --git a/README.md b/README.md
index 689a62bd..55862655 100644
--- a/README.md
+++ b/README.md
@@ -73,11 +73,11 @@ int main() {
```
CHash map of int -> int
```
-#include <stc/cmap.h>
+#include <stc/chash.h>
declare_CHash(ii, map, int, int);
int main() {
- CHash_ii nums = cmap_init;
+ CHash_ii nums = chash_init;
chash_ii_put(&nums, 8, 64);
chash_ii_put(&nums, 11, 121);
@@ -88,12 +88,12 @@ int main() {
CHash set of CString
```
#include <stc/cstring.h>
-#include <stc/cmap.h>
+#include <stc/chash.h>
declare_CHash_string(s, set); // Shorthand macro for the general declare_CHash expansion.
// CString keys are managed internally, although CHash is ignorant of CString.
int main() {
- CHash_s words = cmap_init;
+ CHash_s words = chash_init;
chash_s_put(&words, "Hello");
chash_s_put(&words, "Groovy");
chash_s_erase(&words, "Hello");
@@ -107,11 +107,11 @@ int main() {
CHash map of CString -> CString. Temporary CString values are created by "make", and moved to the container
```
#include <stc/cstring.h>
-#include <stc/cmap.h>
+#include <stc/chash.h>
declare_CHash_string(ss, map, CString, cstring_destroy);
int main() {
- CHash_ss table = cmap_init;
+ CHash_ss table = chash_init;
chash_ss_put(&table, "Make", cstring_make("my"));
chash_ss_put(&table, "Sunny", cstring_make("day"));
printf("Sunny: %s\n", chash_ss_get(table, "Sunny")->value.str);
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