// <-- go back to projects
git clone https://blmayer.dev/x/map zip
Browsing mainA simple map implementation in C that only costs 24 bytes per node. It uses linked lists under the hood and its performance, time and memmory, is proportional to the length of the object’s key.
Import the library in your .c
file with the directive #import <map.h>
. Now
you have access to the map
type, which will be used to store and retrieve
data, using the add
and get
functions respectively.
After using your map you must free it to avoid leaks, for that use the
destroy
function passing a pointer to your map.
/* Create the map structure */
map m;
/* Initialize it */
init(&m);
/* Now you can add strings to it */
char *data = "this is test data abc";
int ret = add(&m, "abc", data, strclen(data));
if (!ret) {
printf("Error: add returned %d\n", ret);
exit(1);
}
/* To retrieve data back use the get function */
char *res = get(&m, "abc");
puts(res);
/* Lastly, destroy the map */
int count = destroy(&m);
printf("map freed %d allocations.\n", count);
Type make
on the command line.
Type sudo make install
on the command line.
Type make test
on the command line, if any ERROR appears on the terminal
you should not install it yet.
Yes please!
MIT License Copyright (c) 2019 Brian Mayer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.