public static long HashToLong(string data) { uint hash1; uint hash2; PerfectHash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(data.ToUpper(CultureInfo.InvariantCulture)), seed1: 0, seed2: 0, hash1: out hash1, hash2: out hash2); long hashedValue = ((long)hash1 << 32) | (long)hash2; return(hashedValue); }
public static short HashToShort(string data) { uint hash1; uint hash2; string upper = data.ToUpper(CultureInfo.InvariantCulture); PerfectHash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(upper), seed1: 0, seed2: 0, hash1: out hash1, hash2: out hash2); long hashedValue = hash1 ^ hash2; return((short)hashedValue); }
public static long HashToLong(string data) { uint hash1; uint hash2; #if NETSTANDARD1_3 string upper = data.ToUpper(); #else string upper = data.ToUpper(CultureInfo.InvariantCulture); #endif PerfectHash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(upper), seed1: 0, seed2: 0, hash1: out hash1, hash2: out hash2); long hashedValue = ((long)hash1 << 32) | (long)hash2; return(hashedValue); }
public static short HashToShort(string data) { uint hash1; uint hash2; #if WINDOWS_UWP || NETSTANDARD1_3 string upper = data.ToUpper(); #else string upper = data.ToUpper(CultureInfo.InvariantCulture); #endif PerfectHash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(upper), seed1: 0, seed2: 0, hash1: out hash1, hash2: out hash2); long hashedValue = hash1 ^ hash2; return((short)hashedValue); }
public static long HashToLong(string data) { if (data == null) { throw new ArgumentNullException(nameof(data), "The data string cannot be null."); } uint hash1; uint hash2; string upper = data.ToUpper(CultureInfo.InvariantCulture); PerfectHash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(upper), seed1: 0, seed2: 0, hash1: out hash1, hash2: out hash2); long hashedValue = ((long)hash1 << 32) | (long)hash2; return(hashedValue); }
public static string ResolveToPartition(string partitionKey, int partitionCount) { if (string.IsNullOrWhiteSpace(partitionKey)) { throw new ArgumentNullException(nameof(partitionKey)); } if (partitionCount < 1 || partitionCount > DefaultLogicalPartitionCount) { throw new ArgumentOutOfRangeException(nameof(partitionCount), partitionCount, string.Format(CultureInfo.InvariantCulture, "Should be between {0} and {1}", 1, DefaultLogicalPartitionCount)); } short logicalPartition = Math.Abs((short)(PerfectHash.HashToShort(partitionKey) % DefaultLogicalPartitionCount)); int shortRangeWidth = (int)Math.Floor((decimal)DefaultLogicalPartitionCount / (decimal)(partitionCount)); int remainingLogicalPartitions = DefaultLogicalPartitionCount - (partitionCount * shortRangeWidth); int largeRangeWidth = shortRangeWidth + 1; int largeRangesLogicalPartitions = largeRangeWidth * remainingLogicalPartitions; int partitionIndex = logicalPartition < largeRangesLogicalPartitions ? logicalPartition / largeRangeWidth : remainingLogicalPartitions + ((logicalPartition - largeRangesLogicalPartitions) / shortRangeWidth); return(partitionIndex.ToString(NumberFormatInfo.InvariantInfo)); }