public bool Previous(out DepthFirstSearchState previousState) { var nextNodeIndex = currentIndex; if (nextNodeIndex < 0) { previousState = default; return(false); } var currentChildIndex = nativeData.suffixMatcherGraphNodeData[nextNodeIndex + source.graphNodeMemSpace.index].myIndexInParentChildren; currentChildIndex--; nextNodeIndex = nativeData.suffixMatcherGraphNodeData[nextNodeIndex + source.graphNodeMemSpace.index].parentIndex; while (currentChildIndex >= 0) { // descend down the right-hand-side of the tree var childrenIndexing = source.ChildrenForNode(nextNodeIndex, nativeData); nextNodeIndex = nativeData.suffixMatcherChildrenDataArray[childrenIndexing.index + currentChildIndex]; //nextNode = source.nodes[nextNodeIndex]; childrenIndexing = source.ChildrenForNode(nextNodeIndex, nativeData); currentChildIndex = childrenIndexing.length - 1; } if (currentChildIndex < 0) { previousState = new DepthFirstSearchState(source, nextNodeIndex, nativeData); return(true); } previousState = default; return(false); }
public bool Next(out DepthFirstSearchState nextState) { var nextIndex = currentIndex; var indexInChildren = 0; var children = source.ChildrenForNode(nextIndex, nativeData); while (indexInChildren >= children.length && nextIndex >= 0) { var currentNode = nativeData.suffixMatcherGraphNodeData[nextIndex + source.graphNodeMemSpace.index]; var lastIndexInChildren = currentNode.myIndexInParentChildren; nextIndex = currentNode.parentIndex; children = source.ChildrenForNode(nextIndex, nativeData); indexInChildren = lastIndexInChildren + 1; } if (indexInChildren < children.length) { nextIndex = nativeData.suffixMatcherChildrenDataArray[indexInChildren + children.index]; nextState = new DepthFirstSearchState(source, nextIndex, nativeData); return(true); } nextState = default; return(false); }
public bool FindPreviousWithParent(out DepthFirstSearchState foundState, int parentNode) { foundState = this; do { var parent = foundState.GetParentIndex(); if (parent == parentNode) { return(true); } } while (foundState.Previous(out foundState) && foundState.currentIndex >= 0); return(false); }