/// <summary> /// Given a cache key, determine which partition the cache item should reside /// </summary> public override int GetPartition(object key) { // Pull the sub grid origin location for the sub grid or segment represented in the cache key and calculate the // spatial processing division descriptor to use as the partition affinity key if (key is IProjectAffinity affinityKey) { // Compute partition number as the modulo NumPartitions result against the project iD in the spatial affinity key return(Math.Abs(GuidHashCode.Hash(affinityKey.ProjectUID)) % Partitions); } Log.LogCritical($"Unknown key type to compute non spatial affinity partition key for: type [{key.GetType().FullName}] {key}. Returning partition 0 to avoid thrown exception"); return(0); //throw new ArgumentException($"Unknown key type to compute non spatial affinity partition key for: [{key.GetType().FullName}] {key}"); }
public void Test_GuidHashCode_HashCode_Divergence(string guidString, int expectedHash) { Guid g = new Guid(guidString); GuidHashCode.Hash(g).Should().Be(expectedHash, $"for Guid value {g}"); }
public void Test_GuidHashCode_HashCode_NotEmpty() { Guid g = Guid.NewGuid(); GuidHashCode.Hash(g).Should().NotBe(0, $"for Guid value {g}"); }
public void Test_GuidHashCode_Hash_Empty() { // An empty guid (all zeros) should always be 0 GuidHashCode.Hash(Guid.Empty).Should().Be(0); }
public int GetHashCode(Guid obj) => GuidHashCode.Hash(obj);
public int GetPartition(object key) => Math.Abs(GuidHashCode.Hash(((NonSpatialAffinityKey)key).ProjectID)) % Partitions;
//[Benchmark] public void GuidHashCode_UsingLessByteArrays_Safe() { int hash = GuidHashCode.Hash(guid); }
//[Benchmark] public void GuidHashCode_UsingByteArrays() { int hash = GuidHashCode.Hash_Old(guid); }