|
|
@ -68,9 +68,16 @@ int main() {
|
|
|
|
user = hashmap_get(map, &(struct user){ .name="Tom" });
|
|
|
|
user = hashmap_get(map, &(struct user){ .name="Tom" });
|
|
|
|
printf("%s\n", user?"exists":"not exists");
|
|
|
|
printf("%s\n", user?"exists":"not exists");
|
|
|
|
|
|
|
|
|
|
|
|
printf("\n-- iterate over all users --\n");
|
|
|
|
printf("\n-- iterate over all users (hashmap_scan) --\n");
|
|
|
|
hashmap_scan(map, user_iter, NULL);
|
|
|
|
hashmap_scan(map, user_iter, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t iter = 0;
|
|
|
|
|
|
|
|
void *item;
|
|
|
|
|
|
|
|
while (hashmap_iter(map, &iter, &item)) {
|
|
|
|
|
|
|
|
const struct user *user = item;
|
|
|
|
|
|
|
|
printf("%s (age=%d)\n", user->name, user->age);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
hashmap_free(map);
|
|
|
|
hashmap_free(map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -81,7 +88,7 @@ int main() {
|
|
|
|
// Dale age=44
|
|
|
|
// Dale age=44
|
|
|
|
// not exists
|
|
|
|
// not exists
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- iterate over all users --
|
|
|
|
// -- iterate over all users (hashmap_scan) --
|
|
|
|
// Dale (age=44)
|
|
|
|
// Dale (age=44)
|
|
|
|
// Roger (age=68)
|
|
|
|
// Roger (age=68)
|
|
|
|
// Jane (age=47)
|
|
|
|
// Jane (age=47)
|
|
|
@ -104,7 +111,8 @@ hashmap_clear # clear the hash map
|
|
|
|
### Iteration
|
|
|
|
### Iteration
|
|
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
```sh
|
|
|
|
hashmap_scan # iterate over items in hash map
|
|
|
|
hashmap_iter # loop based iteration over all items in hash map
|
|
|
|
|
|
|
|
hashmap_scan # callback based iteration over all items in hash map
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Hash helpers
|
|
|
|
### Hash helpers
|
|
|
|