コード例 #1
0
        private (string, string) GenerateTwoDifferentStringsWithTheSameHashCode()
        {
            var words = new Dictionary <int, string>();

            var    i = 0;
            string tempString;

            while (true)
            {
                i++;
                tempString = i.ToString();
                try
                {
                    words.Add(_hashFunction.GetHashCode(tempString), tempString);
                }
                catch (Exception)
                {
                    break;
                }
            }

            var collisionHash = _hashFunction.GetHashCode(tempString);

            return(words[collisionHash], tempString);
        }
コード例 #2
0
        public void Returns_SameHashCode_FromSameString()
        {
            var inputStringCopy = (string)InputString.Clone();

            _hashFunction.GetHashCode(InputString).Should().Be(_hashFunction.GetHashCode(inputStringCopy));
        }
コード例 #3
0
 /// <summary>
 /// Сounts the index of the chain for this value using a hash function.
 /// </summary>
 /// <param name="value">The value of the element to add.</param>
 /// <param name="lengthOfBuckets">Length of the current buckets</param>
 /// <returns>Index of the chain in which the element should be placed.</returns>
 private int GetArrayPosition(string value, int lengthOfBuckets)
 {
     return(Math.Abs(_hashFunction.GetHashCode(value)) % lengthOfBuckets);
 }