示例#1
0
        public void CtorTest()
        {
            const int           tableSize = 88;
            const int           keySize   = 3;
            const int           valueSize = 10;
            PersistentHashTable hashTable = InitTable("ctor", tableSize, keySize, valueSize, 4);

            try
            {
                Assert.AreEqual(tableSize, hashTable.GetTableSize());
                Assert.AreEqual(keySize, hashTable.GetKeySize());
                Assert.AreEqual(valueSize, hashTable.GetValueSize());
            }
            finally
            {
                hashTable.Close();
            }
        }
示例#2
0
        public void RemoveCollisionTest()
        {
            PersistentHashTable hashTable = InitTable("HashTableRemove", 20, 4, 4, 6);

            try
            {
                //fill the table up with collisions
                byte[] lastCollisionKey = FillTableWithCollisions(5, hashTable);

                hashTable.Remove(lastCollisionKey);

                hashTable.Put(lastCollisionKey, new byte[hashTable.GetValueSize()]);
            }
            finally
            {
                hashTable.Close();
            }
        }
示例#3
0
        private static byte[] FillTableWithCollisions(int targetHashToCollideOn, PersistentHashTable hashTable)
        {
            byte[] collisionKey = new byte[] { 0, 0, 0, 0 };
            for (int run = 0; run < hashTable.GetTableSize(); run++)
            {
                collisionKey = GetNextCollisionKey(targetHashToCollideOn, hashTable.GetTableSize(), collisionKey);

                hashTable.Put(collisionKey, new byte[] { 0, 0, 0, (byte)run });
            }

            //assert the table is full
            try
            {
                hashTable.Put(new byte[] { 255, 255, 255, 255 }, new byte[hashTable.GetValueSize()]);
                Assert.Fail("Should throw exception");
            }
            catch (IndexOutOfRangeException) {}
            return(collisionKey);
        }