/** * Verifies that the tree is in a valid shape. * * @throws IllegalStateException for invalid trees. */ public void verifyTreeIntegrity() { BitSet seen = new BitSet(capacity); for (int child : children) { if (child != INVALID_NODE) { if (seen.getAndSet(child)) { throw new IllegalStateException("node (" + child + ") has multiple parents"); } } } for (int sibling : siblings) { if (sibling != INVALID_NODE) { if (seen.getAndSet(sibling)) { throw new IllegalStateException("node (" + sibling + ") has multiple parents"); } } } }
/** * Verifies that the tree is in a valid shape. * * @throws IllegalStateException for invalid trees. */ public void verifyTreeIntegrity() { BitSet seen = new BitSet(capacity); for (int child : children) { if (child != INVALID_NODE) { if (seen.getAndSet(child)) { throw new IllegalStateException("node (" + child + ") has multiple parents"); } } } for (int sibling : siblings) { if (sibling != INVALID_NODE) { if (seen.getAndSet(sibling)) { throw new IllegalStateException("node (" + sibling + ") has multiple parents"); } } } }
private void iterateBFS(int startNode, RelationshipConsumer consumer) { IntArrayDeque queue = new IntArrayDeque(); BitSet seen = new BitSet(capacity); queue.addFirst(startNode); while (!queue.isEmpty()) { int node = queue.removeFirst(); int child = children[node]; if (child != INVALID_NODE) { do { if (!seen.getAndSet(child)) { queue.addLast(child); } if (!consumer.accept( node, child, RELATION_ID_NOT_SUPPORTED)) { return; } } while ((child = siblings[child]) != INVALID_NODE); } } }
private void iterateBFS(int startNode, RelationshipConsumer consumer) { IntArrayDeque queue = new IntArrayDeque(); BitSet seen = new BitSet(capacity); queue.addFirst(startNode); while (!queue.isEmpty()) { int node = queue.removeFirst(); int child = children[node]; if (child != INVALID_NODE) { do { if (!seen.getAndSet(child)) { queue.addLast(child); } if (!consumer.accept( node, child, RELATION_ID_NOT_SUPPORTED)) { return; } } while ((child = siblings[child]) != INVALID_NODE); } } }