{"id":19636915,"url":"https://github.com/mikegoatly/bitoffsethashset","last_synced_at":"2026-05-11T13:39:02.967Z","repository":{"id":234685207,"uuid":"772928430","full_name":"mikegoatly/BitOffsetHashSet","owner":"mikegoatly","description":"A collection for small sets of integers, equivalent to a HashSet\u003cint\u003e, but faster and less memory usage.","archived":false,"fork":false,"pushed_at":"2024-04-20T11:21:54.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-09T13:50:01.800Z","etag":null,"topics":["csharp","dotnet","hashset","hashsets"],"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/mikegoatly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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-03-16T09:08:23.000Z","updated_at":"2024-04-20T19:35:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"b2ef8bb5-e6e3-481a-94a6-cb2fdd8dcd45","html_url":"https://github.com/mikegoatly/BitOffsetHashSet","commit_stats":null,"previous_names":["mikegoatly/bitoffsetlists"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mikegoatly/BitOffsetHashSet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikegoatly%2FBitOffsetHashSet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikegoatly%2FBitOffsetHashSet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikegoatly%2FBitOffsetHashSet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikegoatly%2FBitOffsetHashSet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikegoatly","download_url":"https://codeload.github.com/mikegoatly/BitOffsetHashSet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikegoatly%2FBitOffsetHashSet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32897672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-10T13:40:02.631Z","status":"online","status_checked_at":"2026-05-11T02:00:05.975Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["csharp","dotnet","hashset","hashsets"],"created_at":"2024-11-11T12:32:12.233Z","updated_at":"2026-05-11T13:39:02.945Z","avatar_url":"https://github.com/mikegoatly.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BitOffsetHashSet\n\n## What is it?\n\nA specialized hash set for integers. It shines when you know that values are going to be relatively closely grouped together,\ne.g. when you have a small number of integers that you are tracking.\n\n## How does it work?\n\nInstead of storing each integer in a separate bucket, integers are stored as a bit in a bitset. This means that when\nvalues are closely grouped together, the memory usage is much lower than a traditional hash set.\n\nCurrently a bucket is structured like this:\n\n```cs\nint BaseOffset // The base offset for the bucket, aligned to a 256bit boundary\nint MaxValue // The maximum value in the bucket\nulong Data1..Data4 // The bitset data\n```\n\nEach bucket can store 256 bits, which means that it can store 256 integers as long as they are consecutive. \n\nThe hash set can make use of multiple buckets, so if sparse data is encountered, it can still cater for it.\n\n## How do I use it?\n\n```cs\nvar set = new BitOffsetHashSet();\nset.Add(1); // true\nset.Add(2); // true\n\n// Duplicate additions are ignored\nset.Add(1); // false\n\nset.Contains(1); // true\nset.Contains(3); // false\n\nset.Remove(1); // true\nset.Contains(1); // false\nset.Remove(1); // false\n```\n\n## How does it perform?\n\nIn benchmark tests, the BitOffsetHashSet is faster than a traditional HashSet when the number of integers is small and\nclosely grouped together.\n\n### Adding sequential values\n\n| Method | Count | Mean | Error | StdDev | Median | Allocated |\n|-|-|-|-|-|-|-|\n|BitOffsetHashSetBenchmarks|1|333.333 ns|46.5456 ns|134.2948 ns|300.000 ns|400 B|\n|HashSetBenchmarks|1|1,246.316 ns|69.2991 ns|198.8320 ns|1,200.000 ns|504 B|\n|BitOffsetHashSetBenchmarks|10|681.720 ns|48.7412 ns|138.2706 ns|700.000 ns|400 B|\n|HashSetBenchmarks|10|2,011.957 ns|115.9737 ns|327.1060 ns|2,000.000 ns|1000 B|\n|BitOffsetHashSetBenchmarks|100|3,938.542 ns|347.7356 ns|1,003.2966 ns|3,600.000 ns|400 B|\n|HashSetBenchmarks|100|3,753.226 ns|165.9474 ns|470.7652 ns|3,750.000 ns|6336 B|\n|BitOffsetHashSetBenchmarks|1000|40,858.763 ns|2,020.5265 ns|5,861.9137 ns|39,400.000 ns|400 B|\n|HashSetBenchmarks|1000|21,849.462 ns|747.4094 ns|2,120.2760 ns|21,300.000 ns|59000 B|\n|BitOffsetHashSetBenchmarks|10000|407,091.176 ns|7,932.9624 ns|12,810.2555 ns|405,400.000 ns|5296 B|\n|HashSetBenchmarks|10000|118,553.333 ns|1,719.9525 ns|1,608.8446 ns|118,600.000 ns|538960 B|\n\nAs can be seen, the BitOffsetHashSet is at least as fast as HashSet when adding around 100 close values,\nbut memory usage is *always* lower. Performance drops as the number of values increases, but at 10,000 values\nthe memory usage is 2 orders of magnitude lower than HashSet.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikegoatly%2Fbitoffsethashset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikegoatly%2Fbitoffsethashset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikegoatly%2Fbitoffsethashset/lists"}