Top Inners Fields Constructors Methods
com.ibm.icu.impl

public Class UnicodeSetStringSpan

extends Object
Class Inheritance
Imports
java.util.ArrayList, com.ibm.icu.text.UnicodeSet, .UnicodeSet.SpanCondition, com.ibm.icu.util.OutputInt

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
UnicodeSetStringSpan.OffsetList

Helper class for UnicodeSetStringSpan.

Field Summary

Modifier and TypeField 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.OffsetList
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<String>
strings

The strings of the parent set.

public static final int

Constructor Summary

AccessConstructor 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.

Method Summary

Modifier and TypeMethod 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
contains(int c)

For fast UnicodeSet::contains(c).

pack-priv static short
makeSpanLengthByte(int spanLength)

private static boolean
matches16(CharSequence s, int start, final String t, int length)

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).
needsStringSpanUTF16
()

Do the strings need to be checked in span() etc.?

public int

Returns:

the limit (exclusive end) of the span
span
(CharSequence
The string to be spanned
s
,
int
The start index that the span begins
start
,
UnicodeSet.SpanCondition
The span condition
spanCondition
)

Spans a string.

public int

Returns:

the limit (exclusive end) of the span
spanAndCount
(CharSequence
The string to be spanned
s
,
int
The start index that the span begins
start
,
UnicodeSet.SpanCondition
The span condition
spanCondition
,
OutputInt
The count
outCount
)

Deprecated as a consequence of OutputInt being deprecated.
Spans a string and counts the smallest number of set elements on any path across the span.
public synchronized int

Returns:

The string index which starts the span (i.e. inclusive).
spanBack
(CharSequence
The string to be spanned
s
,
int length, UnicodeSet.SpanCondition
The span condition
spanCondition
)

Span 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 span
spanNot
(CharSequence
The 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 OutputInt being deprecated.
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.
private int
spanNotBack(CharSequence s, int length)

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
spanOneBack(final UnicodeSet set, CharSequence s, int length)

private synchronized int
spanWithStrings(CharSequence s, int start, int
= spanSet.span(s, start, CONTAINED)
spanLimit
,
UnicodeSet.SpanCondition spanCondition)

Synchronized method for complicated spans using the offsets.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALLback to summary
public static final int ALL
allback to summary
private boolean all

Set up for all variants of span()?

ALL_CP_CONTAINEDback 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.

BACKback to summary
public static final int BACK
BACK_UTF16_CONTAINEDback to summary
public static final int BACK_UTF16_CONTAINED
BACK_UTF16_NOT_CONTAINEDback to summary
public static final int BACK_UTF16_NOT_CONTAINED
CONTAINEDback to summary
public static final int CONTAINED
FWDback to summary
public static final int FWD
FWD_UTF16_CONTAINEDback to summary
public static final int FWD_UTF16_CONTAINED
FWD_UTF16_NOT_CONTAINEDback to summary
public static final int FWD_UTF16_NOT_CONTAINED
LONG_SPANback to summary
pack-priv static final short LONG_SPAN

The spanLength is >=0xfe.

maxLength16back to summary
private final int maxLength16

Maximum lengths of relevant strings.

NOT_CONTAINEDback to summary
public static final int NOT_CONTAINED
offsetsback to summary
private UnicodeSetStringSpan.OffsetList offsets

Span helper

someRelevantback to summary
private boolean someRelevant

Are there strings that are not fully contained in the code point set?

spanLengthsback to summary
private short[] spanLengths

The lengths of span(), spanBack() etc. for each string.

spanNotSetback to summary
private UnicodeSet spanNotSet

Set for span(not contained). Same as spanSet, plus characters that start or end strings.

spanSetback to summary
private UnicodeSet spanSet

Set for span(). Same as parent but without strings.

stringsback to summary
private ArrayList<String> strings

The strings of the parent set.

WITH_COUNTback to summary
public static final int WITH_COUNT

Constructor Detail

UnicodeSetStringSpanback 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.

UnicodeSetStringSpanback 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.

Method Detail

addToSpanNotSetback 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.

containsback to summary
public boolean contains(int c)

For fast UnicodeSet::contains(c).

makeSpanLengthByteback to summary
pack-priv static short makeSpanLengthByte(int spanLength)
matches16back to summary
private static boolean matches16(CharSequence s, int start, final String t, int length)
matches16CPBback 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.

Parameters
s:CharSequence

The string to match in.

start:int

The start index of s.

limit:int

The limit of the subsequence of s being spanned.

t:String

The substring to be matched in s.

tlength:int

The length of t.

needsStringSpanUTF16back to summary
public boolean needsStringSpanUTF16()

Do the strings need to be checked in span() etc.?

Returns:boolean

true if strings need to be checked (call span() here), false if not (use a BMPSet for best performance).

spanback to summary
public int span(CharSequence s, int start, UnicodeSet.SpanCondition spanCondition)

Spans a string.

Parameters
s:CharSequence

The string to be spanned

start:int

The start index that the span begins

spanCondition:UnicodeSet.SpanCondition

The span condition

Returns:int

the limit (exclusive end) of the span

spanAndCountback to summary
public int spanAndCount(CharSequence s, int start, UnicodeSet.SpanCondition spanCondition, OutputInt outCount)

Deprecated

as a consequence of OutputInt being deprecated. See corresponding docs for further information.

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.

Parameters
s:CharSequence

The string to be spanned

start:int

The start index that the span begins

spanCondition:UnicodeSet.SpanCondition

The span condition

outCount:OutputInt

The count

Returns:int

the limit (exclusive end) of the span

spanBackback to summary
public synchronized int spanBack(CharSequence s, int length, UnicodeSet.SpanCondition spanCondition)

Span a string backwards.

Parameters
s:CharSequence

The string to be spanned

spanCondition:UnicodeSet.SpanCondition

The span condition

Returns:int

The string index which starts the span (i.e. inclusive).

spanContainedAndCountback to summary
private synchronized int spanContainedAndCount(CharSequence s, int start, OutputInt outCount)

Deprecated

as a consequence of OutputInt being deprecated. See corresponding docs for further information.

spanNotback to summary
private int spanNot(CharSequence s, int start, OutputInt outCount)

Deprecated

as a consequence of OutputInt being deprecated. See corresponding docs for further information.

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.

Parameters
s:CharSequence

The string to be spanned

start:int

The start index that the span begins

outCount:OutputInt

If not null: Receives the number of code points across the span.

Returns:int

the limit (exclusive end) of the span

spanNotBackback to summary
private int spanNotBack(CharSequence s, int length)
spanOneback 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.

spanOneBackback to summary
pack-priv static int spanOneBack(final UnicodeSet set, CharSequence s, int length)
spanWithStringsback to summary
private synchronized int spanWithStrings(CharSequence s, int start, int spanLimit, UnicodeSet.SpanCondition spanCondition)

Synchronized method for complicated spans using the offsets. Avoids synchronization for simple cases.

Parameters
spanLimit:int

= spanSet.span(s, start, CONTAINED)

com.ibm.icu.impl back to summary

private final Class UnicodeSetStringSpan.OffsetList

extends Object
Class Inheritance

Helper class for UnicodeSetStringSpan.

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.

Field Summary

Modifier and TypeField and Description
private int
private int[]
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addOffset(int
[1..maxLength]
offset
)

Adds an offset.

public void
addOffsetAndCount(int
[1..maxLength]
offset
,
int count)

Adds an offset and updates its count.

public void
public boolean
containsOffset(int
[1..maxLength]
offset
)

public boolean
hasCountAtOffset(int
[1..maxLength]
offset
,
int count)

public boolean
public int

Returns:

min=[1..maxLength]
popMinimum
(OutputInt outCount)

Deprecated as a consequence of OutputInt being deprecated.
Finds the lowest stored offset from a non-empty list, removes it, and reduces all other offsets by this minimum.
public void
setMaxLength(int maxLength)

public void
shift(int
[1..maxLength]
delta
)

Reduces all stored offsets by delta, used when the current position moves by delta.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lengthback to summary
private int length
listback to summary
private int[] list
startback to summary
private int start

Constructor Detail

OffsetListback to summary
public OffsetList()

Method Detail

addOffsetback to summary
public void addOffset(int offset)

Adds an offset. The list must not contain it yet.

Parameters
offset:int

[1..maxLength]

addOffsetAndCountback to summary
public void addOffsetAndCount(int offset, int count)

Adds an offset and updates its count. The list may already contain the offset.

Parameters
offset:int

[1..maxLength]

clearback to summary
public void clear()
containsOffsetback to summary
public boolean containsOffset(int offset)
Parameters
offset:int

[1..maxLength]

hasCountAtOffsetback to summary
public boolean hasCountAtOffset(int offset, int count)
Parameters
offset:int

[1..maxLength]

isEmptyback to summary
public boolean isEmpty()
popMinimumback to summary
public int popMinimum(OutputInt outCount)

Deprecated

as a consequence of OutputInt being deprecated. See corresponding docs for further information.

Finds the lowest stored offset from a non-empty list, removes it, and reduces all other offsets by this minimum.

Returns:int

min=[1..maxLength]

setMaxLengthback to summary
public void setMaxLength(int maxLength)
shiftback 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.

Parameters
delta:int

[1..maxLength]