{"id":13616163,"url":"https://github.com/openacid/slim","last_synced_at":"2025-10-03T14:05:59.349Z","repository":{"id":34197719,"uuid":"168801017","full_name":"openacid/slim","owner":"openacid","description":"Surprisingly space efficient trie in Golang(11 bits/key; 100 ns/get).","archived":false,"fork":false,"pushed_at":"2023-11-24T10:01:22.000Z","size":18957,"stargazers_count":1926,"open_issues_count":7,"forks_count":102,"subscribers_count":38,"default_branch":"main","last_synced_at":"2025-05-29T10:46:23.770Z","etag":null,"topics":["compacted","compress","datastructure","go","golang","memory","tree","trie"],"latest_commit_sha":null,"homepage":"https://openacid.github.io/","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/openacid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","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":"2019-02-02T06:12:39.000Z","updated_at":"2025-05-12T04:34:33.000Z","dependencies_parsed_at":"2024-06-18T13:53:45.216Z","dependency_job_id":"427b653e-e9c2-4bd6-832b-31513e83cc94","html_url":"https://github.com/openacid/slim","commit_stats":{"total_commits":490,"total_committers":10,"mean_commits":49.0,"dds":"0.14081632653061227","last_synced_commit":"e045937bf4e53e06893314bb71a2c710e3132be4"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/openacid/slim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openacid%2Fslim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openacid%2Fslim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openacid%2Fslim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openacid%2Fslim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openacid","download_url":"https://codeload.github.com/openacid/slim/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openacid%2Fslim/sbom","scorecard":{"id":708707,"data":{"date":"2025-08-11","repo":{"name":"github.com/openacid/slim","commit":"e045937bf4e53e06893314bb71a2c710e3132be4"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"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":"Code-Review","score":0,"reason":"Found 0/21 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":"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":"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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/golangci-lint.yml:1","Warn: no topLevel permission defined: .github/workflows/local-lint.yml:1","Warn: no topLevel permission defined: .github/workflows/test-short.yml:1","Warn: no topLevel permission defined: .github/workflows/test.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":"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":"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":"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":"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":"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/golangci-lint.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/golangci-lint.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/golangci-lint.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/local-lint.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/local-lint.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/local-lint.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/local-lint.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/local-lint.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/local-lint.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-short.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/test-short.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-short.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/test-short.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-short.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/test-short.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/test.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/test.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/test.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/openacid/slim/test.yml/main?enable=pin","Info:   0 out of  10 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 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":"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":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":3,"reason":"7 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-cpwx-vrp4-4pq7","Warn: Project is vulnerable to: PYSEC-2021-66 / GHSA-g3rq-g295-4j3m","Warn: Project is vulnerable to: GHSA-h5c8-rqwp-cp95","Warn: Project is vulnerable to: GHSA-h75v-3vvj-5mfj","Warn: Project is vulnerable to: GHSA-q2x7-8rv6-6q7h","Warn: Project is vulnerable to: PYSEC-2020-96 / GHSA-6757-jp84-gxfx","Warn: Project is vulnerable to: PYSEC-2021-142 / GHSA-8q59-q68h-6hv4"],"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-22T07:30:52.132Z","repository_id":34197719,"created_at":"2025-08-22T07:30:52.132Z","updated_at":"2025-08-22T07:30:52.132Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278173367,"owners_count":25942293,"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-03T02:00:06.070Z","response_time":53,"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":["compacted","compress","datastructure","go","golang","memory","tree","trie"],"created_at":"2024-08-01T20:01:24.429Z","updated_at":"2025-10-03T14:05:59.324Z","avatar_url":"https://github.com/openacid.png","language":"Go","funding_links":[],"categories":["Misc","开源类库","Go","Open source library"],"sub_categories":["数据结构","Data Structure"],"readme":"\u003c!--\nbased on the a great readme template\nhttps://gist.github.com/PurpleBooth/109311bb0361f32d87a2\n--\u003e\n\n# Slim - surprisingly space efficient data types in Golang\n\n[![Travis](https://travis-ci.com/openacid/slim.svg?branch=main)](https://travis-ci.com/openacid/slim)\n![test](https://github.com/openacid/slim/workflows/test/badge.svg)\n\n[![Report card](https://goreportcard.com/badge/github.com/openacid/slim)](https://goreportcard.com/report/github.com/openacid/slim)\n[![Coverage Status](https://coveralls.io/repos/github/openacid/slim/badge.svg?branch=main\u0026service=github)](https://coveralls.io/github/openacid/slim?branch=main\u0026service=github)\n\n[![GoDoc](https://godoc.org/github.com/openacid/slim?status.svg)](http://godoc.org/github.com/openacid/slim)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/openacid/slim)](https://pkg.go.dev/github.com/openacid/slim)\n[![Sourcegraph](https://sourcegraph.com/github.com/openacid/slim/-/badge.svg)](https://sourcegraph.com/github.com/openacid/slim?badge)\n\nSlim is collection of surprisingly space efficient data types, with\ncorresponding serialization APIs to persisting them on-disk or for transport.\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Why slim](#why-slim)\n- [Performance and memory overhead](#performance-and-memory-overhead)\n- [Synopsis](#synopsis)\n  - [1. Index on-disk key-values](#1-index-on-disk-key-values)\n  - [2. Sparse index](#2-sparse-index)\n  - [3. Range scan](#3-range-scan)\n- [Filter mode and KV mode.](#filter-mode-and-kv-mode)\n- [Try it](#try-it)\n  - [Versions](#versions)\n- [Who are using slim](#who-are-using-slim)\n- [Feedback and contributions](#feedback-and-contributions)\n- [Authors](#authors)\n- [License](#license)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Why slim\n\nAs data on internet keeps increasing exponentially,\nthe capacity gap between memory and disk becomes greater.\n\nMost of the time, a data itself does not need to be loaded into expensive main memory.\nOnly the much more important information, WHERE-A-DATA-IS, deserve a seat in\nmain memory.\n\n\nThis is what `slim` does, keeps as little information as possible in main\nmemory, as a minimized index of huge amount external data.\n\n-   `SlimIndex`: is a common index structure, building on top of `SlimTrie`.\n\n    [![GoDoc](https://godoc.org/github.com/openacid/slim/index?status.svg)](http://godoc.org/github.com/openacid/slim/index)\n\n-   `SlimTrie` is the underlying index data structure, evolved from [trie][].\n\n    [![GoDoc](https://godoc.org/github.com/openacid/slim/trie?status.svg)](http://godoc.org/github.com/openacid/slim/trie)\n\n    **Features**:\n\n    -   **Minimized**:\n        **11 bits per key**(far less than an 64-bits pointer!!).\n\n    -   **Stable**:\n        memory consumption is stable in various scenarios.\n        The Worst case converges to average consumption tightly.\n        See benchmark.\n\n    -   **Loooong keys**:\n        You can have **VERY** long keys(`16K bytes`), without any waste of memory(and money).\n        Do not waste your life writing another prefix compression`:)`.\n        ([aws-s3][] limits key length to 1024 bytes).\n        Memory consumption only relates to key count, **not to key length**.\n\n    -   **Ordered**:\n        like [btree][], keys are stored.\n        Range-scan will be ready in `0.6.0`.\n\n    -   **Fast**:\n        **~150 ns** per `Get()`.\n        Time complexity for a get is `O(log(n) + k); n: key count; k: key length`.\n\n    -   **Ready for transport**:\n        a single `proto.Marshal()` is all it requires to serialize, transport or persisting on disk etc.\n\n\n## Performance and memory overhead\n\n- **3.3 times faster** than the [btree][].\n- **2.3 times faster** than binary search.\n\n![](trie/report/bench_msab_present_zipf.jpg)\n\n- **Memory overhead is about 11 bit per key**.\n\n![](trie/report/mem_usage.jpg)\n\nThe data struct in this benchmark is a slice of key-value pairs with a `SlimTrie` serving as the index.\nThe slim itself is built in the **filter** mode, to maximize memory reduction and performance.\nThe whole struct `slimKV` is a fully functional kv-store, just like a static `btree`.\n\n```go\ntype slimKV struct {\n    slim *trie.SlimTrie\n    Elts []*KVElt\n}\ntype KVElt struct {\n    Key string\n    Val int32\n}\n```\n\nYou can find the benchmark code in [benchmark](trie/benchmark/benchmark.go);\n\nRead more about [Performance](docs/performance.md)\n\n\n\n## Synopsis\n\n### 1. Index on-disk key-values\n\nOne of the typical usages of slim is to index serialized data on disk(e.g., key value records in a SSTable).\nBy keeping a slim in memory, one can quickly find the on-disk offset of the record by a key.\n\n\u003cdetails\u003e\n    \u003csummary\u003eShow me the code ......\u003c/summary\u003e\n\n```go\npackage index_test\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/openacid/slim/index\"\n)\n\ntype Data string\n\nfunc (d Data) Read(offset int64, key string) (string, bool) {\n\tkv := strings.Split(string(d)[offset:], \",\")[0:2]\n\tif kv[0] == key {\n\t\treturn kv[1], true\n\t}\n\treturn \"\", false\n}\n\nfunc Example() {\n\n\t// Accelerate external data accessing (in memory or on disk) by indexing\n\t// them with a SlimTrie:\n\n\t// `data` is a sample of some unindexed data. In our example it is a comma\n\t// separated key value series.\n\t//\n\t// In order to let SlimTrie be able to read data, `data` should have\n\t// a `Read` method:\n\t//     Read(offset int64, key string) (string, bool)\n\tdata := Data(\"Aaron,1,Agatha,1,Al,2,Albert,3,Alexander,5,Alison,8\")\n\n\t// keyOffsets is a prebuilt index that stores key and its offset in data accordingly.\n\tkeyOffsets := []index.OffsetIndexItem{\n\t\t{Key: \"Aaron\", Offset: 0},\n\t\t{Key: \"Agatha\", Offset: 8},\n\t\t{Key: \"Al\", Offset: 17},\n\t\t{Key: \"Albert\", Offset: 22},\n\t\t{Key: \"Alexander\", Offset: 31},\n\t\t{Key: \"Alison\", Offset: 43},\n\t}\n\n\t// `SlimIndex` is simply a container of SlimTrie and its data.\n\tst, err := index.NewSlimIndex(keyOffsets, data)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\n\t// Lookup\n\tv, found := st.Get(\"Alison\")\n\tfmt.Printf(\"key: %q\\n  found: %t\\n  value: %q\\n\", \"Alison\", found, v)\n\n\tv, found = st.Get(\"foo\")\n\tfmt.Printf(\"key: %q\\n  found: %t\\n  value: %q\\n\", \"foo\", found, v)\n\n\t// Output:\n\t// key: \"Alison\"\n\t//   found: true\n\t//   value: \"8\"\n\t// key: \"foo\"\n\t//   found: false\n\t//   value: \"\"\n}\n```\n\n\u003c/details\u003e\n\n### 2. Sparse index\n\nCreate an index item for every 4(or more as you wish) keys.\n\nLet several adjacent keys share one index item reduces a lot memory\ncost if there are huge amount keys in external data.\nSuch as to index billions of 4KB objects on a 4TB disk(because one disk IO\ncosts 20ms for either reading 4KB or reading 1MB).\n\n\u003cdetails\u003e\n    \u003csummary\u003eShow me the code ......\u003c/summary\u003e\n\n```go\npackage index_test\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/openacid/slim/index\"\n)\n\ntype RangeData string\n\nfunc (d RangeData) Read(offset int64, key string) (string, bool) {\n\tfor i := 0; i \u003c 4; i++ {\n\t\tif int(offset) \u003e= len(d) {\n\t\t\tbreak\n\t\t}\n\n\t\tkv := strings.Split(string(d)[offset:], \",\")[0:2]\n\t\tif kv[0] == key {\n\t\t\treturn kv[1], true\n\t\t}\n\t\toffset += int64(len(kv[0]) + len(kv[1]) + 2)\n\n\t}\n\treturn \"\", false\n}\n\nfunc Example_indexRanges() {\n\n\t// Index ranges instead of keys:\n\t// In this example at most 4 keys shares one index item.\n\n\tdata := RangeData(\"Aaron,1,Agatha,1,Al,2,Albert,3,Alexander,5,Alison,8\")\n\n\t// keyOffsets is a prebuilt index that stores range start, range end and its offset.\n\tkeyOffsets := []index.OffsetIndexItem{\n\t\t// Aaron  +--\u003e 0\n\t\t// Agatha |\n\t\t// Al     |\n\t\t// Albert |\n\n\t\t// Alexander +--\u003e 31\n\t\t// Alison    |\n\n\t\t{Key: \"Aaron\", Offset: 0},\n\t\t{Key: \"Agatha\", Offset: 0},\n\t\t{Key: \"Al\", Offset: 0},\n\t\t{Key: \"Albert\", Offset: 0},\n\n\t\t{Key: \"Alexander\", Offset: 31},\n\t\t{Key: \"Alison\", Offset: 31},\n\t}\n\n\tst, err := index.NewSlimIndex(keyOffsets, data)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tv, found := st.RangeGet(\"Aaron\")\n\tfmt.Printf(\"key: %q\\n  found: %t\\n  value: %q\\n\", \"Aaron\", found, v)\n\n\tv, found = st.RangeGet(\"Al\")\n\tfmt.Printf(\"key: %q\\n  found: %t\\n  value: %q\\n\", \"Al\", found, v)\n\n\tv, found = st.RangeGet(\"foo\")\n\tfmt.Printf(\"key: %q\\n  found: %t\\n  value: %q\\n\", \"foo\", found, v)\n\n\t// Output:\n\t// key: \"Aaron\"\n\t//   found: true\n\t//   value: \"1\"\n\t// key: \"Al\"\n\t//   found: true\n\t//   value: \"2\"\n\t// key: \"foo\"\n\t//   found: false\n\t//   value: \"\"\n}\n```\n\n\u003c/details\u003e\n\n\n### 3. Range scan\n\nSlim can also be used as a traditional in-memory kv-store:\nBuilding a slim with `Opt{ Complete: Bool(true) }`,\nit won't strip out any information(e.g., it won't eliminate single-branch labels)\nand it will functions the same as a `btree`.\nThis snippet shows how to iterate key values.\n\n\u003cdetails\u003e\n    \u003csummary\u003eShow me the code ......\u003c/summary\u003e\n\n```go\npackage trie\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/openacid/slim/encode\"\n)\n\nfunc ExampleSlimTrie_ScanFrom() {\n\tvar keys = []string{\n\t\t\"\",\n\t\t\"`\",\n\t\t\"a\",\n\t\t\"ab\",\n\t\t\"abc\",\n\t\t\"abca\",\n\t\t\"abcd\",\n\t\t\"abcd1\",\n\t\t\"abce\",\n\t\t\"be\",\n\t\t\"c\",\n\t\t\"cde0\",\n\t\t\"d\",\n\t}\n\tvalues := makeI32s(len(keys))\n\n\tcodec := encode.I32{}\n\tst, _ := NewSlimTrie(codec, keys, values, Opt{\n\t\tComplete: Bool(true),\n\t})\n\n\t// untilD stops when encountering \"d\".\n\tuntilD := func(k, v []byte) bool {\n\t\tif string(k) == \"d\" {\n\t\t\treturn false\n\t\t}\n\n\t\t_, i32 := codec.Decode(v)\n\t\tfmt.Println(string(k), i32)\n\t\treturn true\n\t}\n\n\tfmt.Println(\"scan (ab, +∞):\")\n\tst.ScanFrom(\"ab\", false, true, untilD)\n\n\tfmt.Println()\n\tfmt.Println(\"scan [be, +∞):\")\n\tst.ScanFrom(\"be\", true, true, untilD)\n\n\tfmt.Println()\n\tfmt.Println(\"scan (ab, be):\")\n\tst.ScanFromTo(\n\t\t\"ab\", false,\n\t\t\"be\", false,\n\t\ttrue, untilD)\n\n\t// Output:\n\t//\n\t// scan (ab, +∞):\n\t// abc 4\n\t// abca 5\n\t// abcd 6\n\t// abcd1 7\n\t// abce 8\n\t// be 9\n\t// c 10\n\t// cde0 11\n\t//\n\t// scan [be, +∞):\n\t// be 9\n\t// c 10\n\t// cde0 11\n\t//\n\t// scan (ab, be):\n\t// abc 4\n\t// abca 5\n\t// abcd 6\n\t// abcd1 7\n\t// abce 8\n}\n```\n\n\u003c/details\u003e\n\n\n## Filter mode and KV mode.\n\nSlim can be built into either a filter(like `bloom filter` but with key order preserved.) or a real kv-store(like `btree`)\nThere is an `option` in `NewSlimTrie(..., option)` to control the building behavior.\nRef: [Opt](https://pkg.go.dev/github.com/openacid/slim@v0.5.11/trie#Opt)\n\n- To use slim as a kv-store, set the option to `Complete` then there won't be false positives.\n\n- To use it as a filter, set `InnerPrefix`, `LeafPrefix` to false(`Complete` implies `InnerPrefix==true` and `LeafPrefix==true`).\n  Then slim won't store any single branch label in the trie it builds.\n\n  With  `InnerPrefix==true`, it does not reduce a single label branch that leads to an inner node.\n\n  With  `LeafPrefix==true`, it does not reduce a single label branch that leads to a leaf node.\n\n  E.g.:\n\n  ```\n  // Complete\n  InnerPrefix: true\n  LeafPrefix: true\n  ^ -a-\u003e 1 -b-\u003e $\n   `-c-\u003e 2 -x-\u003e 3 -y-\u003e $\n                 `-z-\u003e $\n  \n  InnerPrefix: true\n  LeafPrefix: false\n  ^ -a-\u003e $\n   `-c-\u003e 2 -x-\u003e 3 -y-\u003e $\n                 `-z-\u003e $\n  \n  InnerPrefix: false\n  LeafPrefix: true\n  ^ -a-\u003e 1 -b-\u003e $\n   `-c-\u003e 3 -y-\u003e $\n          `-z-\u003e $\n  \n  InnerPrefix: false\n  LeafPrefix: false\n  ^ -a-\u003e $\n   `-c-\u003e 3 -y-\u003e $\n          `-z-\u003e $\n  ```\n\nThe memory consumption in filter mode and kv mode differs significantly.\nThe following chart shows memory consumption by 1 million var-length string, 10 to 20 byte in different mode:\n\n| -                | size  | gzip-size |\n| :--              | --:   | --:       |\n| sample data size | 15.0M | 14.0M     |\n| Complete:true    | 14.0M | 10.0M     |\n| InnerPrefix:ture |  1.3M |  0.9M     |\n| all false        |  1.3M |  0.8M     |\n\n\n\u003c!-- ## FAQ --\u003e\n\n## Try it\n\n**Install**\n\n```sh\ngo get github.com/openacid/slim/trie\n```\n\nChange-log: [Change-log](docs/change-log.yaml)\n\n### Versions\n\nA newer version `y` being compatible with an older version `x` means `y` can\nload data serialized by `x`. But `x` should never try to load data serialized by\na newer version `y`.\n\n- `v0.5.*` is compatible with `0.2.*`, `0.3.*`, `0.4.*`, `0.5.*`.\n- `v0.4.*` is compatible with `0.2.*`, `0.3.*`, `0.4.*`.\n- `v0.3.*` is compatible with `0.2.*`, `0.3.*`.\n- `v0.2.*` is compatible with `0.2.*`.\n\n\n\u003c!-- TODO add FAQ --\u003e\n\u003c!-- TODO add serialization explanation, on-disk data structure etc. --\u003e\n\n## Who are using slim\n\n\u003cspan\u003e \u003cspan\u003e ![][baishancloud-favicon] \u003c/span\u003e \u003cspan\u003e [baishancloud][] \u003c/span\u003e \u003c/span\u003e\n\n\u003c!-- ## Slim internal --\u003e\n\n\u003c!-- ### Built With --\u003e\n\n\u003c!-- - [protobuf][] - Define on-disk data-structure and serialization engine. --\u003e\n\u003c!-- - [dep][] - Dependency Management. --\u003e\n\u003c!-- - [semver][] - For versioning data-structure. --\u003e\n\n\u003c!-- ### Directory Layout --\u003e\n\n\u003c!-- We follow the: [golang-standards-project-layout][]. --\u003e\n\n\u003c!-- [\u003e TODO read the doc and add more standards \u003c] --\u003e\n\n\u003c!-- -   `vendor/`: dependency packages. --\u003e\n\u003c!-- -   `prototype/`: on-disk data-structure. --\u003e\n\u003c!-- -   `docs/`: documents about design, trade-off, etc --\u003e\n\u003c!-- -   `tools/`: documents about design, trade-off, etc --\u003e\n\u003c!-- -   `expamples/`: documents about design, trade-off, etc --\u003e\n\n\u003c!-- Other directories are sub-package. --\u003e\n\n\n\u003c!-- ### Versioning --\u003e\n\n\u003c!-- We use [SemVer](http://semver.org/) for versioning. --\u003e\n\n\u003c!-- For the versions available, see the [tags on this repository](https://github.com/your/project/tags).  --\u003e\n\n\u003c!-- ### Data structure explained --\u003e\n\u003c!-- [\u003e TODO  \u003c] --\u003e\n\n\u003c!-- ## Limitation --\u003e\n\u003c!-- [\u003e TODO  \u003c] --\u003e\n\n\n\u003c!-- -   [ ] bitrie: 1 byte-per-key implementation. --\u003e\n\u003c!-- -   [ ] balanced bitrie: which gives better worst-case performance. --\u003e\n\u003c!-- -   [ ] generalised API as a drop-in replacement for map etc. --\u003e\n\n\n## Feedback and contributions\n\n**Feedback and Contributions are greatly appreciated**.\n\nAt this stage, the maintainers are most interested in feedback centered on:\n\n-   Do you have a real life scenario that `slim` supports well, or doesn't support at all?\n-   Do any of the APIs fulfill your needs well?\n\nLet us know by filing an issue, describing what you did or wanted to do, what\nyou expected to happen, and what actually happened:\n\n-   [bug-report][]\n-   [improve-document][]\n-   [feature-request][]\n\nOr other type of [issue][new-issue].\n\n\u003c!-- ## Contributing --\u003e\n\u003c!-- The maintainers actively manage the issues list, and try to highlight issues --\u003e\n\u003c!-- suitable for newcomers. --\u003e\n\n\u003c!-- [\u003e TODO dep CONTRIBUTING \u003c] --\u003e\n\u003c!-- The project follows the typical GitHub pull request model. See CONTRIBUTING.md for more details. --\u003e\n\n\u003c!-- Before starting any work, please either comment on an existing issue, --\u003e\n\u003c!-- or file a new one. --\u003e\n\n\u003c!-- [\u003e TODO  \u003c] --\u003e\n\u003c!-- Please read [CONTRIBUTING.md][] --\u003e\n\u003c!-- for details on our code of conduct, and the process for submitting pull requests to us. --\u003e\n\u003c!-- https://gist.github.com/PurpleBooth/b24679402957c63ec426 --\u003e\n\n\n\u003c!-- ### Code style --\u003e\n\n\u003c!-- ### Tool chain --\u003e\n\n\u003c!-- ### Customized install --\u003e\n\n\u003c!-- Alternatively, if you have a customized go develop environment, you could also --\u003e\n\u003c!-- clone it: --\u003e\n\n\u003c!-- ```sh --\u003e\n\u003c!-- git clone git@github.com:openacid/slim.git --\u003e\n\u003c!-- ``` --\u003e\n\n\u003c!-- As a final step you'd like have a test to see if everything goes well: --\u003e\n\n\u003c!-- ```sh --\u003e\n\u003c!-- cd path/to/slim/build/pseudo-gopath --\u003e\n\u003c!-- export GOPATH=$(pwd) --\u003e\n\u003c!-- go test github.com/openacid/slim/array --\u003e\n\u003c!-- ``` --\u003e\n\n\u003c!-- Another reason to have a `pseudo-gopath` in it is that some tool have their --\u003e\n\u003c!-- own way conducting source code tree. --\u003e\n\u003c!-- E.g. [git-worktree](https://git-scm.com/docs/git-worktree) --\u003e\n\u003c!-- checkouts source code into another dir other than the GOPATH work space. --\u003e\n\n\u003c!-- ## Update dependency --\u003e\n\n\u003c!-- Dependencies are tracked by [dep](https://github.com/golang/dep). --\u003e\n\u003c!-- All dependencies are kept in `vendor/` dir thus you do not need to do anything --\u003e\n\u003c!-- to run it. --\u003e\n\n\u003c!-- You need to update dependency only when you bring in new feature with other dependency. --\u003e\n\n\u003c!-- -   Install `dep` --\u003e\n\n\u003c!--     ``` --\u003e\n\u003c!--     curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh --\u003e\n\u003c!--     ``` --\u003e\n\n\u003c!-- -   Download dependency --\u003e\n\n\u003c!--     ``` --\u003e\n\u003c!--     dep ensure --\u003e\n\u003c!--     ``` --\u003e\n\n\u003c!--     \u003e dep uses Gopkg.toml Gopkg.lock to track dependency info. --\u003e\n\u003c!--     \u003e  --\u003e\n\u003c!--     \u003e Gopkg.toml Gopkg.lock is created with `dep init`. --\u003e\n\u003c!--     \u003e --\u003e\n\u003c!--     \u003e dep creates a `vendor` dir to have all dependency package there. --\u003e\n\n\u003c!-- See more: [dep-install][] --\u003e\n\n\n## Authors\n\n\u003c!-- ordered by unicode of author's name --\u003e\n\u003c!-- leave 3 to 5 major jobs you have done in this project --\u003e\n\n- ![][刘保海-img-sml] **[刘保海][]** *marshaling*\n- ![][吴义谱-img-sml] **[吴义谱][]** *array*\n- ![][张炎泼-img-sml] **[张炎泼][]** *slimtrie design*\n- ![][李文博-img-sml] **[李文博][]** *trie-compressing, trie-search*\n- ![][李树龙-img-sml] **[李树龙][]** *marshaling*\n\n\nSee also the list of [contributors][] who participated in this project.\n\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n\u003c!-- ## Acknowledgments --\u003e\n\n\u003c!-- [\u003e TODO  \u003c] --\u003e\n\u003c!-- - Hat tip to anyone whose code was used --\u003e\n\n\u003c!-- - Inspiration --\u003e\n\u003c!--     patricial tree --\u003e\n\u003c!--     fusion tree --\u003e\n\u003c!--     critic trie --\u003e\n\u003c!-- - etc --\u003e\n\n\u003c!-- links --\u003e\n\n\u003c!-- Bio --\u003e\n\n[刘保海]: https://github.com/liubaohai\n[吴义谱]: https://github.com/pengsven\n[张炎泼]: https://github.com/drmingdrmer\n[李文博]: https://github.com/wenbobuaa\n[李树龙]: https://github.com/lishulong\n\n\u003c!-- avatar --\u003e\n\n[刘保海-img-sml]: https://avatars1.githubusercontent.com/u/26271283?s=36\u0026v=4\n[吴义谱-img-sml]: https://avatars3.githubusercontent.com/u/6927668?s=36\u0026v=4\n[张炎泼-img-sml]: https://avatars3.githubusercontent.com/u/44069?s=36\u0026v=4\n[李文博-img-sml]: https://avatars1.githubusercontent.com/u/11748387?s=36\u0026v=4\n[李树龙-img-sml]: https://avatars2.githubusercontent.com/u/13903162?s=36\u0026v=4\n\n[contributors]: https://github.com/openacid/slim/contributors\n\n[dep]: https://github.com/golang/dep\n[protobuf]: https://github.com/protocolbuffers/protobuf\n[semver]: http://semver.org/\n\n[protoc-install]: http://google.github.io/proto-lens/installing-protoc.html\n[dep-install]: https://github.com/golang/dep#installation\n\n[CONTRIBUTING.md]: CONTRIBUTING.md\n\n[baishancloud]: http://www.baishancdnx.com\n[baishancloud-favicon]: http://www.baishancdnx.com/public/favicon.ico\n[golang-standards-project-layout]: https://github.com/golang-standards/project-layout\n\n\u003c!-- issue links --\u003e\n\n[bug-report]:       https://github.com/openacid/slim/issues/new?labels=bug\u0026template=bug_report.md\n[improve-document]: https://github.com/openacid/slim/issues/new?labels=doc\u0026template=doc_improve.md\n[feature-request]:  https://github.com/openacid/slim/issues/new?labels=feature\u0026template=feature_request.md\n\n[new-issue]: https://github.com/openacid/slim/issues/new/choose\n\n\u003c!-- benchmark --\u003e\n\n[benchmark-get-png]: docs/trie/charts/bench_get_2019_06_03.png\n\n\u003c!-- links to other resource --\u003e\n\n\u003c!-- reference --\u003e\n\n[trie]: https://en.wikipedia.org/wiki/Trie\n[btree]: https://github.com/google/btree\n[aws-s3]: https://aws.amazon.com/s3/\n[red-black-tree]: https://en.wikipedia.org/wiki/Red%E2%80%93black_tree","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenacid%2Fslim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenacid%2Fslim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenacid%2Fslim/lists"}