summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-07-12 05:10:32 +0200
committerGitHub <[email protected]>2020-07-12 05:10:32 +0200
commit6ea915f62d7e8ce12c8dd9b6707f80822fbfd267 (patch)
tree5136c207fc4dc90592549d9e581d67e57c56c916
parent3e0e248a229d416a9c02fbb676ec86b5e72af99f (diff)
downloadSTC-modified-6ea915f62d7e8ce12c8dd9b6707f80822fbfd267.tar.gz
STC-modified-6ea915f62d7e8ce12c8dd9b6707f80822fbfd267.zip
Update README.md
-rw-r--r--README.md9
1 files changed, 6 insertions, 3 deletions
diff --git a/README.md b/README.md
index 1ebc3490..a4347b18 100644
--- a/README.md
+++ b/README.md
@@ -105,16 +105,19 @@ You may customize the destroy-, hash- and equals- function. It also supports a f
```
chash_si_put(&map, cstring_make("mykey"), 12);
```
-but the main problem is lookup:
+and the main incovenience is on lookup:
```
CString lookup = cstring_make("mykey");
int x = chash_si_get(&map, lookup)->value;
cstring_destroy(&lookup);
```
-The predefined shorthand macro *declare_CHash_string()* defines a CHash container with a CString as key, however this you may use it like:
+To avoid this, use *declare_CHash_string()*:
```
+declare_CHash_string(si, MAP, int);
+...
+CHash_si map = chash_init;
chash_si_put(&map, "mykey", 12); // constructs a CString key from the char* internally.
-int x = chash_si_get(&map, "mykey")->value; // no allocation of string key happens here, which is good.
+int x = chash_si_get(&map, "mykey")->value; // no allocation of string key happens here.
```
An alternative would be to use *char* * as key type, but you would have to manage the memory of the hash char* keys yourself.
Note that this customization is also available for **CVector**, but only affects the *find()* function currently. See *declare_CVector_string()*.