{"id":18706089,"url":"https://github.com/uxmal/btreepoc","last_synced_at":"2025-11-09T07:30:30.066Z","repository":{"id":99257098,"uuid":"160980578","full_name":"uxmal/BTreePOC","owner":"uxmal","description":"BTree experimentation","archived":false,"fork":false,"pushed_at":"2019-04-08T19:20:19.000Z","size":36,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-28T06:42:48.235Z","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":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uxmal.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":"2018-12-08T21:34:21.000Z","updated_at":"2021-01-30T08:52:00.000Z","dependencies_parsed_at":"2023-07-16T01:19:35.464Z","dependency_job_id":null,"html_url":"https://github.com/uxmal/BTreePOC","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/uxmal%2FBTreePOC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uxmal%2FBTreePOC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uxmal%2FBTreePOC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uxmal%2FBTreePOC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uxmal","download_url":"https://codeload.github.com/uxmal/BTreePOC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239571542,"owners_count":19661164,"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-07T12:12:55.450Z","updated_at":"2025-11-09T07:30:29.988Z","avatar_url":"https://github.com/uxmal.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BTreePOC\nThis is a C# sorted dictionary, using a B+tree implementation.\n\n## Motivation\nThe [Reko decompiler](https://github.com/uxmal/reko) uses `SortedList\u003cK,V\u003e` in many places to maintain collections in sorted order. Especially useful is `SortedList`'s `IndexOfKey` method, which is used to compute lower bounds. Lower bounds cannot be computed cheaply using `SortedDictionary\u003cK,V\u003e`. \n\nHowever, the implementation of `SortedList` is simply an array; it's basically the embodiment of the [insertion sort](https://en.wikipedia.org/wiki/Insertion_sort) algorithm. If `n` items are added to the end of the `SortedList`, the complexity is `O(n)` only if the items are added in sorted order. If they are added in random order, or even worse, in reverse-sorted order, the complexity explodes to `O(n^2)`.\n\n`SortedDictionary` is implemented as a balanced binary tree. That implementation results in `O(n log n)` complexity. However, `SortedDictionary` lacks a good way to find a lower bound to a given key, i.e. to find the largest item in the collection that is smaller than or equal to the given key.\n\nSpurred by this, I wrote the `BTreeDictionary\u003cK,V\u003e` class, which implements `IDictionary\u003cK,V\u003e`, and additionally an `IndexOfKey` method which either returns the index `i` of an item equal to the key, or the index of the location the key would have been in. In the latter case, the index of the lower bound is `i-1`.\n\nBenchmark measurements of `BTreeDictionary` compared to `SortedList` and `SortedDictionary` show the following:\n* The `O(n^2)` behaviour of `SortedList` is confirmed.\n* The `O(n log n)` behaviour of `BTreeDictionary` and `SortedDictionary` are confirmed.\n* `BTreeDictionary` consistently outperforms `SortedDictionary` by a factor of 2. On my development machine, adding an item to an `BTreeDictionary` takes ~30 us, while adding an item to `SortedDictionary` takes ~60 us.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuxmal%2Fbtreepoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuxmal%2Fbtreepoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuxmal%2Fbtreepoc/lists"}