| Modifier and Type | Class and Description |
|---|---|
| private static class | UnicodeSetStringSpan.OffsetList
Helper class for UnicodeSetStringSpan. |
| Modifier and Type | Field and Description |
|---|---|
| public static final int | |
| private boolean | all
Set up for all variants of span()? |
| pack-priv static final short | ALL_CP_CONTAINED
Special spanLength short values. |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| pack-priv static final short | LONG_SPAN
The spanLength is >=0xfe. |
| private final int | maxLength16
Maximum lengths of relevant strings. |
| public static final int | |
| private UnicodeSetStringSpan. | offsets
Span helper |
| private boolean | someRelevant
Are there strings that are not fully contained in the code point set? |
| private short[] | spanLengths
The lengths of span(), spanBack() etc. for each string. |
| private UnicodeSet | spanNotSet
Set for span(not contained). |
| private UnicodeSet | spanSet
Set for span(). |
| private ArrayList | strings
The strings of the parent set. |
| public static final int |
| Access | Constructor and Description |
|---|---|
| public | UnicodeSetStringSpan(final UnicodeSet set, final ArrayList<String> setStrings, int which)
Constructs for all variants of span(), or only for any one variant. |
| public | UnicodeSetStringSpan(final UnicodeSetStringSpan otherStringSpan, final ArrayList<String> newParentSetStrings)
Constructs a copy of an existing UnicodeSetStringSpan. |
| Modifier and Type | Method and Description |
|---|---|
| private void | addToSpanNotSet(int c)
Adds a starting or ending string character to the spanNotSet so that a character span ends before any string. |
| public boolean | |
| pack-priv static short | |
| private static boolean | |
| pack-priv static boolean | matches16CPB(CharSequence
The string to match in. s, int The start index of s. start, int The limit of the subsequence of s being spanned. limit, final String The substring to be matched in s. t, int The length of t. tlength)Compare 16-bit Unicode strings (which may be malformed UTF-16) at code point boundaries. |
| public boolean | Returns: true if strings need to be checked (call span() here), false if not (use a BMPSet for best performance).Do the strings need to be checked in span() etc.? |
| public int | Returns: the limit (exclusive end) of the spanThe string to be spanned s, int The start index that the span begins start, UnicodeSet.The span condition spanConditionSpans a string. |
| public int | Returns: the limit (exclusive end) of the spanThe string to be spanned s, int The start index that the span begins start, UnicodeSet.The span condition spanCondition,The count outCount)
Deprecated
as a consequence of
Spans a string and counts the smallest number of set elements on any path across the span.
OutputInt being deprecated.
|
| public synchronized int | Returns: The string index which starts the span (i.e. inclusive).The string to be spanned s, int length, UnicodeSet.The span condition spanConditionSpan a string backwards. |
| private synchronized int | spanContainedAndCount(CharSequence s, int start, OutputInt outCount)
Deprecated
as a consequence of
OutputInt being deprecated.
|
| private int | Returns: the limit (exclusive end) of the spanThe string to be spanned s, int The start index that the span begins start, OutputInt If not null: Receives the number of code points across the span. outCount)
Deprecated
as a consequence of
Algorithm for spanNot()==span(SpanCondition.NOT_CONTAINED)
Theoretical algorithm:
- Iterate through the string, and at each code point boundary:
+ If the code point there is in the set, then return with the current position.
OutputInt being deprecated.
|
| private int | |
| pack-priv static int | spanOne(final UnicodeSet set, CharSequence s, int start, int length)
Does the set contain the next code point? |
| pack-priv static int | |
| private synchronized int | spanWithStrings(CharSequence s, int start, int
= spanSet.span(s, start, CONTAINED) spanLimit, UnicodeSet.Synchronized method for complicated spans using the offsets. |
| ALL | back to summary |
|---|---|
| public static final int ALL | |
| all | back to summary |
|---|---|
| private boolean all Set up for all variants of span()? | |
| ALL_CP_CONTAINED | back to summary |
|---|---|
| pack-priv static final short ALL_CP_CONTAINED Special spanLength short values. (since Java has not unsigned byte type) All code points in the string are contained in the parent set. | |
| BACK | back to summary |
|---|---|
| public static final int BACK | |
| BACK_UTF16_CONTAINED | back to summary |
|---|---|
| public static final int BACK_UTF16_CONTAINED | |
| BACK_UTF16_NOT_CONTAINED | back to summary |
|---|---|
| public static final int BACK_UTF16_NOT_CONTAINED | |
| CONTAINED | back to summary |
|---|---|
| public static final int CONTAINED | |
| FWD | back to summary |
|---|---|
| public static final int FWD | |
| FWD_UTF16_CONTAINED | back to summary |
|---|---|
| public static final int FWD_UTF16_CONTAINED | |
| FWD_UTF16_NOT_CONTAINED | back to summary |
|---|---|
| public static final int FWD_UTF16_NOT_CONTAINED | |
| LONG_SPAN | back to summary |
|---|---|
| pack-priv static final short LONG_SPAN The spanLength is >=0xfe. | |
| maxLength16 | back to summary |
|---|---|
| private final int maxLength16 Maximum lengths of relevant strings. | |
| NOT_CONTAINED | back to summary |
|---|---|
| public static final int NOT_CONTAINED | |
| offsets | back to summary |
|---|---|
| private UnicodeSetStringSpan. Span helper | |
| someRelevant | back to summary |
|---|---|
| private boolean someRelevant Are there strings that are not fully contained in the code point set? | |
| spanLengths | back to summary |
|---|---|
| private short[] spanLengths The lengths of span(), spanBack() etc. for each string. | |
| spanNotSet | back to summary |
|---|---|
| private UnicodeSet spanNotSet Set for span(not contained). Same as spanSet, plus characters that start or end strings. | |
| spanSet | back to summary |
|---|---|
| private UnicodeSet spanSet Set for span(). Same as parent but without strings. | |
| strings | back to summary |
|---|---|
| private ArrayList<String> strings The strings of the parent set. | |
| WITH_COUNT | back to summary |
|---|---|
| public static final int WITH_COUNT | |
| UnicodeSetStringSpan | back to summary |
|---|---|
| public UnicodeSetStringSpan(final UnicodeSet set, final ArrayList<String> setStrings, int which) Constructs for all variants of span(), or only for any one variant. Initializes as little as possible, for single use. | |
| UnicodeSetStringSpan | back to summary |
|---|---|
| public UnicodeSetStringSpan(final UnicodeSetStringSpan otherStringSpan, final ArrayList<String> newParentSetStrings) Constructs a copy of an existing UnicodeSetStringSpan. Assumes which==ALL for a frozen set. | |
| addToSpanNotSet | back to summary |
|---|---|
| private void addToSpanNotSet(int c) Adds a starting or ending string character to the spanNotSet so that a character span ends before any string. | |
| contains | back to summary |
|---|---|
| public boolean contains(int c) For fast UnicodeSet::contains(c). | |
| makeSpanLengthByte | back to summary |
|---|---|
| pack-priv static short makeSpanLengthByte(int spanLength) | |
| matches16 | back to summary |
|---|---|
| private static boolean matches16(CharSequence s, int start, final String t, int length) | |
| matches16CPB | back to summary |
|---|---|
| pack-priv static boolean matches16CPB(CharSequence s, int start, int limit, final String t, int tlength) Compare 16-bit Unicode strings (which may be malformed UTF-16) at code point boundaries. That is, each edge of a match must not be in the middle of a surrogate pair.
| |
| needsStringSpanUTF16 | back to summary |
|---|---|
| public boolean needsStringSpanUTF16() Do the strings need to be checked in span() etc.?
| |
| span | back to summary |
|---|---|
| public int span(CharSequence s, int start, UnicodeSet. Spans a string.
| |
| spanAndCount | back to summary |
|---|---|
| public int spanAndCount(CharSequence s, int start, UnicodeSet. Deprecated as a consequence of Spans a string and counts the smallest number of set elements on any path across the span. For proper counting, we cannot ignore strings that are fully contained in code point spans. If the set does not have any fully-contained strings, then we could optimize this like span(), but such sets are likely rare, and this is at least still linear.
| |
| spanBack | back to summary |
|---|---|
| public synchronized int spanBack(CharSequence s, int length, UnicodeSet. Span a string backwards.
| |
| spanContainedAndCount | back to summary |
|---|---|
| private synchronized int spanContainedAndCount(CharSequence s, int start, OutputInt outCount)
Deprecated as a consequence of | |
| spanNot | back to summary |
|---|---|
| private int spanNot(CharSequence s, int start, OutputInt outCount)
Deprecated as a consequence of Algorithm for spanNot()==span(SpanCondition.NOT_CONTAINED) Theoretical algorithm: - Iterate through the string, and at each code point boundary: + If the code point there is in the set, then return with the current position. + If a set string matches at the current position, then return with the current position. Optimized implementation: (Same assumption as for span() above.) Create and cache a spanNotSet which contains all of the single code points of the original set but none of its strings. For each set string add its initial code point to the spanNotSet. (Also add its final code point for spanNotBack().) - Loop: + Do spanLength=spanNotSet.span(SpanCondition.NOT_CONTAINED). + If the current code point is in the original set, then return the current position. + If any set string matches at the current position, then return the current position. + If there is no match at the current position, neither for the code point there nor for any set string, then skip this code point and continue the loop. This happens for set-string-initial code points that were added to spanNotSet when there is not actually a match for such a set string.
| |
| spanNotBack | back to summary |
|---|---|
| private int spanNotBack(CharSequence s, int length) | |
| spanOne | back to summary |
|---|---|
| pack-priv static int spanOne(final UnicodeSet set, CharSequence s, int start, int length) Does the set contain the next code point? If so, return its length; otherwise return its negative length. | |
| spanOneBack | back to summary |
|---|---|
| pack-priv static int spanOneBack(final UnicodeSet set, CharSequence s, int length) | |
| spanWithStrings | back to summary |
|---|---|
| private synchronized int spanWithStrings(CharSequence s, int start, int spanLimit, UnicodeSet. Synchronized method for complicated spans using the offsets. Avoids synchronization for simple cases.
| |
List of offsets from the current position from where to try matching a code point or a string. Stores offsets rather than indexes to simplify the code and use the same list for both increments (in span()) and decrements (in spanBack()).
Assumption: The maximum offset is limited, and the offsets that are stored at any one time are relatively dense, that is, there are normally no gaps of hundreds or thousands of offset values.
This class optionally also tracks the minimum non-negative count for each position, intended to count the smallest number of elements of any path leading to that position.
The implementation uses a circular buffer of count integers, each indicating whether the corresponding offset is in the list, and its path element count. This avoids inserting into a sorted list of offsets (or absolute indexes) and physically moving part of the list.
Note
In principle, the caller should setMaxLength() to the maximum of the max string length and U16_LENGTH/U8_LENGTH to account for "long" single code points.
Note
An earlier version did not track counts and stored only byte flags. With boolean flags, if maxLength were guaranteed to be no more than 32 or 64, the list could be stored as bit flags in a single integer. Rather than handling a circular buffer with a start list index, the integer would simply be shifted when lower offsets are removed. UnicodeSet does not have a limit on the lengths of strings.
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private int[] | |
| private int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public void | |
| public boolean | |
| public boolean | |
| public boolean | |
| public int | Returns: min=[1..maxLength]
Deprecated
as a consequence of
Finds the lowest stored offset from a non-empty list, removes it,
and reduces all other offsets by this minimum.
OutputInt being deprecated.
|
| public void | |
| public void | shift(int
[1..maxLength] delta)Reduces all stored offsets by delta, used when the current position moves by delta. |
| length | back to summary |
|---|---|
| private int length | |
| list | back to summary |
|---|---|
| private int[] list | |
| start | back to summary |
|---|---|
| private int start | |
| OffsetList | back to summary |
|---|---|
| public OffsetList() | |
| addOffset | back to summary |
|---|---|
| public void addOffset(int offset) Adds an offset. The list must not contain it yet.
| |
| addOffsetAndCount | back to summary |
|---|---|
| public void addOffsetAndCount(int offset, int count) Adds an offset and updates its count. The list may already contain the offset.
| |
| clear | back to summary |
|---|---|
| public void clear() | |
| containsOffset | back to summary |
|---|---|
public boolean containsOffset(int offset)
| |
| hasCountAtOffset | back to summary |
|---|---|
public boolean hasCountAtOffset(int offset, int count)
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() | |
| popMinimum | back to summary |
|---|---|
| public int popMinimum(OutputInt outCount)
Deprecated as a consequence of Finds the lowest stored offset from a non-empty list, removes it, and reduces all other offsets by this minimum.
| |
| setMaxLength | back to summary |
|---|---|
| public void setMaxLength(int maxLength) | |
| shift | back to summary |
|---|---|
| public void shift(int delta) Reduces all stored offsets by delta, used when the current position moves by delta. There must not be any offsets lower than delta. If there is an offset equal to delta, it is removed.
| |