{"id":13763402,"url":"https://github.com/mzaks/compact-dict","last_synced_at":"2026-02-19T07:20:10.190Z","repository":{"id":223104012,"uuid":"759327781","full_name":"mzaks/compact-dict","owner":"mzaks","description":"A fast and compact Dict implementation in Mojo 🔥","archived":false,"fork":false,"pushed_at":"2025-08-03T13:38:46.000Z","size":323,"stargazers_count":36,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-08-03T15:24:34.089Z","etag":null,"topics":["dict","dictionary","hashmap","mojo"],"latest_commit_sha":null,"homepage":"","language":"Mojo","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/mzaks.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":"2024-02-18T09:30:38.000Z","updated_at":"2025-08-03T13:38:50.000Z","dependencies_parsed_at":"2024-06-03T15:24:33.562Z","dependency_job_id":"fbe3ae01-bf91-4d4f-9acd-871a2fb000e7","html_url":"https://github.com/mzaks/compact-dict","commit_stats":null,"previous_names":["mzaks/compact-dict"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mzaks/compact-dict","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzaks%2Fcompact-dict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzaks%2Fcompact-dict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzaks%2Fcompact-dict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzaks%2Fcompact-dict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mzaks","download_url":"https://codeload.github.com/mzaks/compact-dict/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzaks%2Fcompact-dict/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29606203,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T06:47:36.664Z","status":"ssl_error","status_checked_at":"2026-02-19T06:45:47.551Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["dict","dictionary","hashmap","mojo"],"created_at":"2024-08-03T15:00:44.033Z","updated_at":"2026-02-19T07:20:10.179Z","avatar_url":"https://github.com/mzaks.png","language":"Mojo","readme":"`compact-dict` is a fast hashmap based dictionary implemented in Mojo 🔥.\n\nAlthough the dictionary is fast (currently it is about 10x faster than the std `Dict`) its main concern is with reducing memory footprint.\n\nWe introduce two self-sufficient modules:\n- `string_dict` where the key type of the dictionary is a `String`\n- `generic_dict` which allows keys to be of any type conforming with `Keyable` trait\n\nBoth modules expose a `Dict` struct which has the following compile time parametrization options:\n- Value type can be any type conforming with `CollectionElement` trait\n- We use a fast hash function as default, but you can provide your own hash function\n- By setting the `KeyCountType` to a lower unsigned DType e.g. (`DType.uint8` or `DType.uint16`) we can reduce the memory footprint. The type needs to be able to represent number of keys\n- By setting the `KeyOffsetType` to a lower unsigned DType we can reduce the memory footprint even further. The type needs to be able to represent the sum of all key bytes\n- Set `destructive` to `False` if you don't intend to delete keys from the dict. This way we do not waste space for deleted flags\n- Set `caching_hashes` to `False` in order to reduce memory footprint by not caching the hash values. Keep in mind that this change slows down the rehashing process\n\nThe `Dict` can be instantiated with a `capacity` value. Default is set to 16, min capacity is 8. If you know the number of elements ahead of time set it, this will avoid rehashing and might improve memory footprint.\n\n### Sample code for generic dict:\n```\nfrom generic_dict import Dict, Keyable, KeysBuilder\nfrom testing import assert_equal\n\n@fieldwise_init\nstruct Person(Keyable, Copyable, Movable):\n    var name: String\n    var age: Int\n\n    fn accept[T: KeysBuilder](self, mut keys_builder: T):\n        keys_builder.add_buffer[DType.uint8](self.name.unsafe_ptr(), len(self.name))\n        keys_builder.add(Int64(self.age))\n\nfn main() raises:\n    var p1 = Person(\"Maxim\", 42)\n    var p2 = Person(\"Maximilian\", 62)\n    var p3 = Person(\"Alex\", 25)\n    var p4 = Person(\"Maria\", 28)\n    var p5 = Person(\"Daria\", 13)\n    var p6 = Person(\"Max\", 31)\n\n    var d = Dict[Int]()\n    _ = d.put(p1, 1)\n    _ = d.put(p2, 11)\n    _ = d.put(p3, 111)\n    _ = d.put(p4, 1111)\n    _ = d.put(p5, 11111)\n    _ = d.put(p6, 111111)\n\n    assert_equal(d.get(p1, 0), 1)\n    assert_equal(d.get(p2, 0), 11)\n    assert_equal(d.get(p3, 0), 111)\n    assert_equal(d.get(p4, 0), 1111)\n    assert_equal(d.get(p5, 0), 11111)\n    assert_equal(d.get(p6, 0), 111111)\n```\n\n### Note:\nTo run all tests and benchmarks, call:\n\n```bash\nmake test\n```\n\nand\n\n```bash\nmake benchmark \n```\n\nfor `memory` test you need to install `words` package proper for your distro: https://unix.stackexchange.com/questions/213628/where-do-the-words-in-usr-share-dict-words-come-from/798355#798355\n\n```bash\nmake memory \n```","funding_links":[],"categories":["🗂️ Libraries\u003ca id='libraries'\u003e\u003c/a\u003e","Data Structure and Algorithm"],"sub_categories":["Data Structures"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmzaks%2Fcompact-dict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmzaks%2Fcompact-dict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmzaks%2Fcompact-dict/lists"}