private IEnumerable <HashTableElement> GetElementWithKeyEnumerable(byte[] key) { int hash = key.GetHash(); int nextAvailableArrayIndex = hash % GetTableSize(); HashTableElement element = GetElementAt(nextAvailableArrayIndex); yield return(element); while (!element.Key.EqualsBytes(key) && !element.Key.EqualsBytes(NullKey)) { int nextIndex = GetNextIndexAfterCollision(element.Index); while (nextIndex >= _simpleCollectionNextIndex.GetNextIndex()) //there's nothing past this so simulate a wrap around { nextIndex = GetNextIndexAfterCollision(element.Index); } element = GetElementAt(nextIndex); //if (element.Key.EqualsBytes(key)) // we've looped all the way around // throw new KeyNotFoundException("key not found"); yield return(element); } if (element.Key.EqualsBytes(NullKey)) // key was not located before the null key was found { throw new KeyNotFoundException("key not found"); } }
public int AllocateBlock() { int indexToAllocate; if (GetNextFreeSpaceIndex() == FreeSpaceTailIndicator) { indexToAllocate = _simpleCollectionNextSpace.GetNextIndex(); } else { indexToAllocate = PopFreeSpaceOffStack(); } return(indexToAllocate); }
private void GetNextIndexTestAssert(int expected) { IPersistentArrayNextSpace target = InitPA("GetPANextIndexTest", 1, 16); try{ target.Put(expected - 1, new byte[0]); int actual = target.GetNextIndex(); Assert.AreEqual(expected, actual); } finally { target.Close(); } }
public int GetNextIndex() { return(_simpleCollectionNextSpace.GetNextIndex()); }