summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-03-04 23:37:39 +0100
committerGitHub <[email protected]>2020-03-04 23:37:39 +0100
commit9e2fe2c3d39a2935f218954f3447bc25c0148684 (patch)
treeb2e1fad3934d1ba87ed96aafb3a5b02f3ed0bf35
parentfe30df42ee433a17636b02bc2df45337e96f1ced (diff)
downloadSTC-modified-9e2fe2c3d39a2935f218954f3447bc25c0148684.tar.gz
STC-modified-9e2fe2c3d39a2935f218954f3447bc25c0148684.zip
Update README.mc
-rw-r--r--README.md77
1 files changed, 76 insertions, 1 deletions
diff --git a/README.md b/README.md
index 929aae14..786d1e15 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,78 @@
# C99Containers
-Generic C99 Containers: CString, CVector and CMap classes, fully generic with ownership management etc. Very efficient.
+Introduction
+------------
+Typesafe, efficient, generic C99 containers: CString, CVector and CMap
+
+Headers only library with the most useful data structures: string, dynamic vector/stack, and map/assosiative array.
+
+The map is using open hashing with a novel probing strategy (fibonacci sequence), which is as efficient as quadratic probing, but has none of its limitations (max half full table, and prime number table length only requirements).
+
+The library has a very intuitive and straight forward API, and as mentioned is fully type safe. It uses "overloadable macros", to simplify usage.
+
+Usage
+-----
+Simple CVector:
+```
+#include "cvector.h"
+declare_CVector(ix, int64_t); // ix is just an example tag name, use anything.
+
+CVector(ix) bignums = cvector_initializer; // use cvector_ix_init(); if initializing after declaration.
+cvector_ix_reserve(&bignums, 1000);
+for (int i = 0; i<1000; ++i)
+ cvector_ix_push(&bignums, i * i);
+
+uint64_t value;
+for (int i = 0; i < cvector_size(bignums); ++i)
+ value = bignums.data[i];
+cvector_ix_destroy(&bignums);
+```
+CVector of CString
+```
+#include "cstring.h"
+#include "cvector.h"
+declare_CVector(cs, CString, cstring_destroy); // supply inline destructor of values
+
+CVector(cs) names = cvector_initializer;
+cvector_cs_push(&names, cstring_make("Mary"));
+cvector_cs_push(&names, cstring_make("Joe"));
+printf("%s\n", names.data[1].str); // Access the string char*
+cvector_cs_destroy(&names);
+```
+Simple CMap, int -> int.
+```
+#include "cmap.h"
+declare_CMap(ii, int, int);
+
+CMap(ii) nums = cmap_initializer;
+cmap_ii_put(&nums, 8, 64);
+cmap_ii_put(&nums, 11, 121);
+printf("%s\n", cmap_ii_get(&nums, 8)->value);
+cmap_ii_destroy(&nums);
+```
+Simple CMap with CString keys -> int values
+```
+#include "cmap.h"
+declare_CMap_STR(si, int); // Just a shorthand macro for the general declare call.
+// Keys strings are managed internally, although CMap is ignorant of CString.
+
+CMap(si) nums = cmap_initializer;
+cmap_si_put(&nums, "Hello", 64);
+cmap_si_put(&nums, "Groovy", 121);
+cmap_si_put(&nums, "Groovy", 200); // overwrite previous
+// iterate the map:
+for (CMapIter(si) i = cmap_si_begin(&nums); i.item != cmap_si_end(&nums); i = cmap_si_next(i))
+ printf("%s: %d\n", i.item->key.str, i.item->value);
+cmap_si_destroy(&nums);
+```
+CMap with CString keys, and CString values. Values are not handled internally.
+```
+#include "cmap.h"
+declare_CMap_STR(ss, CString, cstring_destroy);
+
+CMap(ss) table = cmap_initializer;
+cmap_ss_put(&table, "Hello", 64);
+cmap_ss_put(&table, "Groovy", 121);
+printf("%s\n", cmap_ss_get(&table, "Groovy")->value.str);
+cmap_ss_destroy(&table); // frees key and value CStrings, and hash table (CVector).
+```