Example #1
0
        /// <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}");
        }
Example #2
0
        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}");
        }
Example #3
0
        public void Test_GuidHashCode_HashCode_NotEmpty()
        {
            Guid g = Guid.NewGuid();

            GuidHashCode.Hash(g).Should().NotBe(0, $"for Guid value {g}");
        }
Example #4
0
 public void Test_GuidHashCode_Hash_Empty()
 {
     // An empty guid (all zeros) should always be 0
     GuidHashCode.Hash(Guid.Empty).Should().Be(0);
 }
Example #5
0
 public int GetHashCode(Guid obj) => GuidHashCode.Hash(obj);
Example #6
0
 public int GetPartition(object key) => Math.Abs(GuidHashCode.Hash(((NonSpatialAffinityKey)key).ProjectID)) % Partitions;
Example #7
0
 //[Benchmark]
 public void GuidHashCode_UsingLessByteArrays_Safe()
 {
     int hash = GuidHashCode.Hash(guid);
 }
Example #8
0
 //[Benchmark]
 public void GuidHashCode_UsingByteArrays()
 {
     int hash = GuidHashCode.Hash_Old(guid);
 }