summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-09-20 09:06:58 +0200
committerTyge Løvset <[email protected]>2020-09-20 09:06:58 +0200
commit927a1b015b7b934220edf9b5c758eed540f3e510 (patch)
treecd2f17dac6b18f776d52892981e8b5466fdf92b1
parent84dd4fe2a1e0768b199bebcbb9d59e9f7f57d3cc (diff)
downloadSTC-modified-927a1b015b7b934220edf9b5c758eed540f3e510.tar.gz
STC-modified-927a1b015b7b934220edf9b5c758eed540f3e510.zip
Fix.
-rw-r--r--examples/README.md16
1 files changed, 8 insertions, 8 deletions
diff --git a/examples/README.md b/examples/README.md
index 96a02584..fd5cd92b 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -8,7 +8,7 @@ Custom key example
This demonstrates how to customize **cmap** with a user-defined key-type. 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. If your key-type stores dynamic memory (e.g. cstr_t, as we will use), it is highly recommended to define a "raw"-struct representaion for your dynamic data struct. In addition, you must define two functions:
1. A hash function; calculates the hash value given an object of the key-type.
-2. A comparison function for equality;
+2. A comparison function for equality;
First, the Viking struct with destructor function:
```C
@@ -52,7 +52,7 @@ static inline Viking viking_fromRaw(VikingRaw vw) { // note: parameter is by val
```
With this in place, we use the full using_cmap() macro to define {Viking -> int} hash map type:
```C
-using_cmap(vk, Viking, int, c_default_del, vikingraw_equals, vikingraw_hash,
+using_cmap(vk, Viking, int, c_default_del, vikingraw_equals, vikingraw_hash,
viking_del, VikingRaw, viking_toRaw, viking_fromRaw);
```
cmap_vk uses vikingraw_hash() for hash value calculations, and vikingraw_equals() for equality test. cmap_vk_del() will free all memory allocated for Viking keys and the hash table values. Finally, main which also demos the generic c_push_items() of multiple elements:
@@ -60,15 +60,15 @@ cmap_vk uses vikingraw_hash() for hash value calculations, and vikingraw_equals(
int main() {
cmap_vk vikings = cmap_INIT;
c_push_items(&vikings, cmap_vk, {
- {{"Einar", "Norway"}, 20},
- {{"Olaf", "Denmark"}, 24},
- {{"Harald", "Iceland"}, 12},
+ { {"Einar", "Norway"}, 20},
+ { {"Olaf", "Denmark"}, 24},
+ { {"Harald", "Iceland"}, 12},
});
-
+
VikingRaw look = {"Einar", "Norway"};
-
+
cmap_vk_entry_t *e = cmap_vk_find(&vikings, look);
- e->second += 5; // add
+ e->second += 5; // add
cmap_vk_emplace(&vikings, look, 0)->second += 5; // update again
c_foreach (k, cmap_vk, vikings) {