public void Remove_SameHashcode() { // We want to add and delete items (with the same hashcode) to the hashtable in such a way that the hashtable // does not expand but have to tread through collision bit set positions to insert the new elements. We do this // by creating a default hashtable of size 11 (with the default load factor of 0.72), this should mean that // the hashtable does not expand as long as we have at most 7 elements at any given time? var hash = new HashtableEx(); var arrList = new ArrayList(); for (int i = 0; i < 7; i++) { var hashConfuse = new BadHashCode(i); arrList.Add(hashConfuse); hash.Add(hashConfuse, i); } var rand = new Random(-55); int iCount = 7; for (int i = 0; i < 100; i++) { for (int j = 0; j < 7; j++) { Assert.AreEqual(hash[arrList[j]], ((BadHashCode)arrList[j]).Value); } // Delete 3 elements from the hashtable for (int j = 0; j < 3; j++) { int iElement = rand.Next(6); hash.Remove(arrList[iElement]); Assert.IsFalse(hash.ContainsValue(null)); arrList.RemoveAt(iElement); int testInt = iCount++; var hashConfuse = new BadHashCode(testInt); arrList.Add(hashConfuse); hash.Add(hashConfuse, testInt); } } }
public void Clone(int count) { HashtableEx hash1 = Helpers.CreateStringHashtable(count); Helpers.PerformActionOnAllHashtableWrappers(hash1, hash2 => { HashtableEx clone = (HashtableEx)hash2.Clone(); Assert.AreEqual(hash2.Count, clone.Count); Assert.AreEqual(hash2.IsSynchronized, clone.IsSynchronized); Assert.AreEqual(hash2.IsFixedSize, clone.IsFixedSize); Assert.AreEqual(hash2.IsReadOnly, clone.IsReadOnly); for (int i = 0; i < clone.Count; i++) { string key = "Key_" + i; string value = "Value_" + i; Assert.IsTrue(clone.ContainsKey(key)); Assert.IsTrue(clone.ContainsValue(value)); Assert.AreEqual(value, clone[key]); } }); }
internal bool ContainsValue(PropertyMetadata typeMetadata) => _table.ContainsValue(typeMetadata);