{"id":13786580,"url":"https://github.com/troubear/BetterDictionary","last_synced_at":"2025-05-11T22:31:32.986Z","repository":{"id":54329440,"uuid":"107080139","full_name":"troubear/BetterDictionary","owner":"troubear","description":"Better performance generic Dictionary and HashSet optimized for Unity","archived":true,"fork":false,"pushed_at":"2018-12-20T04:48:49.000Z","size":34,"stargazers_count":71,"open_issues_count":0,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-12T00:02:10.087Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/troubear.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":"2017-10-16T05:01:41.000Z","updated_at":"2025-03-07T04:01:17.000Z","dependencies_parsed_at":"2022-08-13T12:10:38.156Z","dependency_job_id":null,"html_url":"https://github.com/troubear/BetterDictionary","commit_stats":null,"previous_names":["komatus/betterdictionary"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/troubear%2FBetterDictionary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/troubear%2FBetterDictionary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/troubear%2FBetterDictionary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/troubear%2FBetterDictionary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/troubear","download_url":"https://codeload.github.com/troubear/BetterDictionary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253645208,"owners_count":21941312,"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-08-03T19:01:18.408Z","updated_at":"2025-05-11T22:31:27.969Z","avatar_url":"https://github.com/troubear.png","language":"C#","readme":"BetterDictionary for Unity\n===\n本ライブラリが提供するDictionary/HashSetクラスは、System.Collections.Generic名前空間の同名クラスをUnity向けに高速化※したものです。  \n\n    ※.NET Core 2.0等の環境で使用した場合、逆にパフォーマンスが低下する場合があります。\n\n特徴\n---\n- 一部をILで実装したIEqualityComparer\\\u003cT\\\u003eを使用するDictionary/HashSetクラスです。\n  - System.Collections.Generic名前空間の同名クラスを継承しているため、既存プロジェクトへの導入が比較的容易です。\n- .NET 3.5ランタイムにおいて、列挙型・プリミティブ型(intやbyte等)・string型をキーとした場合にパフォーマンスが向上します。\n  - 列挙型は\\~70%程度、プリミティブ型は\\~20%程度、string型は\\~15%程度の高速化。\n  - **列挙型をキーとした場合にボックス化が発生しません。**(IEqualityComparer\u003cT\u003eを実装した場合と同等のパフォーマンスで動作します）\n- .NET 4.6ランタイムにおいても、通常のDictionary/HashSetクラスよりは高速に動作します。\n  - 列挙型は\\~30%程度、プリミティブ型は\\~20%程度、string型は\\~20%程度の高速化。\n- IL2CPP(iOS/Android)に対応しています。  \n  - ※但し、IL2CPPが生成するC++コードのコンパイルエラーを強引に回避しているため、将来的にコンパイルが通らなくなる可能性があります。\n\n導入方法\n---\n1. [リリースページ](https://github.com/komatus/BetterDictionary/releases)から最新版の.unitypackageをダウンロード＆インストールします。\n    - リポジトリのAssets/Plugins以下を直接自身のプロジェクトにコピーしても問題ありません。\n1. 既存コードを以下のように変更します。  \n    \n    ```csharp\n    // Before:\n    Dictionary\u003cMyEnum, string\u003e _dict = new Dictionary\u003cMyEnum, string\u003e();\n    HashSet\u003cstring\u003e _strings         = new HashSet\u003cstring\u003e();\n\n    // After:\n    Dictionary\u003cMyEnum, string\u003e _dict = new Better.Dictionary\u003cMyEnum, string\u003e();\n    HashSet\u003cstring\u003e _strings         = new Better.HashSet\u003cstring\u003e();\n    ```\n\n1. または、`PlayerSettings`の`Scripting Define Symbols`に`BETTER_PATCH`を追加し、プロジェクトソース内で使用されているSystem.Collections.Generic名前空間のDictionary/HashSetクラスを本ライブラリのクラスで一括置換※します。\n    - ※`BETTER_PATCH`シンボルの追加によって、本ライブラリのDictionary/HashSetクラスがグローバル名前空間で定義されます。\n\nStringKey (ハッシュ計算済み文字列キー)\n---\nBetter.StringKeyを使用することで、Dictionary/HashSetへのアクセスを高速化することができます。\n\n~~~csharp\nusing Better;\n\n// Typical extension method of the Dictionary class\npublic static void AddOrUpdate\u003cTKey, TValue\u003e(\n  this Dictionary\u003cTKey, TValue\u003e dict, TKey key, TValue value)\n{\n  if (dict.ContainsKey(key))\n  {\n    dict[key] = value;\n  }\n  else\n  {\n    dict.Add(key, value);\n  }\n}\n\nDictionary\u003cstring, int\u003e dict1;\nDictionary\u003cStringKey, int\u003e dict2;\n\ndict1.AddOrUpdate(\"hogehoge\", 1234);\n\n// Depending on the length of the string,\n// several percent to tens of percent faster than the raw string key.\n// 文字列の長さによって、stringキーより数パーセント～数十パーセント速くなります。\ndict2.AddOrUpdate(\"hogehoge\", 1234);\n\n// Attention!!\n// However, in the case of a single operation it will slow down about 30%.\n// ※但し、単一オペレーションでは約30%程度遅くなります。\ndict2[\"hogehoge\"] = 5678;\n\n// Therefore, it is strongly recommended to prepare StringKey in advance.\n// 従って、StringKeyを事前に用意しておくことを強く推奨します。\nstatic StringKey HogeHoge = \"hogehoge\";\ndict2[HogeHoge] = 5678; // Faster than dict1[\"hogehoge\"]\n~~~\n\nTODO\n---\n- 詳細なパフォーマンス計測＆グラフ化\n- Translate the README into English.\n\nLicense\n---\nThis library is under the MIT License.\n\nSome code is borrowed from [Microsoft/referencesource](https://github.com/Microsoft/referencesource).\n","funding_links":[],"categories":["Optimization"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftroubear%2FBetterDictionary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftroubear%2FBetterDictionary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftroubear%2FBetterDictionary/lists"}