public void checkResults(RBTree<Integer, String> tree, int range, int start, int end, int increment) { FastIterator it = tree.range( start, true, end, true ); Entry entry = null; int i = 0; List<Integer> actual = new ArrayList<Integer>(); //System.out.println( start + ":" + end + ":" + (((end - start) / increment) + 1) ); while ( (entry = it.next( entry )) != null ) { Node<Integer, String> node = (Node<Integer, String>) entry; } for ( i = 0; i < range; i = i + increment ) { tree.delete(i); } }
if ( childLeftTuple != null && rightMemory.isIndexed() && !it.isFullIterator() && (rightTuple == null || (rightTuple.getMemory() != childLeftTuple.getRightParent().getMemory())) ) { for ( ; rightTuple != null; rightTuple = (RightTuple) it.next( rightTuple ) ) { propagateFromLeft( rightTuple, leftTuple, contextEntry, true, context, workingMemory ); for ( ; rightTuple != null; rightTuple = (RightTuple) it.next( rightTuple ) ) { childLeftTuple = propagateOrModifyFromLeft( rightTuple, leftTuple, childLeftTuple, contextEntry, context, workingMemory );
if ( childLeftTuple != null && leftMemory.isIndexed() && !it.isFullIterator() && (leftTuple == null || (leftTuple.getMemory() != childLeftTuple.getLeftParent().getMemory())) ) { for ( ; leftTuple != null; leftTuple = (LeftTuple) it.next( leftTuple ) ) { propagateFromRight( rightTuple, leftTuple, memory, context, workingMemory ); for ( ; leftTuple != null; leftTuple = (LeftTuple) it.next( leftTuple ) ) { childLeftTuple = propagateOrModifyFromRight( rightTuple, leftTuple, childLeftTuple, memory, context, workingMemory );
@Test public void testIterator() { final int ITEMS = 10000; RBTree<Integer, String> tree = new RBTree<Integer, String>(); Random random = new Random(0); for (int i = 0; i < ITEMS; i++) { int key = random.nextInt(); tree.insert( key, "" + key ); } int i = 0; FastIterator fastIterator = tree.fastIterator(); int lastKey = Integer.MIN_VALUE; for (Node<Integer, String> node = (Node<Integer, String>)fastIterator.next(null); node != null; node = (Node<Integer, String>)fastIterator.next(node)) { int currentKey = node.key; if (currentKey < lastKey) { fail(currentKey + " should be greater than " + lastKey); } lastKey = currentKey; i++; } assertEquals(ITEMS, i); }
if ( childLeftTuple != null && rightMemory.isIndexed() && !it.isFullIterator() && (rightTuple == null || (rightTuple.getMemory() != childLeftTuple.getRightParent().getMemory())) ) { for ( ; rightTuple != null; rightTuple = (RightTuple) it.next( rightTuple ) ) { final InternalFactHandle handle = rightTuple.getFactHandle(); if ( this.constraints.isAllowedCachedLeft( contextEntry, for ( ; rightTuple != null; rightTuple = (RightTuple) it.next( rightTuple ) ) { final InternalFactHandle handle = rightTuple.getFactHandle();
@Test public void testRange() { RBTree<Integer, String> tree = new RBTree<Integer, String>(); tree.insert( 10, "" + 10 ); tree.insert( 20, "" + 20 ); tree.insert( 25, "" + 25 ); tree.insert( 15, "" + 15 ); tree.insert( 5, "" + 5 ); FastIterator fastIterator = tree.range(2, true, 15, false); Node<Integer, String> node = (Node<Integer, String>)fastIterator.next(null); assertEquals(5, (int)node.key); node = (Node<Integer, String>)fastIterator.next(node); assertEquals(10, (int)node.key); node = (Node<Integer, String>)fastIterator.next(node); assertNull(node); fastIterator = tree.range(2, true, 5, false); node = (Node<Integer, String>)fastIterator.next(null); assertNull(node); fastIterator = tree.range(5, false, 35, false); node = (Node<Integer, String>)fastIterator.next(null); assertEquals(10, (int)node.key); node = (Node<Integer, String>)fastIterator.next(node); assertEquals(15, (int)node.key); node = (Node<Integer, String>)fastIterator.next(node); assertEquals(20, (int)node.key); node = (Node<Integer, String>)fastIterator.next(node); assertEquals(25, (int)node.key); node = (Node<Integer, String>)fastIterator.next(node); assertNull(node); }
if ( childLeftTuple != null && leftMemory.isIndexed() && !it.isFullIterator() && (leftTuple == null || (leftTuple.getMemory() != childLeftTuple.getLeftParent().getMemory())) ) { for ( ; leftTuple != null; leftTuple = (LeftTuple) it.next( leftTuple ) ) { if ( this.constraints.isAllowedCachedRight( memory.getContext(), leftTuple ) ) { for ( ; leftTuple != null; leftTuple = (LeftTuple) it.next( leftTuple ) ) { if ( this.constraints.isAllowedCachedRight( memory.getContext(), leftTuple ) ) {
@Test public void testIterator() { final int ITEMS = 10000; TupleRBTree<Integer> tree = new TupleRBTree<Integer>(); Random random = new Random(0); for (int i = 0; i < ITEMS; i++) { int key = random.nextInt(); tree.insert( key ); } int i = 0; FastIterator fastIterator = tree.fastIterator(); int lastKey = Integer.MIN_VALUE; for (Node<Integer> node = (Node<Integer>)fastIterator.next(null); node != null; node = (Node<Integer>)fastIterator.next(node)) { int currentKey = node.key; if (currentKey < lastKey) { fail(currentKey + " should be greater than " + lastKey); } lastKey = currentKey; i++; } assertEquals(ITEMS, i); } }
if ( childLeftTuple != null && rightMemory.isIndexed() && !rightIt.isFullIterator() && (rightTuple == null || (rightTuple.getMemory() != childLeftTuple.getRightParent().getMemory())) ) { for ( ; rightTuple != null; rightTuple = (RightTuple) rightIt.next( rightTuple ) ) { final InternalFactHandle handle = rightTuple.getFactHandle(); if ( this.constraints.isAllowedCachedLeft( memory.betaMemory.getContext(), boolean isDirty = false; for ( ; rightTuple != null; rightTuple = (RightTuple) rightIt.next( rightTuple ) ) { final InternalFactHandle handle = rightTuple.getFactHandle();
public Object next() { if (!firstConsumed) { firstConsumed = true; return current; } current = fastIterator.next(current); return current; } }
if ( childLeftTuple != null && leftMemory.isIndexed() && !leftIt.isFullIterator() && (leftTuple == null || (leftTuple.getMemory() != childLeftTuple.getLeftParent().getMemory())) ) { for ( ; leftTuple != null; leftTuple = ( LeftTuple ) leftIt.next( leftTuple ) ) { if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(), leftTuple ) ) { for ( ; leftTuple != null; leftTuple = (LeftTuple) leftIt.next( leftTuple ) ) { if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(), leftTuple ) ) {
public void equalsRightMemory(List<RightTuple> rightTuples) { TupleMemory rtm = bm.getRightTupleMemory(); int length = 0; for ( RightTuple expectedRightTuple : rightTuples ) { FastIterator it = betaNode.getRightIterator( rtm ); Tuple actualRightTuple = null; for ( actualRightTuple = BetaNode.getFirstTuple( rtm, it ); actualRightTuple != null; actualRightTuple = (RightTuple) it.next( actualRightTuple ) ) { if ( expectedRightTuple.equals( actualRightTuple ) ) { length++; break; } } if ( actualRightTuple == null ) { fail( "Could not find RightTuple: " + expectedRightTuple ); } } if ( rightTuples.size() != rtm.size() ) { fail( "RightTuple memory size did not match: " + length ); } }
} else { if ( rightMemory.isIndexed() && !rightIt.isFullIterator() ) { for ( RightTuple newBlocker = firstRightTuple; newBlocker != null; newBlocker = (RightTuple) rightIt.next(newBlocker) ) { if ( this.constraints.isAllowedCachedLeft( memory.getContext(), newBlocker.getFactHandle() ) ) {
public void equalsLeftMemory(List<LeftTuple> leftTuples) { TupleMemory ltm = bm.getLeftTupleMemory(); int length = 0; for ( LeftTuple expectedLeftTuple : leftTuples ) { FastIterator it = betaNode.getLeftIterator( ltm ); Tuple actualLeftTuple = null; for ( actualLeftTuple = BetaNode.getFirstTuple( ltm, it ); actualLeftTuple != null; actualLeftTuple = (LeftTuple) it.next( actualLeftTuple ) ) { if ( expectedLeftTuple.equals( actualLeftTuple ) ) { length++; break; } } if ( actualLeftTuple == null ) { fail( "Could not find LeftTuple: " + expectedLeftTuple ); } } if ( leftTuples.size() != ltm.size() ) { fail( "LeftTuple memory size did not match: " + length ); } }
} else { if ( rightMemory.isIndexed()&& !rightIt.isFullIterator() ) { for ( RightTuple newBlocker = firstRightTuple; newBlocker != null; newBlocker = (RightTuple) rightIt.next(newBlocker) ) { if ( this.constraints.isAllowedCachedLeft( memory.getContext(), newBlocker.getFactHandle() ) ) {
@Override public String toString() { FastIterator iterator = fastIterator(); StringBuilder sb = new StringBuilder("["); boolean first = true; for (Entry entry = iterator.next(null); entry != null; entry = iterator.next(null)) { if (first) { first = false; } else { sb.append(", "); } sb.append(entry); } sb.append("]"); return sb.toString(); }
public LeftTuple getFirstLeftTuple(final RightTuple rightTuple, final LeftTupleMemory memory, final PropagationContext context, final FastIterator it) { if ( !this.indexedUnificationJoin ) { return memory.getFirst( rightTuple ); } else { return (LeftTuple) it.next( null ); } }
@Override public String toString() { FastIterator iterator = fastIterator(); StringBuilder sb = new StringBuilder("["); boolean first = true; for (Entry entry = iterator.next(null); entry != null; entry = iterator.next(null)) { if (first) { first = false; } else { sb.append(", "); } sb.append(entry); } sb.append("]"); return sb.toString(); }
@SuppressWarnings("unchecked") private void unlinkCreatedHandles(final InternalWorkingMemory workingMemory, final FromMemory memory, final LeftTuple leftTuple) { Map<Object, RightTuple> matches = (Map<Object, RightTuple>) leftTuple.getObject(); FastIterator rightIt = LinkedList.fastIterator; for ( RightTuple rightTuple : matches.values() ) { for ( RightTuple current = rightTuple; current != null; ) { RightTuple next = (RightTuple) rightIt.next( current ); current.unlinkFromRightParent(); current = next; } } }
public RightTuple getFirstRightTuple(final LeftTuple leftTuple, final RightTupleMemory memory, final PropagationContext context, final FastIterator it) { if ( !this.indexedUnificationJoin ) { return memory.getFirst( leftTuple, (InternalFactHandle) context.getFactHandle(), it ); } else { return (RightTuple) it.next( null ); } }