Skip to content

Commit a10e902

Browse files
refactor: update getLockIndex algorithm
- Replace hash function with MurmurHash3 for improved performance - Calculate lockIndex directly instead of using intermediate variables
1 parent 799ab5d commit a10e902

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Sources/CMAB/CmabService.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ class DefaultCmabService: CmabService {
5959

6060
private func getLockIndex(userId: String, ruleId: String) -> Int {
6161
let combinedKey = userId + ruleId
62-
let hashValue = combinedKey.hashValue
63-
// Take absolute value to ensure positive number
64-
let positiveHash = abs(hashValue)
65-
// Use modulo to map to lock array index [0, NUM_LOCKS-1]
66-
return positiveHash % Self.NUM_LOCKS
62+
let hashValue = MurmurHash3.hash32(key: combinedKey)
63+
let lockIndex = Int(hashValue) % Self.NUM_LOCKS
64+
return lockIndex
6765
}
6866

6967
func getDecision(config: ProjectConfig,

0 commit comments

Comments
 (0)