@Override public IndexSearchResultIteratorCollection search(SearchCondition condition, SearchLimit limit) throws JasDBStorageException { IndexIterator indexIterator = new FullIndexIterator(rootBlock, lockManager, blockPersister); EqualsCondition equalsCondition = EqualsSearchOperation.validateCondition(keyInfo, condition); Key undesiredKey = equalsCondition.getKey(); List<Key> results = new LinkedList<>(); for(Key key : indexIterator) { if(key.compare(undesiredKey, CompareMethod.EQUALS).getCompare() != 0) { results.add(key); } if(limit.isMaxReached(results.size())) { break; } } return new IndexSearchResultIteratorImpl(results, keyInfo.getKeyNameMapper()); } }
private V before(TreeNode<Key, V> currentNode, Key key) { int compare = key.compare(currentNode.getKey(), CompareMethod.BEFORE).getCompare(); if(compare == 0) { return currentNode.getValue(); } else if(compare > 0) { if(currentNode.getRight() != null) { TreeNode<Key, V> right = currentNode.getRight(); if(key.compare(right.min().getKey(), CompareMethod.BEFORE).getCompare() < 0) { return currentNode.getValue(); } else { return before(right, key); } } return currentNode.getValue(); } else if(compare < 0) { if(currentNode.getLeft() != null) { TreeNode<Key, V> left = currentNode.getLeft(); TreeNode<Key, V> leftMax = left.max(); if(key.compare(leftMax.getKey(), CompareMethod.BEFORE).getCompare() > 0) { return leftMax.getValue(); } else { return before(left, key); } } return currentNode.getValue(); } else { return null; } }