Skip to content

Commit

Permalink
update hash function and version
Browse files Browse the repository at this point in the history
  • Loading branch information
vazarkevych committed Oct 18, 2024
1 parent a4cd7a7 commit 985c5e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 3.9.7
- Update hash function to get same result on web & mobile.

# 3.9.6
- Fixed issue with fallback attribute ignoring when needed.

Expand Down
15 changes: 9 additions & 6 deletions lib/src/Utils/gb_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ class FNV {
// Constants for FNV-1a 32-bit hash
final int init32 = 0x811c9dc5;
final int prime32 = 0x01000193;
final int mod32 = 0x100000000; // Equivalent to 2^32

/// Fowler-Noll-Vo hash - 32 bit
/// Returns an integer representing the hash.
int fnv1a32(String data) {
int fnv1a32(String str) {
int hash = init32;
for (int i = 0; i < data.length; i++) {
int b = data.codeUnitAt(i) & 0xff; // Get the ASCII value of the character
hash ^= b; // XOR the hash with the character's value
hash = (hash * prime32) % mod32; // Multiply by prime and mod with mod32
final int length = str.length;

for (int i = 0; i < length; i++) {
hash ^= str.codeUnitAt(i); // XOR with character value

// Perform multiplication by prime using bitwise shifts and ensure 32-bit unsigned
hash = ((hash * prime32) & 0xffffffff).toUnsigned(32);
}

return hash;
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: growthbook_sdk_flutter
description: An open-source feature flagging and experimentation platform that makes it simple to alter features and execute A/B testing.
version: 3.9.6
version: 3.9.7
homepage: https://github.com/alippo-com/GrowthBook-SDK-Flutter
repository: https://github.com/growthbook/growthbook-flutter

Expand Down

0 comments on commit 985c5e5

Please sign in to comment.