{"id":22796092,"url":"https://github.com/krasun/bptree","last_synced_at":"2025-10-06T20:27:42.854Z","repository":{"id":57593877,"uuid":"372212025","full_name":"krasun/bptree","owner":"krasun","description":"In-memory B+ tree implementation for Go.","archived":false,"fork":false,"pushed_at":"2022-01-09T12:28:19.000Z","size":53,"stargazers_count":8,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-13T07:43:54.097Z","etag":null,"topics":["bplus-tree","bplustree","btree","btree-implementation","btrees"],"latest_commit_sha":null,"homepage":"","language":"Go","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/krasun.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}},"created_at":"2021-05-30T12:45:04.000Z","updated_at":"2024-11-11T02:55:58.000Z","dependencies_parsed_at":"2022-09-12T22:01:34.644Z","dependency_job_id":null,"html_url":"https://github.com/krasun/bptree","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/krasun/bptree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krasun%2Fbptree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krasun%2Fbptree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krasun%2Fbptree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krasun%2Fbptree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krasun","download_url":"https://codeload.github.com/krasun/bptree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krasun%2Fbptree/sbom","scorecard":{"id":569597,"data":{"date":"2025-08-11","repo":{"name":"github.com/krasun/bptree","commit":"d1a69a297982d25ca9dc09ec6a91fbe2f2f7e54c"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/build.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/krasun/bptree/build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/krasun/bptree/build.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/krasun/bptree/build.yml/main?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Code-Review","score":0,"reason":"Found 0/15 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T15:56:55.960Z","repository_id":57593877,"created_at":"2025-08-20T15:56:55.960Z","updated_at":"2025-08-20T15:56:55.960Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278673259,"owners_count":26026070,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"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":["bplus-tree","bplustree","btree","btree-implementation","btrees"],"created_at":"2024-12-12T05:10:17.076Z","updated_at":"2025-10-06T20:27:42.838Z","avatar_url":"https://github.com/krasun.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **bp**tree\n\n[![Build](https://github.com/krasun/bptree/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/krasun/bptree/actions/workflows/build.yml)\n[![codecov](https://codecov.io/gh/krasun/bptree/branch/main/graph/badge.svg?token=8NU6LR4FQD)](https://codecov.io/gh/krasun/bptree)\n[![Go Report Card](https://goreportcard.com/badge/github.com/krasun/bptree)](https://goreportcard.com/report/github.com/krasun/bptree)\n[![GoDoc](https://godoc.org/https://godoc.org/github.com/krasun/bptree?status.svg)](https://godoc.org/github.com/krasun/bptree)\n\nAn in-memory [B+ tree](https://en.wikipedia.org/wiki/B%2B_tree) implementation for Go with byte-slice keys and values. \n\n## Installation \n\nTo install, run:\n\n```\ngo get github.com/krasun/bptree\n```\n\n## Quickstart\n\nFeel free to play: \n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/krasun/bptree\"\n)\n\nfunc main() {\n\ttree, err := bptree.New()\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"error: %v\\n\", err)\n        os.Exit(1)\n\t}\n\n\ttree.Put([]byte(\"apple\"), []byte(\"sweet\"))\n\ttree.Put([]byte(\"banana\"), []byte(\"honey\"))\n\ttree.Put([]byte(\"cinnamon\"), []byte(\"savoury\"))\n\n\tbanana, ok := tree.Get([]byte(\"banana\"))\n\tif ok {\n\t\tfmt.Printf(\"banana = %s\\n\", string(banana))\n\t} else {\n\t\tfmt.Println(\"value for banana not found\")\n\t}\n\n\ttree.ForEach(func(key, value []byte) {\n\t\tfmt.Printf(\"key = %s, value = %s\\n\", string(key), string(value))\n\t})\n\n\t// Output: \n\t// banana = honey\n\t// key = apple, value = sweet\n\t// key = banana, value = honey\n\t// key = cinnamon, value = savoury\n}\n```\n\nYou can use an iterator: \n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/krasun/bptree\"\n)\n\nfunc main() {\n\ttree, err := bptree.New(bptree.Order(3))\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"error: %v\\n\", err)\n        os.Exit(1)\n\t}\n\n\ttree.Put([]byte(\"apple\"), []byte(\"sweet\"))\n\ttree.Put([]byte(\"banana\"), []byte(\"honey\"))\n\ttree.Put([]byte(\"cinnamon\"), []byte(\"savoury\"))\n\n\tbanana, ok := tree.Get([]byte(\"banana\"))\n\tif ok {\n\t\tfmt.Printf(\"banana = %s\\n\", string(banana))\n\t} else {\n\t\tfmt.Println(\"value for banana not found\")\n\t}\n\n\tfor it := tree.Iterator(); it.HasNext(); {\n\t\tkey, value := it.Next()\n\t\tfmt.Printf(\"key = %s, value = %s\\n\", string(key), string(value))\n\t}\n\n\t// Output: \n\t// banana = honey\n\t// key = apple, value = sweet\n\t// key = banana, value = honey\n\t// key = cinnamon, value = savoury\n}\n```\n\nAn iterator is stateful. You can have multiple iterators without any impact on each other, but make sure to synchronize access to them and the tree in a concurrent environment.\n\nCaution! `Next` panics if there is no next element. Make sure to test for the next element with `HasNext` before.\n\n## Use cases \n\n1. When you want to use []byte as a key in the map. \n2. When you want to iterate over keys in map in sorted order.\n\n## Limitations \n\n**Caution!** To guarantee that the B+ tree properties are not violated, keys are copied. \n\nYou should clearly understand what []byte slice is and why it is dangerous to use it as a key. Go language authors do prohibit using byte slice ([]byte) as a map key for a reason. The point is that you can change the values of the key and thus violate the invariants of map: \n\n```go\n// if it worked \nb := []byte{1}\nm := make(map[[]byte]int)\nm[b] = 1\n\nb[0] = 2 // it would violate the invariants \nm[[]byte{1}] // what do you expect to receive?\n```\n\nSo to make sure that this situation does not occur in the tree, the key is copied byte by byte.\n\n## Benchmark\n\nRegular Go map is as twice faster for put and get than B+ tree. But if you \nneed to iterate over keys in sorted order, the picture is slightly different: \n\n```\n$ go test -benchmem -bench .                                                                                            127 ↵\ngoos: darwin\ngoarch: amd64\npkg: github.com/krasun/bptree\nBenchmarkTreePut-8                     \t     187\t   6423171 ns/op\t 2825134 B/op\t   99844 allocs/op\nBenchmarkMapPut-8                      \t     525\t   2736062 ns/op\t 1732158 B/op\t   20150 allocs/op\nBenchmarkTreePutRandomized-8           \t     177\t   6745088 ns/op\t 1622519 B/op\t   69431 allocs/op\nBenchmarkMapPutRandomized-8            \t     612\t   1944303 ns/op\t  981396 B/op\t   20111 allocs/op\nBenchmarkMapGet-8                      \t    1484\t    704045 ns/op\t   38880 B/op\t    9900 allocs/op\nBenchmarkTreeGet-8                     \t     505\t   2184212 ns/op\t   38880 B/op\t    9900 allocs/op\nBenchmarkTreePutAndForEach-8           \t     181\t   6958273 ns/op\t 2825133 B/op\t   99844 allocs/op\nBenchmarkMapPutAndIterateAfterSort-8   \t     205\t   5473439 ns/op\t 2558078 B/op\t   20172 allocs/op\nPASS\nok  \tgithub.com/krasun/bptree\t15.460s\n```\n\n## Tests\n\nRun tests with: \n\n```\n$ go test -cover .\nok  \tgithub.com/krasun/bptree\t0.468s\tcoverage: 100.0% of statements\n```\n\n## License \n\n**bp**tree is released under [the MIT license](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrasun%2Fbptree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrasun%2Fbptree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrasun%2Fbptree/lists"}