-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Push and pop OutputAccumulator as IntersectTermsEnumFrames are pushed and popped #12900
Changes from all commits
26e166c
722a96b
85f8c96
fe1e0fe
eba6fe6
2e33baf
e387ec9
f00f604
bf54d6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,8 @@ public IntersectTermsEnum( | |
assert setSavedStartTerm(startTerm); | ||
|
||
currentFrame = f; | ||
outputAccumulator.push(currentFrame.arc.output()); | ||
|
||
if (startTerm != null) { | ||
seekToStartTerm(startTerm); | ||
} | ||
|
@@ -184,8 +186,7 @@ private IntersectTermsEnumFrame pushFrame(int state) throws IOException { | |
int idx = currentFrame.prefix; | ||
assert currentFrame.suffix > 0; | ||
|
||
outputAccumulator.reset(); | ||
outputAccumulator.push(arc.output()); | ||
int initOutputCount = outputAccumulator.outputCount(); | ||
while (idx < f.prefix) { | ||
final int target = term.bytes[idx] & 0xff; | ||
// TODO: we could be more efficient for the next() | ||
|
@@ -198,9 +199,11 @@ private IntersectTermsEnumFrame pushFrame(int state) throws IOException { | |
} | ||
|
||
f.arc = arc; | ||
f.outputNum = outputAccumulator.outputCount() - initOutputCount; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK we need this because a single frame might traverse multiple FST arcs, so we need to accumulate possibly / often more than one output. |
||
assert arc.isFinal(); | ||
outputAccumulator.push(arc.nextFinalOutput()); | ||
f.load(outputAccumulator); | ||
outputAccumulator.pop(arc.nextFinalOutput()); | ||
return f; | ||
} | ||
|
||
|
@@ -343,6 +346,7 @@ private boolean popPushNext() throws IOException { | |
throw NoMoreTermsException.INSTANCE; | ||
} | ||
final long lastFP = currentFrame.fpOrig; | ||
outputAccumulator.pop(currentFrame.outputNum); | ||
currentFrame = stack[currentFrame.ord - 1]; | ||
currentTransition = currentFrame.transition; | ||
assert currentFrame.lastSubFP == lastFP; | ||
|
@@ -429,6 +433,7 @@ private BytesRef _next() throws IOException { | |
currentFrame = null; | ||
return null; | ||
} | ||
outputAccumulator.pop(currentFrame.outputNum); | ||
currentFrame = stack[currentFrame.ord - 1]; | ||
currentTransition = currentFrame.transition; | ||
isSubBlock = popPushNext(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -495,7 +495,7 @@ public boolean seekExact(BytesRef target) throws IOException { | |
targetUpto = 0; | ||
outputAccumulator.push(arc.nextFinalOutput()); | ||
currentFrame = pushFrame(arc, 0); | ||
outputAccumulator.pop(); | ||
outputAccumulator.pop(arc.nextFinalOutput()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like another potential bug : If Not sure why we have not seen any bug report for this. Maybe our output format protect it implicitly? This is in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! And the new check you added in But I also think this was (luckily!?) not a bug, because this case is when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the other places where we "blindly" pop are fine -- we conditionalize by |
||
} | ||
|
||
// if (DEBUG) { | ||
|
@@ -569,7 +569,7 @@ public boolean seekExact(BytesRef target) throws IOException { | |
// if (DEBUG) System.out.println(" arc is final!"); | ||
outputAccumulator.push(arc.nextFinalOutput()); | ||
currentFrame = pushFrame(arc, targetUpto); | ||
outputAccumulator.pop(); | ||
outputAccumulator.pop(arc.nextFinalOutput()); | ||
// if (DEBUG) System.out.println(" curFrame.ord=" + currentFrame.ord + " hasTerms=" + | ||
// currentFrame.hasTerms); | ||
} | ||
|
@@ -767,7 +767,7 @@ public SeekStatus seekCeil(BytesRef target) throws IOException { | |
targetUpto = 0; | ||
outputAccumulator.push(arc.nextFinalOutput()); | ||
currentFrame = pushFrame(arc, 0); | ||
outputAccumulator.pop(); | ||
outputAccumulator.pop(arc.nextFinalOutput()); | ||
} | ||
|
||
// if (DEBUG) { | ||
|
@@ -841,7 +841,7 @@ public SeekStatus seekCeil(BytesRef target) throws IOException { | |
// if (DEBUG) System.out.println(" arc is final!"); | ||
outputAccumulator.push(arc.nextFinalOutput()); | ||
currentFrame = pushFrame(arc, targetUpto); | ||
outputAccumulator.pop(); | ||
outputAccumulator.pop(arc.nextFinalOutput()); | ||
// if (DEBUG) System.out.println(" curFrame.ord=" + currentFrame.ord + " hasTerms=" + | ||
// currentFrame.hasTerms); | ||
} | ||
|
@@ -1187,14 +1187,27 @@ static class OutputAccumulator extends DataInput { | |
|
||
void push(BytesRef output) { | ||
if (output != Lucene90BlockTreeTermsReader.NO_OUTPUT) { | ||
assert output.length > 0; | ||
outputs = ArrayUtil.grow(outputs, num + 1); | ||
outputs[num++] = output; | ||
} | ||
} | ||
|
||
void pop() { | ||
assert num > 0; | ||
num--; | ||
void pop(BytesRef output) { | ||
if (output != Lucene90BlockTreeTermsReader.NO_OUTPUT) { | ||
assert num > 0; | ||
assert outputs[num - 1] == output; | ||
num--; | ||
} | ||
} | ||
|
||
void pop(int cnt) { | ||
assert num >= cnt; | ||
num -= cnt; | ||
} | ||
|
||
int outputCount() { | ||
return num; | ||
} | ||
|
||
void reset() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay :)