{"id":13645837,"url":"https://github.com/Bazist/HArray","last_synced_at":"2025-04-21T17:31:32.134Z","repository":{"id":48688190,"uuid":"71177076","full_name":"Bazist/HArray","owner":"Bazist","description":"Fastest Trie structure (Linux \u0026 Windows)","archived":false,"fork":false,"pushed_at":"2022-12-26T18:35:11.000Z","size":16681,"stargazers_count":92,"open_issues_count":2,"forks_count":10,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-09T19:39:41.061Z","etag":null,"topics":["benchmark","cplusplus","data-structures","fast","trie"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bazist.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":"2016-10-17T20:12:33.000Z","updated_at":"2024-10-29T10:30:03.000Z","dependencies_parsed_at":"2023-01-31T00:45:17.493Z","dependency_job_id":null,"html_url":"https://github.com/Bazist/HArray","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/Bazist%2FHArray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bazist%2FHArray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bazist%2FHArray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bazist%2FHArray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bazist","download_url":"https://codeload.github.com/Bazist/HArray/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250100443,"owners_count":21374939,"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":["benchmark","cplusplus","data-structures","fast","trie"],"created_at":"2024-08-02T01:02:43.064Z","updated_at":"2025-04-21T17:31:31.108Z","avatar_url":"https://github.com/Bazist.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# HArray\n\n[![Build status](https://img.shields.io/github/actions/workflow/status/Bazist/HArray/build.yml)](https://img.shields.io/github/actions/workflow/status/Bazist/HArray/build.yml)\n\n## Probably, this is most optimized Trie structure in the World ! Thats all what you need know about this project :)\n\n**HArrayInt** - Key\\Value In Memory structure for 32bit keys\n\n**HArray** - Key\\Value In Memory structure for keys with variety size\n\n**HArrayChar** - Wrapper for HArray with interfaces: char* key, uint32 keyLen, char* value, uint32 valueLen\n\n**HArrayUniqueIntValueList** - Wrapper for HArray with inteterfaces: uint32* key, uint32 keyLen, List\\\u003cuint32\\\u003e  listOfUniqueValues\n\n------------------\n\n## [Start overview from Benchmarks](https://github.com/Bazist/HArray/blob/master/Benchmarks.md)\n\n------------------\n### Overview\n\n- **High optimized** Trie structure implemented in more than **8K lines**\n- Tested on **1 Billion keys** succesfully\n- **Keys with variable length** inside one instance of the container\n- **Without any Stop World** events such as Rebuild/Rehashing on Insert key.\n- **Without any Hash Functions**, the container has adpative algorithm for different nature of keys\n- **Scan by Prefix/Scan by Range** functionality as bonus\n- **All Keys are sorted**. Ability to set your **Custom Order** of Keys \n- **Predictable** behaviour even in worst case: smoothly consuming memory, almost constantly latency on insert/lookup\n- **Prefix Compression** helps reduce memory when keys have the same prefix: urls, file paths, words etc.\n- **Serialize/Deserialize** from/to file at a speed close to the max speed of the hard drive\n- **Fair Delete** operation with smoothly dismantling each Key. \n  Dead fibres are used for insert new keys, so structure perfect works in massive insert/delete scenarios.\n\n------------------\n\n## Build Library and Benchmarks\n\n### Prerquisites\n\nThe following need to be installed and configured on development box:\n\n- C++ development tools.\n- [CMake](https://cmake.org/).\n\n### Build on Linux and Mac\n\n```bash\nmkdir build\ncmake -Bbuild\ncd build \u0026\u0026 make\n```\n\nTo build release version of the library and benchmarks run instead:\n\n```bash\ncmake -Bbuild -DCMAKE_BUILD_TYPE=Release\n```\n\nThe library (`libharray.a`) and benchmark application (`HArrayBenchmark`) will be created in `build` folder.\n\n### Build on Windows\n\n```cmd\nmd build\ncmake -Bbuild\nmsbuild build\\HArray.sln\n```\n\nTo build release version run:\n\n```cmd\nmsbuild build\\HArray.sln /property:Configuration=Release\n```\n\nThe benchmark application `HArrayBenchmark.exe` together with static library `libharray.lib` will be in `build\\Debug` or `build\\Release` folder.\n\n## Why we love Trie ? Because it has much more functionality and stability than Hashtables and much more faster than Binary Trees. Let's compare properties:\n\n![alt tag](https://raw.githubusercontent.com/Bazist/HArray/master/Images/functionality2.png)\n\n------------------\n\n## Trie ? I heard about Trees and Hastables but don't know anything about Trie\n# [Explain me as for Beginners](https://github.com/Bazist/HArray/blob/master/Trie_for_beginners.md)\n\n### Examples\n\nInitialize container\n\n```c++\n#include \"HArray.h\"\n\nHArray ha;\nha.init(); //ha.init(24) set your custom capacity for big datasets\n```\nInsert a key\n\n```c++\nuint32 key[] = { 10, 20, 30, 40 };\nuint32 keyLen = sizeof(key) / 4; //in key segments\nuint32 value = 1;\n\nha.insert(key, keyLen, value);\n```\n\nGet value by key. Will return 0 if key is not found\n\n```c++\nuint32 value;\nif(ha.getValueByKey(key, keyLen, value))\n{\n   printf(\"%d\", value)\n}\nelse\n{\n   //key is not found\n}\n```\n\nGet all keys by range from min key to max key. \n\n```c++\nHArrayPair pairs[5];\nuint32 pairsSize = 5;\n\nuint32 minKey[] = { 10, 10 };\nuint32 minKeyLen = sizeof(minKey) / 4; //in key segments\n\nuint32 maxKey[] = { 20, 20 };\nuint32 maxKeyLen = sizeof(maxKey) / 4; //in key segments\n\nuint32 count = ha.getKeysAndValuesByRange(pairs, pairsSize, minKey, minKeyLen, maxKey, maxKeyLen);\nfor (uint32 i = 0; i \u003c count; i++)\n{\n   uint32* key = pairs[i].Key;\n   uint32 keyLen = pairs[i].KeyLen;\n\n   uint32 value = pairs[i].Value;\n   \n   //here your code\n}\n```\n\nScan all keys through visitor\n\n```c++\nbool visitor(uint32* key, uint32 keyLen, uint32 value, uchar8 valueType, void* pData)\n{\n   //handle founded key here\n   // ...\n\n   //return true to continue scaning or false otherwise\n   return true;\n}\n\n//Start scanning\n\nvoid* pData = 0; //useful data in context\n\nha.scanKeysAndValues(\u0026visitor, pData);\n```\n\nSerialize/Deserialize containter from/to file\n\n```c++\nha.saveToFile(\"c:\\\\dump\");\n\nha.loadFromFile(\"c:\\\\dump\");\n```\n\nCheck if container has part of key\n\n```c++\nuint32 key[] = { 10, 20, 30 };\nuint32 keyLen = sizeof(key) / 4; //in key segments\n\nif(ha.hasPartKey(key, keyLen))\n{\n   //code here\n}\n```\n\nSet specific comparator to redefine order of keys in the container.\n\n```c++\nfloat key[] = { 10.0, 20.0, 30.0 };\nuint32 keyLen = sizeof(key) / 4; //in key segments\n\nuint32 value = 1;\n\n//Set float comparator for right sorting\n//Another options: setStrComparator, setInt32Comparator, setUInt32Comparator \n//or define your custom comparator through setCustomComparator\nha.setFloatComparator();\n\nha.insert((uint32*)key, keyLen, value);\n\n```\n\nDelete Key and Value from container\n\n```c++\nha.delValueByKey(key, keyLen);\n```\n\n### How to Run\n\n```c++\ngit clone github.com/Bazist/HArray.git\ncd HArray/HArray\nmake\n./HArray\n```\n\n### License\n\nThe code is licensed under the GNU General Public License v3.0, see the [LICENSE file](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBazist%2FHArray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBazist%2FHArray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBazist%2FHArray/lists"}