public int SearchLast(object key, IIndexComparer <T> comparer) { int blockIndex = FindLastBlock(key, comparer); int sr; if (blockIndex < 0) { // Guarenteed not found in any blocks so return start of insert block blockIndex = (-(blockIndex + 1)); // - 1; sr = -1; } else { // We got a block, so find out if it's in the block or not. IIndexBlock <T> block = Blocks[blockIndex]; // Try and find it in the block, sr = block.SearchLast(key, comparer); } int offset = 0; for (int i = 0; i < blockIndex; ++i) { IIndexBlock <T> block = Blocks[i]; offset += block.Count; } return(sr >= 0 ? offset + sr : -offset + sr); }
public bool Contains(T value) { int blockIndex = FindLastBlock(value); if (blockIndex < 0) { // We didn't find in the list, so return false. return(false); } // We got a block, so find out if it's in the block or not. IIndexBlock <T> block = Blocks[blockIndex]; // Find, if not there then return false. return(block.SearchLast(value) >= 0); }
public bool RemoveSort(T value) { CheckImmutable(); int blockIndex = FindLastBlock(value); if (blockIndex < 0) { // Not found a block, // The block to remove the value, blockIndex = (-(blockIndex + 1)) - 1; if (blockIndex < 0) { blockIndex = 0; } } // We got a block, so find out if it's in the block or not. IIndexBlock <T> block = Blocks[blockIndex]; // The point to remove the block, int i = block.SearchLast(value); if (i < 0) { // This means we can't found the value in the given block, so return // false. return(false); } // Remove value into the block, T valRemoved = RemoveFromBlock(blockIndex, block, i); if (value.CompareTo(valRemoved) != 0) { throw new ApplicationException("Incorrect value removed."); } // Value removed so return true. return(true); }
public bool UniqueInsertSort(T value) { CheckImmutable(); int blockIndex = FindLastBlock(value); if (blockIndex < 0) { // Not found a block, // The block to insert the value, blockIndex = (-(blockIndex + 1)) - 1; if (blockIndex < 0) { blockIndex = 0; } } // We got a block, so find out if it's in the block or not. IIndexBlock <T> block = Blocks[blockIndex]; // The point to insert in the block, int i = block.SearchLast(value); if (i < 0) { i = -(i + 1); } else { // This means we found the value in the given block, so return false. return(false); } // Insert value into the block, InsertIntoBlock(value, blockIndex, block, i); // Value inserted so return true. return(true); }
public void InsertSort(object key, T value, IIndexComparer <T> comparer) { CheckImmutable(); int blockIndex = FindLastBlock(key, comparer); if (blockIndex < 0) { // Not found a block, // The block to insert the value, blockIndex = (-(blockIndex + 1)) - 1; if (blockIndex < 0) { blockIndex = 0; } } // We got a block, so find out if it's in the block or not. IIndexBlock <T> block = Blocks[blockIndex]; // The point to insert in the block, int i = block.SearchLast(key, comparer); if (i < 0) { i = -(i + 1); } else { i = i + 1; // NOTE: A block can never become totally full so it's always okay to // skip one ahead. } // Insert value into the block, InsertIntoBlock(value, blockIndex, block, i); }