{"id":15683952,"url":"https://github.com/barrust/hashmap","last_synced_at":"2025-05-07T14:41:02.070Z","repository":{"id":53755350,"uuid":"42628994","full_name":"barrust/hashmap","owner":"barrust","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-07T14:13:51.000Z","size":84,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T11:02:13.745Z","etag":null,"topics":["c","hash-map","hash-table","hashmap","hashtable","map"],"latest_commit_sha":null,"homepage":null,"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/barrust.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-17T02:19:58.000Z","updated_at":"2022-12-30T09:17:12.000Z","dependencies_parsed_at":"2022-09-02T14:23:44.416Z","dependency_job_id":null,"html_url":"https://github.com/barrust/hashmap","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrust%2Fhashmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrust%2Fhashmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrust%2Fhashmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrust%2Fhashmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barrust","download_url":"https://codeload.github.com/barrust/hashmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252897313,"owners_count":21821419,"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":["c","hash-map","hash-table","hashmap","hashtable","map"],"created_at":"2024-10-03T17:09:19.917Z","updated_at":"2025-05-07T14:41:02.043Z","avatar_url":"https://github.com/barrust.png","language":"C","readme":"# hashmap\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![GitHub release](https://img.shields.io/github/v/release/barrust/hashmap.svg)](https://github.com/barrust/hashmap/releases)\n[![C/C++ CI](https://github.com/barrust/hashmap/workflows/C/C++%20CI/badge.svg?branch=master)](https://github.com/barrust/hashmap/actions)\n[![codecov](https://codecov.io/gh/barrust/hashmap/branch/master/graph/badge.svg)](https://codecov.io/gh/barrust/hashmap)\n\nHashmap implementation written in **C**\n\nHashmaps are a key value store with quick look up times. The hashmap_stats()\nfunction will provide a summary of the current lookup times including average,\nworst case key not found, and worst case key found.\n\nThis hashmap implementation is a simple and, generally, quick method to include\na hashmap in C programs. It was developed to provide a basis for testing and\nbenchmarking performance along with providing a purposeful, low overhead\nlibrary.\n\nTo use the library, copy the `src/hashmap.h` and `src/hashmap.c` files into your\nproject, compile and link the library, and include it where needed.\n\n**NOTE:** The key is of type `char*` as in a `c-string`\n\n## License\nMIT 2016\n\n## Usage:\n``` c\n#include \"hashmap.h\"\n\nHashMap h;\nhashmap_init(\u0026h);\n\nhashmap_set_string(\u0026h, \"google\", \"search engine, android, web ads\");\nhashmap_set_string(\u0026h, \"facebook\", \"social media site\");\nhashmap_set_string(\u0026h, \"twitter\", \"the sound of little birds\");\n\nchar* tmp = (char*)hashmap_get(\u0026h, \"google\");\nif (tmp == NULL) {\n    printf(\"'google' was not in the hashmap\\n\");\n} else {\n    printf(\"key: test\\tvalue: %s\\n\", tmp);\n    hashmap_set_string(\u0026h, \"google\", \"search engine, android, web ads, and automobiles\");\n}\n\nhashmap_stats(\u0026h);\nhashmap_destroy(\u0026h);\n```\n\n## Thread safety\n\nDue to the the overhead of enforcing thread safety, it is up to the user to\nensure that each thread has controlled access to the hashmap. For **OpenMP**\ncode, the following should suffice.\n\n``` c\n#include \"set.h\"\n#include \u003comp.h\u003e\n\nint main(int argc, char** argv) {\n    HashMap h;\n    hashmap_init(\u0026h);\n\n    #pragma omp parallel for\n    for (int i = 0; i \u003c 500000; i++) {\n        char key[KEY_LEN] = {0};\n        sprintf(key, \"%d\", i);\n\n        #pragma omp critical (hashmap_set_lock)\n        {\n            hashmap_add_int(\u0026h, key, i);\n        }\n    }\n    hashmap_destroy(\u0026h);\n}\n```\n\nGuards must be used when inserting and removing elements as the layout of the\nnodes may change. When there are only retrievals, `hashmap_get`, then there is\nno need for guards. If the retrievals are simultaneous to the insertions and\ndeletions then guards must be placed around `hashmap_get` to ensure that the\nnode location doesn't change.\n\n## Required Compile Flags:\nNone\n\n### Future Enhancements:\n* Allow for sorting from the `hashmap_keys` function\n* Prove if relaying out nodes needs to do more than 1 loop\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarrust%2Fhashmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarrust%2Fhashmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarrust%2Fhashmap/lists"}