https://github.com/djblue/map.c
My simple implementation of a map for fun.
https://github.com/djblue/map.c
Last synced: 16 days ago
JSON representation
My simple implementation of a map for fun.
- Host: GitHub
- URL: https://github.com/djblue/map.c
- Owner: djblue
- License: mit
- Created: 2015-04-05T22:03:58.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-10T05:43:15.000Z (almost 11 years ago)
- Last Synced: 2025-01-19T13:36:48.542Z (12 months ago)
- Language: C
- Size: 117 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# map.c
[](https://travis-ci.org/djblue/map.c)
Basic map written in c. There currently is no hash function because keys
are expected to be integers, although adding a hashing function would be
super simple; it just happened for my use case, I didn't need a hash
function.
NOTE: All values are expected to be pointers.
# building
To build the project, do:
make
# test
All of the tests are in the `main.c` file.
To run all the test, do:
make test
# methods
Below are all the supported methods of the hash map.
## map_create()
Will create and return a hash map with `MAP_NUM_BUCKET` buckets.
Example:
```c
map *m = map_create();
// use m
```
## map_create_n(n)
Will create and return a hash map with `1024` buckets.
```c
map *m = map_create_n(1024);
// use m
```
## map_free(m)
Will free a previously created map.
```c
map *m = map_create();
map_free(m);
```
## map_set(m, key, value)
Will set a key to the supplied value.
```c
int i = 1234;
// will store reference to i with key = 0.
map_set(m, 0, &i);
```
## map_unset(m, key)
Will remove key 0 from map.
```c
map_set(m, 0);
```
## map_get(m, key)
Get value for a given key from map m.
```c
map_get(m, 0);
```
## map_has(m, key)
Check if the map has a given key.
```c
map_has(m, 0);
```