{"id":16204464,"url":"https://github.com/leinlin/filedictionary","last_synced_at":"2025-03-16T11:30:33.189Z","repository":{"id":203685903,"uuid":"690877781","full_name":"leinlin/FileDictionary","owner":"leinlin","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-30T08:36:51.000Z","size":34,"stargazers_count":36,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-27T08:01:23.720Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leinlin.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":"2023-09-13T04:17:29.000Z","updated_at":"2025-02-05T08:46:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"1f78d8e5-501a-43d4-9a01-8ae11d575956","html_url":"https://github.com/leinlin/FileDictionary","commit_stats":null,"previous_names":["leinlin/filedictionary"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leinlin%2FFileDictionary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leinlin%2FFileDictionary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leinlin%2FFileDictionary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leinlin%2FFileDictionary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leinlin","download_url":"https://codeload.github.com/leinlin/FileDictionary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814907,"owners_count":20352037,"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-10-10T09:58:21.488Z","updated_at":"2025-03-16T11:30:32.789Z","avatar_url":"https://github.com/leinlin.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](https://socialify.git.ci/leinlin/FileDictionary/image?description=1\u0026descriptionEditable=A%20project%20for%20ATRI%2CCSharp%20Collection.\u0026forks=1\u0026issues=1\u0026language=1\u0026logo=https%3A%2F%2Fi.loli.net%2F2020%2F11%2F12%2FYcINCkyp8vK2inD.png\u0026owner=1\u0026pattern=Circuit%20Board\u0026stargazers=1\u0026theme=Light)\n\n### 👋 Here is ATRI FileDictionary - 一个有厨力的字典配置系统\n\n## ✨ 特性概览 | Features\n- 纯用算法实现的hash表，没有用到任何C#的字典功能便于修改优化性能\n- 完全开源，没有引用任何第三方库\n- 实现了几乎全部的C# 字典特性，使用起来非常方便\n- 只查询的的表，内存消耗几乎为0.效率在骁龙845机器的读取上为1ms,可以读取100个数据\n\n\n### 🚀 使用范例\n\n编辑器下创建字典的文件\n```\n    var fileDictionary = new FileDictionary\u003cint, string\u003e(\"test.bin\", 1024, true);\n    // 添加数据\n    for (int i = 0; i \u003c= 100; i++)\n    {\n        fileDictionary[i] = \"test\" + i.ToString();\n    }\n    // \n    fileDictionary.Close()\n```\n\nruntime下读取文件\n```\n    var fileDictionary = new FileDictionary\u003cint, string\u003e(\"test.bin\", 1024);\n    // 添加\n    for (int i = 0; i \u003c= 100; i++)\n    {\n        fileDictionary[i] = \"bf1ecbbf0a2d38e3d5c7f7ab43524985\";\n    }\n    // 查询\n    var value = fileDictionary[100];\n\n    // 字典拥有修改和删除，但是使用的时候需要注意性能\n\n    // 修改\n    fileDictionary[100] = \"new str\";\n\n    // 删除\n    fileDictionary.Remove(100);\n\n    // 遍历\n    foreach (var item in fileDictionary)\n    {\n        // your code\n    }\n\n    // 转字典\n    var dict = fileDictionary.ToDictionary();\n```\n\n### 多字典查询\n```\nFileDictionary\u003cstring, bool\u003e f = new FileDictionary\u003cstring, bool\u003e(\"test.bin\", 1024, true);\nfor (int i = 0; i \u003c 10000; i++)\n{\n    f.Add(i.ToString(), i % 2 == 0);\n}\nf.Dispose();\n\nFileDictionary\u003cstring, bool\u003e f2 = new FileDictionary\u003cstring, bool\u003e(\"test2.bin\", 1024, true);\nfor (int i = 0; i \u003c 10000; i++)\n{\n    f2.Add(i.ToString(), i % 2 == 0);\n}\nf2.Dispose();\n\nFileDictionary\u003cint, string\u003e f3 = new FileDictionary\u003cint, string\u003e(\"test3.bin\", 1024, true);\nfor (int i = 0; i \u003c 10000; i++)\n{\n    f3.Add(i, i.ToString());\n}\nf3.Dispose();\n\nFileDB fdb = new FileDB(\"file.fdb\");\n// 编辑器下直接合并为一个大DB\nfdb.MergeEditor(\"test.bin\", \"test2.bin\", \"test3.bin\");\n\n// 运行中合并FileDictionary 为DB，这样可以避免热更的时候更出去过大的文件\nfdb.MergeRuntime(\"test.bin\", \"test2.bin\", \"test3.bin\");\n\nbool v;\nif (fdb.TryGetValueByTableName(\"test\", \"0\", out v))\n{\n    print(\"test success:\" + v);\n}\nelse\n{\n    print(\"test fail\");\n}\n\nif (fdb.TryGetValueByTableName(\"test2\", \"3\", out v))\n{\n    print(\"test2 success:\" + v);\n}\nelse\n{\n    print(\"test2 fail\");\n}\n\nstring strV;\nif (fdb.TryGetValueByTableName(\"test3\", 100, out strV))\n{\n    print(\"test3 success:\" + strV);\n}\nelse\n{\n    print(\"test3 fail\");\n}\n```\n\n\n### 📱 目前库里面支持的类型有 \n- \u003cint,string\u003e\n- \u003cint, bool\u003e\n- \u003cint, int\u003e\n- \u003cint, string[]\u003e\n- \u003cint, byte[]\u003e\n- \u003cstring,string\u003e\n- \u003cstring, bool\u003e\n- \u003cstring, int\u003e\n- \u003cstring, string[]\u003e\n- \u003cstring, byte[]\u003e\n\n### 📖 使用疑问\n- 添加新的字典类型：如果需要支持新的kv类型，可以 继承 IFileDictionaryDelegate\u003cTKey, TValue\u003e接口实现对应的序列化、反序列化、hashcode。最后在在FileDictionaryDelegateFactory的GetFileDictionaryDelegate中添加对应的代码。\n- probuf或者其他的二进制存储推荐使用 \u003cint, byte[]\u003e使用的时候反序列化，当然如果嫌弃麻烦可以自己写一个将二进制序列化为class的IFileDictionaryDelegate\u003cTKey, TValue\u003e接口类\n- 如果需要把配置表转到内存中，推荐使用ToDictionary，然后直接放到内存的字典中，之后将本字典释放掉即可\n- 如果不需要数据，建议直接Dipose掉FileDictionary\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleinlin%2Ffiledictionary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleinlin%2Ffiledictionary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleinlin%2Ffiledictionary/lists"}