diff --git a/src/client/spark_api/utils/EqualityComparer.cs b/src/client/spark_api/utils/EqualityComparer.cs index 2556dbd05..a30f11b9b 100644 --- a/src/client/spark_api/utils/EqualityComparer.cs +++ b/src/client/spark_api/utils/EqualityComparer.cs @@ -77,16 +77,17 @@ namespace bts.utils { public static int auto_phase(params int[] hash_codes) => auto_phase(Array.AsReadOnly(hash_codes)); - + public static int auto_phase(IEnumerable items) => auto_phase(items.Take(_max_auto_phase_buckets).ToList()); - public static int auto_phase(IReadOnlyList hash_codes) { + public static int auto_phase(IReadOnlyList hash_codes, int bit_span = 32) { + Log.assert(bit_span > 0 && bit_span <= 32); // don't divide by zero if (hash_codes.Count == 0) return 0; int size = Math.Min(hash_codes.Count, _max_auto_phase_buckets); - int bits_per_hash = 32 / size; + int bits_per_hash = bit_span / size; int phase = 1 << (bits_per_hash - 1); int rv = hash_codes[0].GetHashCode() % phase; /// The idea is to split the 32 to bits into evenly sized buckets for each hash code item. @@ -164,4 +165,4 @@ namespace bts.utils { public int GetHashCode(T obj) => obj == null ? 0 : _comparer.GetHashCode(obj); } } -} \ No newline at end of file +}