{"id":27650812,"url":"https://github.com/grgomariani/layered-hashmap-cpp","last_synced_at":"2025-04-24T03:48:08.080Z","repository":{"id":287229600,"uuid":"109444427","full_name":"GrgoMariani/Layered-HashMap-Cpp","owner":"GrgoMariani","description":"Chinese remainder theorem based hashmap (hash table, unordered map). Instead of creating one hashmap and chaining the elements into linked lists it creates new hashmaps.","archived":false,"fork":false,"pushed_at":"2019-08-20T07:48:26.000Z","size":852,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-24T03:48:04.649Z","etag":null,"topics":["cpp","data-structures-algorithms","hashing","hashmap","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GrgoMariani.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,"zenodo":null}},"created_at":"2017-11-03T21:28:07.000Z","updated_at":"2023-09-22T21:06:14.000Z","dependencies_parsed_at":"2025-04-10T17:09:38.823Z","dependency_job_id":"c406f4d3-5040-472d-bfff-295716d86877","html_url":"https://github.com/GrgoMariani/Layered-HashMap-Cpp","commit_stats":null,"previous_names":["grgomariani/layered-hashmap-cpp"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrgoMariani%2FLayered-HashMap-Cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrgoMariani%2FLayered-HashMap-Cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrgoMariani%2FLayered-HashMap-Cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrgoMariani%2FLayered-HashMap-Cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GrgoMariani","download_url":"https://codeload.github.com/GrgoMariani/Layered-HashMap-Cpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250560007,"owners_count":21450168,"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":["cpp","data-structures-algorithms","hashing","hashmap","map"],"created_at":"2025-04-24T03:48:07.502Z","updated_at":"2025-04-24T03:48:08.069Z","avatar_url":"https://github.com/GrgoMariani.png","language":"C++","readme":"## Chinese Remainder Theorem based HashMap (Layered Hash Table)\nA C++11 header for HashMap structure\n\n### Info\nA project of mine made some time ago. While tinkering about HashMaps I realized I could do a really simple auto-dynamically-allocating one.\n\nBy using the properties of `Chinese Remainder Theorem` we can achieve extremely quick read and writes, as well as keeping the memory allocation low as it can be.\n\nTested on a ridiculously big number of objects. Could be used to find 1 in 10^9 (1000000000) objects by using only 16GB of space - average search depth is 2.26 reads, maximum search depth is 7 reads - so yeah, really really fast.\nIt can be set to go even faster (avg 1.4 max 5).\n\nFor those that are interested you can read more in the included [PDF file](ShortExplanation.pdf).\n\n### Install\nClone the repo and just `make` . The repo supports MinGW and Linux.\n\nThis will only compile the example, but what more do you need.\n\nYou can find the executables in `build/crt_hashmap_example` and `build/stdlib_hashmap_example`.\n\n## Benchmark\nCheck the makefile. You can either compile my version of the HashMap or the stdlib `std::unordered_map\u003c\u003e` .\nThe Sources are _wrapped_.\n\nBy uncommenting-commenting just two lines in the makefile _(yes, it's commented where to do it)_ you can check the code against the stdlib implementation.\n\nCurrently, I see this as an absolute win. However, please try using this on different datasets.\n\n\n### Usage\nThe namespace used is CRT (as in Chinese Remainder Theorem). You can check sample usage in example.cpp file.\nTo create an empty HashMap use\n```C++\n CRT::HashMap\u003cstring, int\u003e hash;   //! string to int mapping\n```\nThis creates an empty HashMap of size 10000 elements, that uses ascending memory allocation.\nShould you want to create a bigger default HashMap or set the memory allocation as descending you can use the constructor. I would recommend setting the default HashMap to 0.7*Probable_number_of_your_objects\n```C++\n CRT::HashMap\u003cstring, float\u003e hash(10000000, true); \n // Reserves 10 000 000 objects in the memory and sets the dynamic memory allocation to true\n // Key=string , Value=float\n```\n\nIf you would like to compile with some other template pair include it in the .cpp files for now.\n\n### Future\n\nI've got some changes I need to do. _(benchmarks against stdlib, further optimize speed, simplify usage, improve debug and logging, auto-optimization, ...)_\n\n### Example\nTo compile the included example\n```console\n make\n```\n\n### Methods\n\n#### void put(Key, Value)\n\n![put-algo](GIFS/put.gif)\n\n```C++\n hashmap.put(\"requested key\", Value);\n // maps Value to \"requested key\", if it fails to do so in this block, it allocates new block of memory for the next block\n // Overwrites the old value if found\n```\nThe method also automatically optimizes the hashmap\n\n#### bool get(key, value)\n\n![get-algo](GIFS/get.gif)\n\n```C++\n if( hashmap.get(\"requested key\", value) )\n {\n\tresult=value;\n\t//If this is true then the Value is stored in value (nonreferenced). //Copy constructor on value needed\n }\n else\n {\n\t//no \"requested key\" found\n }\n```\nThe method automatically optimizes the hashmap where it can\n\n#### void remove(key)\n\n![remove-algo](GIFS/remove.gif)\n\n```C++\n hashmap.remove( \"requested key\") )\n // removes the \"requested key\" mapping from memory\n```\n#### void clear()\n```C++\n hashmap.clear()\n //deallocates all blocks and allocates one block of the same size as it started with\n```\n\n### Other\nShould you use your custom object as value don't forget to assign the correct copy constructor for it.\n\n~~I've commented a few methods I didn't use but you could find useful. HashMap::print_all() prints all elements of the table and the flags on positions. Feel free to uncomment it in 'Block.h' 'and HashMap.h' and use.~~\nYou can now use the VERBOSE_DEBUG define flag while compiling.\n\nThe structure could be easily re-purposed to read from HardDrive instead of RAM should you have even more elements, or even made with multi-thread support to get the best out of the speed and memory allocation.\n\nOr both.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrgomariani%2Flayered-hashmap-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrgomariani%2Flayered-hashmap-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrgomariani%2Flayered-hashmap-cpp/lists"}