Created
March 8, 2024 03:46
-
-
Save avioli/23b6b9cbcbbab12e657c67aa970b3970 to your computer and use it in GitHub Desktop.
Revisions
-
avioli created this gist
Mar 8, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ /// FNV-1a 64bit hash algorithm optimized for Dart Strings int fastHash(String string) { var hash = 0xcbf29ce484222325; var i = 0; while (i < string.length) { final codeUnit = string.codeUnitAt(i++); hash ^= codeUnit >> 8; hash *= 0x100000001b3; hash ^= codeUnit & 0xFF; hash *= 0x100000001b3; } return hash; } // From: https://isar.dev/recipes/string_ids.html#fast-hash-function // Avoid using string.hashCode because it is not guaranteed to be stable across different platforms and versions of Dart.