v1.3.0
This commit is contained in:
35
README.md
35
README.md
@@ -1,3 +1,36 @@
|
||||
# hm.h
|
||||
|
||||
A single header library that implements chained hash table in C.
|
||||
A single header, C11 compliant, library that implements a
|
||||
[hash table](https://en.wikipedia.org/wiki/Hash_table#Separate_chaining)
|
||||
in C using separate chaining.
|
||||
|
||||
## Example
|
||||
|
||||
```c
|
||||
#define HM_IMPLEMENTATION
|
||||
#include "hm.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
HashMap ages = {0}; // or hm_create(...) to specify custom key and
|
||||
// value sizes, a size of 0 means a NULL
|
||||
// terminated string
|
||||
|
||||
hm_put(&ages, "alice", "30");
|
||||
hm_put(&ages, "bob", "25");
|
||||
|
||||
char *alice = hm_get(&ages, "alice"); // NULL if key is not found
|
||||
printf("alice is %s\n", alice);
|
||||
|
||||
HashMapIterator it = hm_iterate(&ages);
|
||||
while (hm_next(&it) != NULL) {
|
||||
printf("%s: %s\n", (const char*)hm_key(&it), (char*)hm_value(&it));
|
||||
}
|
||||
|
||||
hm_free(&ages); // The HashMap can still be reused
|
||||
return 0;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user