@Test public void prune() throws Exception { Node<InvariantSpan> a = new Node<>(new InvariantSpan(300, 4, documentHash)); Node<InvariantSpan> b = new Node<>(new InvariantSpan(350, 1, documentHash)); Node<InvariantSpan> c = new Node<>(new InvariantSpan(360, 1, documentHash)); Node<InvariantSpan> d = new Node<>(new InvariantSpan(361, 5, documentHash)); d.tag = "d"; Node<InvariantSpan> cd = new Node.Builder<InvariantSpan>(1).left(c).right(d).tag("cd").build(); Node<InvariantSpan> bcd = new Node.Builder<InvariantSpan>(1).left(b).right(cd).tag("bcd").build(); Node<InvariantSpan> abcd = new Node.Builder<InvariantSpan>(4).left(a).right(bcd).tag("abcd").build(); NodeIndex<InvariantSpan> cIndex = RopeUtils.index(6, abcd, 0); List<Node<InvariantSpan>> orphans = Partitioner.pruneIndexNode(cIndex.node, 6, cIndex.displacement); assertEquals(1, orphans.size()); assertEquals("d", orphans.get(0).tag); }
public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } }
Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } } }
Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } }  }
Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } }  static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
			long displacement); }
Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.parent.isRed = false; } return pruneTree(indexNode.parent.parent, 0, leftPartitionWidth, displacement, indexNode.parent.parent.isRightNode()); } return new ArrayList<>(); } else { return pruneTree(indexNode.parent, 0, leftPartitionWidth, displacement, true); } }  static NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x); static List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth,
			long displacement);  }