-
Notifications
You must be signed in to change notification settings - Fork 1.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
Add "direct to binary" option for DaciukMihovAutomatonBuilder and use it in TermInSetQuery#visit #12320
Merged
Merged
Add "direct to binary" option for DaciukMihovAutomatonBuilder and use it in TermInSetQuery#visit #12320
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0365857
Add "direct to binary" option for DaciukMihovAutomatonBuilder and use…
gsmiller 681f384
plumb through Automata
gsmiller 3163d4d
little more cleanup
gsmiller e7ce7e3
test basic minimization
gsmiller 84061ee
addressing some feedback
gsmiller 485ebc8
fixup rebase
gsmiller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -477,38 +477,59 @@ public static int UTF8toUTF32(final BytesRef utf8, final int[] ints) { | |
int utf8Upto = utf8.offset; | ||
final byte[] bytes = utf8.bytes; | ||
final int utf8Limit = utf8.offset + utf8.length; | ||
UTF8CodePoint reuse = null; | ||
while (utf8Upto < utf8Limit) { | ||
final int numBytes = utf8CodeLength[bytes[utf8Upto] & 0xFF]; | ||
int v = 0; | ||
switch (numBytes) { | ||
case 1: | ||
ints[utf32Count++] = bytes[utf8Upto++]; | ||
continue; | ||
case 2: | ||
// 5 useful bits | ||
v = bytes[utf8Upto++] & 31; | ||
break; | ||
case 3: | ||
// 4 useful bits | ||
v = bytes[utf8Upto++] & 15; | ||
break; | ||
case 4: | ||
// 3 useful bits | ||
v = bytes[utf8Upto++] & 7; | ||
break; | ||
default: | ||
throw new IllegalArgumentException("invalid utf8"); | ||
} | ||
reuse = codePointAt(bytes, utf8Upto, reuse); | ||
ints[utf32Count++] = reuse.codePoint; | ||
utf8Upto += reuse.numBytes; | ||
} | ||
|
||
return utf32Count; | ||
} | ||
|
||
// TODO: this may read past utf8's limit. | ||
final int limit = utf8Upto + numBytes - 1; | ||
while (utf8Upto < limit) { | ||
v = v << 6 | bytes[utf8Upto++] & 63; | ||
/** | ||
* Computes the codepoint and codepoint length (in bytes) of the specified {@code offset} in the | ||
* provided {@code utf8} byte array, assuming UTF8 encoding. As with other related methods in this | ||
* class, this assumes valid UTF8 input and <strong>does not perform</strong> full UTF8 | ||
* validation. Passing invalid UTF8 or a position that is not a valid header byte position may | ||
* result in undefined behavior. This makes no attempt to synchronize or validate. | ||
*/ | ||
public static UTF8CodePoint codePointAt(byte[] utf8, int pos, UTF8CodePoint reuse) { | ||
if (reuse == null) { | ||
reuse = new UTF8CodePoint(); | ||
} | ||
|
||
int leadByte = utf8[pos] & 0xFF; | ||
int numBytes = utf8CodeLength[leadByte]; | ||
reuse.numBytes = numBytes; | ||
int v; | ||
switch (numBytes) { | ||
case 1 -> { | ||
reuse.codePoint = leadByte; | ||
return reuse; | ||
} | ||
ints[utf32Count++] = v; | ||
case 2 -> v = leadByte & 31; // 5 useful bits | ||
case 3 -> v = leadByte & 15; // 4 useful bits | ||
case 4 -> v = leadByte & 7; // 3 useful bits | ||
default -> throw new IllegalArgumentException( | ||
"Invalid UTF8 header byte: 0x" + Integer.toHexString(leadByte)); | ||
} | ||
|
||
return utf32Count; | ||
// TODO: this may read past utf8's limit. | ||
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. Ahh yes another |
||
final int limit = pos + numBytes; | ||
pos++; | ||
while (pos < limit) { | ||
v = v << 6 | utf8[pos++] & 63; | ||
} | ||
reuse.codePoint = v; | ||
|
||
return reuse; | ||
} | ||
|
||
/** Holds a codepoint along with the number of bytes required to represent it in UTF8 */ | ||
public static final class UTF8CodePoint { | ||
public int codePoint; | ||
public int numBytes; | ||
} | ||
|
||
/** Shift value for lead surrogate to form a supplementary character. */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Kept the old name here since I'm proposing this change for 9.x (and the rename will come in 10)