{"id":20180382,"url":"https://github.com/ppcamp/cpp_hasher","last_synced_at":"2025-05-07T03:30:29.390Z","repository":{"id":173770149,"uuid":"651270190","full_name":"ppcamp/cpp_hasher","owner":"ppcamp","description":"This is a case of study to check it out the benefits/tradeoffs for maps implementation. This repo uses vcpkg and CMake for package management/build.","archived":true,"fork":false,"pushed_at":"2023-06-10T21:20:30.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-03T05:43:45.049Z","etag":null,"topics":[],"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/ppcamp.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":"2023-06-08T22:10:17.000Z","updated_at":"2024-05-19T17:22:50.000Z","dependencies_parsed_at":"2023-09-29T06:05:46.442Z","dependency_job_id":null,"html_url":"https://github.com/ppcamp/cpp_hasher","commit_stats":null,"previous_names":["ppcamp/cpp_hasher"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppcamp%2Fcpp_hasher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppcamp%2Fcpp_hasher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppcamp%2Fcpp_hasher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppcamp%2Fcpp_hasher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ppcamp","download_url":"https://codeload.github.com/ppcamp/cpp_hasher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252806321,"owners_count":21807188,"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":[],"created_at":"2024-11-14T02:30:27.917Z","updated_at":"2025-05-07T03:30:29.372Z","avatar_url":"https://github.com/ppcamp.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cpp hasher\n\n\nThis is a case of study to check it out the benefits/tradeoffs for maps implementation.\n\n\u003e A simple example of how to implement a hash function/algorithm.\n\n## Introduction\n\nIn C++, we have `unordered_map`, which implements a hashtable and we also have `map`,\nwhich implements a `red black tree`¹. In\n[Go, we also have a builtin \"unordered map\" implementation](https://go.dev/src/runtime/map.go)\n\n### In `C++`:\n\nStage|map|unordered_map\n-----|---|----------\nOrdering| increasing order of keys(by default) | no ordering\nImplementation  | Self balancing BST  | Hash Table\n||(like Red-Black Tree)\nsearch time  | log(n)| O(1) -\u003e Average\n||| O(n) -\u003e Worst Case\nInsertion time  | log(n) + Rebalance  | Same as search\nDeletion time| log(n) + Rebalance  | Same as search\n\nSee [here](https://www.geeksforgeeks.org/map-vs-unordered_map-c/) for this table ref.\n\n\u003e Remember that for every new Map type (such as map\u003cint,int\u003e, map\u003cstring,int\u003e) we create a definition\n\u003e for it, and thus, increase the binary size.\n\n### In Golang:\n\nThe \"hashmap\" algorithm has some heuristics embeded in, therefore, the only problem\nwith the Go implementation is the \"resize\" factor, which may occurr too often if you don't known\nthe capacity at building time (a determinant factor to use `unordered_map` in C++).\n\n\n### Rust:\n\nHowever, the Rust team uses a different algorithm, now called as\n\"[SwissTable](https://abseil.io/blog/20180927-swisstables)\". This same algorithm can be found\nby the C++ [abseil lib](https://abseil.io/docs/cpp/).\n\n\nNote¹: See `/usr/include/c++/11/bits/stl_map.h`\n\n\n### Result:\n\n```bash\nBenchmarks:\n\n- bench insertion using my map: 24µs\n- bench insertion using Cpp map: 3µs\n- bench insertion using Cpp unordered map: 3µs\n```\n\n### See\n\n- https://www.digitalocean.com/community/tutorials/hash-table-in-c-plus-plus\n- https://medium.com/kalamsilicon/hash-tables-implementation-in-go-48c165c54553\n- https://www.youtube.com/watch?v=Tl7mi9QmLns\u0026ab_channel=GopherAcademy\n- https://abseil.io/blog/20180927-swisstables\n- https://www.youtube.com/watch?v=ncHmEUmJZf4\u0026ab_channel=CppCon\n- https://stackoverflow.com/a/3341737\n- https://datastructures.maximal.io/hash-tables/\n- http://google.github.io/googletest/reference/assertions.html\n\n## Dependecies\n\nThis repo also [vcpkg](https://github.com/microsoft/vcpkg#using-vcpkg-with-cmake)\nto manage dependencies. All building process is done by using `Cmake`.\nFor unit tests, this repo uses the\n[Google test suite](http://google.github.io/googletest/quickstart-cmake.html)\n\n\n```bash\n# Installing Cmake deps (to work in multi platform)\nsudo apt install cmake pkg-config\n\n# Installing the debugger:\nsudo apt install gdb\n\n# Installing vcpkg dependencies (packages dependecies)\ncd vcpkg \u0026\u0026 vcpkg install #-x-install-root=..\n```\n\nSee [here](https://learn.microsoft.com/pt-br/vcpkg/users/versioning#version-schemes) for more infos\nabout the `vcpkg` (package manager). [Here](https://vcpkg.io/en/packages.html) to search for pkgs.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppcamp%2Fcpp_hasher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fppcamp%2Fcpp_hasher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppcamp%2Fcpp_hasher/lists"}