hashCode()
Computes a hash code for a storage key, useful for hash-based data structures.Signature
Parameters
- key (
BrandedStorageKey) - Storage key to hash
Returns
number - 32-bit hash code (JavaScript) or u64 (Zig)
Examples
Use Cases
HashMap Keys
Partitioning
Caching
Sharding
Implementation Notes
- Hash code is computed from both address and slot
- Same key always produces same hash (deterministic)
- Different keys may produce same hash (collisions possible)
- Hash distribution is pseudo-random for good bucketing
Properties
- Deterministic: Same input always produces same output
- Fast: O(1) time complexity
- Collision-resistant: Good distribution, but collisions possible
- 32-bit: JavaScript returns 32-bit signed integer
- 64-bit: Zig returns 64-bit unsigned integer
Related
- StorageKey() - Factory function
- equals() - Equality comparison
- toString() - String serialization
- Fundamentals - Learn about storage keys

