{"id":21832702,"url":"https://github.com/winterrdog/c-hash-map","last_synced_at":"2025-03-21T13:43:43.328Z","repository":{"id":234667117,"uuid":"789345885","full_name":"winterrdog/c-hash-map","owner":"winterrdog","description":"this is a pure C project i took on to learn the details of how to implement a hash table aka hash map aka associative array.","archived":false,"fork":false,"pushed_at":"2024-05-05T15:11:56.000Z","size":38,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T09:27:19.818Z","etag":null,"topics":["computer-science","data-structures","hash","hashmap","hashtable"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/winterrdog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-20T09:28:57.000Z","updated_at":"2024-06-25T12:21:04.000Z","dependencies_parsed_at":"2024-04-23T19:55:11.993Z","dependency_job_id":"35b3e791-d596-4b89-96cb-25df8e90972c","html_url":"https://github.com/winterrdog/c-hash-map","commit_stats":null,"previous_names":["winterrdog/custom-hash-table"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterrdog%2Fc-hash-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterrdog%2Fc-hash-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterrdog%2Fc-hash-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterrdog%2Fc-hash-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/winterrdog","download_url":"https://codeload.github.com/winterrdog/c-hash-map/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244807278,"owners_count":20513607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-science","data-structures","hash","hashmap","hashtable"],"created_at":"2024-11-27T19:25:01.915Z","updated_at":"2025-03-21T13:43:43.307Z","avatar_url":"https://github.com/winterrdog.png","language":"C","readme":"# ABOUT REPO\n\nThis is a hash table implementation in C with functions to _insert/update, search, create, get size,_ and _delete_ the hash table. It only operates on string keys and string values ONLY. It handles collisions using _open addressing with double hashing_ which is the most used technique for most production-level hash tables. The hash table is implemented using a _dynamic array_ so it can grow and shrink as needed based on the current load factor. Inspired by @jamesroutley's [implementation](https://github.com/jamesroutley/algorithms-and-data-structures/tree/master/hash-table). _I made drastic changes in some algorithms and fixed all memory bugs_.\n\nNo memory leaks or `OOB` writes are possible in this program ( _at least to the limit of my knowledge_ ), you can verify that with:\n\n```sh\ncd src \u0026\u0026 gcc -ggdb3 -fsanitize=address -o hash_table hash_table.c main.c prime.c xmalloc.c -lm\n```\n\nIn short, this C program can be considered _memory-safe_.\n\n## Requirements\n\n- `gcc`\n- Compatible with any operating system that supports `gcc`\n\n## Hash Table C API\n\nThese are the functions provided by the hashmap as of now( all located in `src/hash_table.h` ):\n\n```c\n// custom types\ntypedef struct\n{\n    const char* key;\n    const char* value;\n} ht_item; // hash table entry -- represents a key-value pair\ntypedef struct\n{\n    size_t size;\n    size_t base_size;\n    size_t count;\n    ht_item** items;\n} ht_hash_table; // hash table structure -- represents the hash table\n\n// function prototypes\nht_hash_table* ht_new(); // 'creates' new hash table\nvoid ht_del_hash_table(ht_hash_table* t); // 'deletes' an existing hash table\nvoid ht_insert(ht_hash_table* table, const char* k, const char* v); // 'inserts' a new key-value pair\nvoid ht_delete(ht_hash_table* table, const char* k); // 'deletes' a key-value pair from the hash table\nconst char* ht_search(ht_hash_table* table, const char* k); // 'searches' for a key in the hash table\nsize_t ht_size(ht_hash_table* table); // get number of elements in hash table\n```\n\n## Usage\n\n- Run the following command to compile the program:\n\n```bash\n./compile.sh\n```\n\n- Run the following command to execute the program:\n\n```bash\n./hash_table\n```\n\nThis will run the driver program in `src/main.c` which demonstrates the usage of the hash table functions but it won't output anything to the console. You can modify the `main.c` file to test the hash table functions as you like. No output will indicate that the program ran successfully otherwise it will throw an error and exit.\n\n## TODO\n\n- Add support for multiple data types\n\n## NOTE\n\nThis hashmap can be used in production-level code. It can be used as a good base to make another custom hash table.\n\nFor any issues or PRs you can always let me know.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinterrdog%2Fc-hash-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinterrdog%2Fc-hash-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinterrdog%2Fc-hash-map/lists"}