summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-07-15 16:14:47 +0200
committerTyge Løvset <[email protected]>2020-07-15 16:14:47 +0200
commitd75429864d14e744d251a7393d505584701f61cc (patch)
treed9b64c7758068344170a09bc5767fbc6b1fe825e
parent55917598781e64a5357c0a8aa7b4c18388dfd9ee (diff)
parent9047c69701c8b66f41bc26a2f25582f14f163f47 (diff)
downloadSTC-modified-d75429864d14e744d251a7393d505584701f61cc.tar.gz
STC-modified-d75429864d14e744d251a7393d505584701f61cc.zip
Merge branch 'master' of https://github.com/tylo-work/C99Containers
-rw-r--r--examples/README.md11
1 files changed, 5 insertions, 6 deletions
diff --git a/examples/README.md b/examples/README.md
index ef9cb19e..3658076c 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -13,8 +13,7 @@ This demonstrates how to customize **CHash map** with a user-defined key-type. Y
2. A comparison function for equality;
When your key type consists of several members, you will usually have the hash function calculate hash values for the individual members, and then somehow combine them into one hash value for the entire object.
-In order to use Viking as a map key, it is smart to define a plain-old-data "view" of the Viking struct first.
-
+If your key-type stores dynamic memory (e.g. CString as we will use), it is smart to define a plain-old-data "view" of the your key struct first:
```
#include <stdio.h>
#include <stc/chash.h>
@@ -38,7 +37,7 @@ int vikingvw_equals(const VikingVw* x, const VikingVw* y) {
}
```
-An the the Viking data struct:
+And then the Viking data struct:
```
typedef struct Viking {
CString name;
@@ -59,12 +58,13 @@ Viking viking_fromVw(VikingVw vw) {
}
```
-With this in place, we use the full declare_CHash() macro to define [Viking -> int] hash map type:
+With this in place, we use the full declare_CHash() macro to define {Viking -> int} hash map type:
```
declare_CHash(vk, MAP, Viking, int, c_emptyDestroy, vikingvw_hash, vikingvw_equals,
viking_destroy, VikingVw, viking_getVw, viking_fromVw);
```
-The demo program:
+CHash_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test. chash_vk_destroy() will free all memory allocated for Viking keys and the hash table values.
+Finally, the demo:
```
int main()
{
@@ -83,4 +83,3 @@ int main()
chash_vk_destroy(&vikings);
}
```
-CHash_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test. chash_vk_destroy() will free all memory allocated for Viking keys and the hash table values.