{"id":19110894,"url":"https://github.com/h2co3/hash_table","last_synced_at":"2025-04-30T20:47:51.108Z","repository":{"id":141621217,"uuid":"63640508","full_name":"H2CO3/hash_table","owner":"H2CO3","description":"Fast, data-oriented, stdlib-style hash table","archived":false,"fork":false,"pushed_at":"2017-01-17T23:18:45.000Z","size":13,"stargazers_count":21,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-19T08:34:19.219Z","etag":null,"topics":["cpp","cpp14","data-oriented","hash-map","hash-table","lookup"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/H2CO3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-07-18T22:08:26.000Z","updated_at":"2023-10-11T20:48:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"81c92ea8-7d90-49ff-a70d-bf444bd77bff","html_url":"https://github.com/H2CO3/hash_table","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/H2CO3%2Fhash_table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/H2CO3%2Fhash_table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/H2CO3%2Fhash_table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/H2CO3%2Fhash_table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/H2CO3","download_url":"https://codeload.github.com/H2CO3/hash_table/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251780927,"owners_count":21642863,"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","cpp14","data-oriented","hash-map","hash-table","lookup"],"created_at":"2024-11-09T04:26:26.662Z","updated_at":"2025-04-30T20:47:51.089Z","avatar_url":"https://github.com/H2CO3.png","language":"C++","readme":"A fast, data-oriented, stdlib-flavored hash table\n=======\n\nThis repo contains the implementation of a fast (both for lookup and insertion) hash table, with an interface similar to that of C++ standard library collection types.\n\nThe algorithm is inspired by what's found in Apple's Objective-C runtime: rather than using the classic \"tombstone\" or \"dummy value\" approach for deleted key-value pairs, this variant always compares even deleted values in a collision sequence, however the global maximum of collision sequence lengths is stored and lookup terminates once a sequence of this length has been traversed without finding a match.\n\nThe table also expands its internal storage in chunks of powers of two, so bit twiddling can be used for modular arithmetic rather than the more expensive true integer division.\n\nUsage\n-----\n\n\t#include \"hash_table.hh\"\n\n    hash_table\u003cKeyType, ValueType\u003e table;\n    \n    // an optional capacity may be specified\n    // in the constructor. It need not be a power of 2.\n    hash_table\u003cKeyType, ValueType\u003e table_with_capacity(1000);\n    \n    // custom hash and equality comparator function objects\n    // may also be provided if necessary:\n    hash_table\u003cKeyType, ValueType, Hash, EqCmp\u003e customized_table;\n    \n    // As with std::unordered_map::operator[],\n    // our implementation of operator[] also\n    // value-initializes non-existent entries.\n    table[\"foo\"] = \"bar\";\n    table[\"qux\"]; // ValueType{}\n    \n    // .find() for those who \u003c3 iterators\n    if (table.find(\"qux\") == table.end()) {\n        std::printf(\"key not found\\n\");\n    }\n    \n    // and in general, there's an iterator-based API\n    // begin(), end(), cbegin(), cend(), etc. all work\n    for (auto \u0026entry : table) {\n        do_stuff_with(entry.key, entry.value);\n    }\n    \n    auto it = table.find(\"some key\");\n    if (it != table.end()) {\n        table.erase(it); // erase it!\n    }\n    \n    // But my preferred interface is get*() and set():\n    if (auto *valptr = table.get(\"foo\")) {\n        std::printf(\"found it: %s\\n\", valptr-\u003ec_str());\n    }\n    \n    auto answer = table.get_or(\"answer\", \"42\");\n    table.remove(\"answer\");\n    \n    // Of course, size() and empty() work too!\n    std::size_t num_keys = table.size();\n    bool is_empty = table.empty();\n    \n    // For debugging purposes only: load factor!\n    double lf = table.load_factor();\n\nLicense\n-------\n2-clause BSD. [if this is a problem for you, ping me and we'll find a solution. I'm no lawyer `:-)`]\n\nTODO\n----\n* include some benchmarks (my experience shows that this is generally ≥5 times faster than `std::unordered_map`, depending on the exact use case.)\n* tests\n* maybe more/better usage examples?\n* unicorns!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2co3%2Fhash_table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh2co3%2Fhash_table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2co3%2Fhash_table/lists"}