diff --git a/.github/workflows/build-listing.yml b/.github/workflows/build-listing.yml new file mode 100644 index 0000000..e95ce72 --- /dev/null +++ b/.github/workflows/build-listing.yml @@ -0,0 +1,21 @@ +name: Build Package Listing + +on: + workflow_dispatch: + workflow_run: + workflows: [Build Release] + types: + - completed + release: + types: [published, created, edited, unpublished, deleted, released] + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +jobs: + + build-listing: + uses: Narazaka/vpm-repos/.github/workflows/build-package-listing.yml@main \ No newline at end of file diff --git a/.github/workflows/call-build-repo-listing.yml b/.github/workflows/call-build-repo-listing.yml new file mode 100644 index 0000000..32e1bff --- /dev/null +++ b/.github/workflows/call-build-repo-listing.yml @@ -0,0 +1,18 @@ +name: Call Build Repo Listing + +on: + workflow_dispatch: + workflow_run: + workflows: [Build Package Listing] + types: + - completed + +permissions: + contents: read + +jobs: + + build-listing: + uses: Narazaka/vpm-repos/.github/workflows/call-build-listing.yml@main + secrets: + DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..aaf72f3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,14 @@ +name: Build Release + +on: + workflow_dispatch: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + build: + uses: Narazaka/vpm-repos/.github/workflows/release.yml@main \ No newline at end of file diff --git a/FNV1a32.cs b/FNV1a32.cs new file mode 100644 index 0000000..3e323fb --- /dev/null +++ b/FNV1a32.cs @@ -0,0 +1,26 @@ +namespace Narazaka.SimpleHash +{ + public static class FNV1a32 + { + // cvf. https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function + const uint FNV_OFFSET_BASIS = 2166136261; + const uint FNV_PRIME = 16777619; + public static uint ComputeHash(byte[] bytes) + { + uint hash = FNV_OFFSET_BASIS; + var len = bytes.Length; + for (var i = 0; i < len; i++) + { + hash = (hash ^ bytes[i]) * FNV_PRIME; + } + return hash; + } + +#if HAS_UDON_ENCODING + public static uint ComputeHash(string str) + { + return ComputeHash(Koyashiro.UdonEncoding.UdonUTF8.GetBytes(str)); + } +#endif + } +} diff --git a/FNV1a32.cs.meta b/FNV1a32.cs.meta new file mode 100644 index 0000000..57a890f --- /dev/null +++ b/FNV1a32.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: be3d0e46710dc2d46aa3de7995a915e3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..1c98478 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2023 Narazaka + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. diff --git a/LICENSE.txt.meta b/LICENSE.txt.meta new file mode 100644 index 0000000..dab04ca --- /dev/null +++ b/LICENSE.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3e0c1a60cc84ba14fab784da4c4c7532 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Narazaka.SimpleHash.asmdef b/Narazaka.SimpleHash.asmdef new file mode 100644 index 0000000..508bac7 --- /dev/null +++ b/Narazaka.SimpleHash.asmdef @@ -0,0 +1,22 @@ +{ + "name": "Narazaka.SimpleHash", + "rootNamespace": "", + "references": [ + "Koyashiro.UdonEncoding" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [ + { + "name": "net.koyashiro.udonencoding", + "expression": "0.4.4", + "define": "HAS_UDON_ENCODING" + } + ], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Narazaka.SimpleHash.asmdef.meta b/Narazaka.SimpleHash.asmdef.meta new file mode 100644 index 0000000..72677fc --- /dev/null +++ b/Narazaka.SimpleHash.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5b0c9699ef476e2499186cdd8a56a723 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c2560b --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Simple Hash + +Udon compatible 32bit hash lib + +- FNV1a32 + +## Install + +1. https://vpm.narazaka.net/ から「Add to VCC」ボタンを押してリポジトリをVCCにインストールします。 +2. VCCでSettings→Packages→Installed Repositoriesの一覧中で「Narazaka VPM Listing」にチェックが付いていることを確認します。 +3. ワールドプロジェクトの「Manage Project」から「Simple Hash」をインストールします。 + +## Usage + +```csharp +using Narazaka.SimpleHash; +var playerHash = FNV1a32.ComputeHash(Networking.LocalPlayer.displayName); +``` + +## 更新履歴 + +- 1.0.0 + - リリース + +## License + +[Zlib License](LICENSE.txt) diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..fa7f0fb --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: a70aebd7b4080f746b194b1d0d9ad5a2 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..53cc0bc --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "net.narazaka.simple-hash", + "version": "1.0.0", + "displayName": "Simple Hash", + "description": "Udon compatible 32bit hash lib (FNV1a32)", + "author": { + "name": "Narazaka", + "url": "https://github.com/Narazaka" + }, + "license": "Zlib", + "type": "tool", + "url" : "https://github.com/Narazaka/SimpleHash.git", + "vpmDependencies": { + "com.vrchat.worlds": ">=3.0.9" + } +} diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..a698197 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5c332d284c259e741b26a640f5a9d16d +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: