public class SegmentTree extends Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
SegmentTree.SegmentTreeData |
| Modifier and Type | Field and Description |
|---|---|
static int |
F_ANCHOR_FLAGS |
static int |
MAX_VALUE |
protected byte[] |
segmentBytes |
protected int[] |
treeData |
| Modifier | Constructor and Description |
|---|---|
protected |
SegmentTree(int[] treeData,
byte[] segmentBytes) |
| Modifier and Type | Method and Description |
|---|---|
void |
addSegments(@NotNull IBasedSegmentBuilder<?> builder,
int startIndex,
int endIndex,
int startOffset,
int endOffset,
int startPos,
int endPos)
Add segments of subsequence of this tree to builder
|
void |
addSegments(@NotNull IBasedSegmentBuilder<?> builder,
@NotNull SegmentTreeRange treeRange)
Add segments selected by given treeRange
|
int |
aggrLength(int pos) |
static int |
aggrLength(int pos,
int[] treeData) |
static @NotNull SegmentTree |
build(@NotNull BasedSegmentBuilder builder) |
static @NotNull SegmentTree |
build(@NotNull Iterable<Seg> segments,
@NotNull CharSequence allText) |
static @NotNull SegmentTree.SegmentTreeData |
buildTreeData(@NotNull Iterable<Seg> segments,
@NotNull CharSequence allText,
boolean buildIndexData)
Build binary tree search data
|
int |
byteOffset(int pos) |
static int |
byteOffset(int pos,
int[] treeData) |
int |
byteOffsetData(int pos) |
static int |
byteOffsetData(int pos,
int[] treeData) |
@Nullable Segment |
findSegment(int index,
@NotNull BasedSequence baseSeq,
@Nullable Segment hint) |
static @Nullable Segment |
findSegment(int index,
int[] treeData,
int startPos,
int endPos,
byte[] segmentBytes,
@NotNull BasedSequence baseSeq) |
@Nullable Segment |
findSegment(int index,
int startPos,
int endPos,
@NotNull BasedSequence baseSeq,
@Nullable Segment hint) |
@Nullable SegmentTreePos |
findSegmentPos(int index) |
static @Nullable SegmentTreePos |
findSegmentPos(int index,
int[] treeData,
int startPos,
int endPos) |
@Nullable SegmentTreePos |
findSegmentPos(int index,
int startPos,
int endPos) |
static int |
getAnchorOffset(int byteOffsetData) |
static int |
getByteOffset(int byteOffsetData) |
static @NotNull CharSequence |
getCharSequence(@NotNull Segment segment,
int startIndex,
int endIndex,
int startPos,
int endPos)
Get char sequence of segment corresponding to sub-sequence in segment tree
|
@Nullable Segment |
getPrevAnchor(int pos,
@NotNull BasedSequence baseSeq) |
static @Nullable Segment |
getPrevAnchor(int pos,
int[] treeData,
byte[] segmentBytes,
@NotNull BasedSequence baseSeq) |
@NotNull Segment |
getSegment(int pos,
@NotNull BasedSequence baseSeq) |
static @NotNull Segment |
getSegment(int pos,
int[] treeData,
byte[] segmentBytes,
@NotNull BasedSequence baseSeq) |
@NotNull Segment |
getSegment(int byteOffset,
int pos,
int startIndex,
@NotNull BasedSequence baseSeq) |
byte[] |
getSegmentBytes() |
@NotNull SegmentOffsetTree |
getSegmentOffsetTree(@NotNull BasedSequence baseSeq)
Build an offset segment tree from this index segment tree
|
@NotNull SegmentTreeRange |
getSegmentRange(int startIndex,
int endIndex,
int startPos,
int endPos,
@NotNull BasedSequence baseSequence,
@Nullable Segment hint) |
int |
getTextEndOffset(Segment segment,
@NotNull BasedSequence baseSequence) |
int |
getTextStartOffset(Segment segment,
@NotNull BasedSequence baseSequence) |
int[] |
getTreeData() |
boolean |
hasPreviousAnchor(int pos) |
static boolean |
hasPreviousAnchor(int pos,
int[] treeData) |
int |
previousAnchorOffset(int pos) |
static int |
previousAnchorOffset(int pos,
int[] treeData) |
static void |
setTreeData(int pos,
int[] treeData,
int agrrLength,
int byteOffset,
int prevAnchorOffset) |
int |
size() |
@NotNull String |
toString() |
@NotNull String |
toString(@NotNull BasedSequence baseSeq) |
public static final int MAX_VALUE
public static final int F_ANCHOR_FLAGS
protected final int[] treeData
protected final byte[] segmentBytes
public int[] getTreeData()
public byte[] getSegmentBytes()
public int size()
public int aggrLength(int pos)
public int byteOffsetData(int pos)
public int byteOffset(int pos)
public static int getByteOffset(int byteOffsetData)
public static int getAnchorOffset(int byteOffsetData)
public boolean hasPreviousAnchor(int pos)
public int previousAnchorOffset(int pos)
@Nullable public @Nullable SegmentTreePos findSegmentPos(int index)
@NotNull public @NotNull Segment getSegment(int byteOffset, int pos, int startIndex, @NotNull @NotNull BasedSequence baseSeq)
@Nullable public @Nullable Segment findSegment(int index, @NotNull @NotNull BasedSequence baseSeq, @Nullable @Nullable Segment hint)
@Nullable public @Nullable Segment findSegment(int index, int startPos, int endPos, @NotNull @NotNull BasedSequence baseSeq, @Nullable @Nullable Segment hint)
@NotNull public @NotNull SegmentTreeRange getSegmentRange(int startIndex, int endIndex, int startPos, int endPos, @NotNull @NotNull BasedSequence baseSequence, @Nullable @Nullable Segment hint)
public int getTextEndOffset(Segment segment, @NotNull @NotNull BasedSequence baseSequence)
public int getTextStartOffset(Segment segment, @NotNull @NotNull BasedSequence baseSequence)
public void addSegments(@NotNull
@NotNull IBasedSegmentBuilder<?> builder,
@NotNull
@NotNull SegmentTreeRange treeRange)
builder - based segment buildertreeRange - treeRange for which to add segmentspublic void addSegments(@NotNull
@NotNull IBasedSegmentBuilder<?> builder,
int startIndex,
int endIndex,
int startOffset,
int endOffset,
int startPos,
int endPos)
builder - builder to which to add the segmentsstartIndex - start index of sub-sequence of segment treeendIndex - end index of sub-sequence of segment treestartOffset - start offset of the subsequence to use as start anchorendOffset - end offset of the subsequence to use as end anchorstartPos - start pos of sub-sequence segments in treeendPos - end pos of sub-sequence segments in tree@NotNull public static @NotNull CharSequence getCharSequence(@NotNull @NotNull Segment segment, int startIndex, int endIndex, int startPos, int endPos)
segment - segmentstartIndex - start index of sub-sequence of segment treeendIndex - end index of sub-sequence of segment treestartPos - start pos of sub-sequence segments in treeendPos - end pos of sub-sequence segments in tree@Nullable public @Nullable SegmentTreePos findSegmentPos(int index, int startPos, int endPos)
@NotNull public @NotNull Segment getSegment(int pos, @NotNull @NotNull BasedSequence baseSeq)
@Nullable public @Nullable Segment getPrevAnchor(int pos, @NotNull @NotNull BasedSequence baseSeq)
@NotNull public @NotNull String toString(@NotNull @NotNull BasedSequence baseSeq)
public static int aggrLength(int pos,
int[] treeData)
public static int byteOffsetData(int pos,
int[] treeData)
public static int byteOffset(int pos,
int[] treeData)
public static void setTreeData(int pos,
int[] treeData,
int agrrLength,
int byteOffset,
int prevAnchorOffset)
public static boolean hasPreviousAnchor(int pos,
int[] treeData)
public static int previousAnchorOffset(int pos,
int[] treeData)
@Nullable public static @Nullable SegmentTreePos findSegmentPos(int index, int[] treeData, int startPos, int endPos)
@Nullable public static @Nullable Segment findSegment(int index, int[] treeData, int startPos, int endPos, byte[] segmentBytes, @NotNull @NotNull BasedSequence baseSeq)
@NotNull public static @NotNull Segment getSegment(int pos, int[] treeData, byte[] segmentBytes, @NotNull @NotNull BasedSequence baseSeq)
@Nullable public static @Nullable Segment getPrevAnchor(int pos, int[] treeData, byte[] segmentBytes, @NotNull @NotNull BasedSequence baseSeq)
@NotNull public static @NotNull SegmentTree build(@NotNull @NotNull Iterable<Seg> segments, @NotNull @NotNull CharSequence allText)
@NotNull public static @NotNull SegmentTree build(@NotNull @NotNull BasedSegmentBuilder builder)
@NotNull public static @NotNull SegmentTree.SegmentTreeData buildTreeData(@NotNull @NotNull Iterable<Seg> segments, @NotNull @NotNull CharSequence allText, boolean buildIndexData)
Index data has aggregated lengths with BASE and TEXT segments in the data, Offset data has segment start offset with BASE and ANCHOR segments in the data since TEXT segments have no offset they are skipped
The offset data can be used to pass as treeData to findSegmentPos(int, int[], int, int) with desired offset instead of index
to find a segment which can contain the desired offset, with some post processing logic to handle offset segments which are not in the data
segments - segments of the treeallText - all out of base textbuildIndexData - true to build index search data, false to build base offset tree data@NotNull public @NotNull SegmentOffsetTree getSegmentOffsetTree(@NotNull @NotNull BasedSequence baseSeq)
Efficiently reuses segmentBytes and only computes offset treeData for BASE and ANCHOR segments
baseSeq - base sequence for the sequence for this segment treeCopyright © 2020. All rights reserved.