Beispiel #1
0
        /// <summary>
        /// Computes Adler32 for encoded string
        /// </summary>
        public static uint ForEncodedString(string text, System.Text.Encoding encoding)
        {
            if (encoding == null)
            {
                encoding = System.Text.Encoding.UTF8;
            }
            var buff = encoding.GetBytes(text);

            return(Adler32.ForBytes(buff));
        }
Beispiel #2
0
        /// <summary>
        /// Gets sharding ID for byte[], that is - computes byte[] hash as UInt64 .
        /// WARNING! Changing this function will render all existing sharding partitioning invalid. Use extreme care!
        /// </summary>
        public static ulong ByteArrayToShardingID(byte[] key)
        {
            if (key == null)
            {
                return(0);
            }
            if (key.Length == 0)
            {
                return(0);
            }

            ulong result = 1566083941ul * (ulong)Adler32.ForBytes(key);

            return(result);
        }