Esempio n. 1
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);
        }
Esempio n. 2
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();
            }
        }