Top Description Inners Fields Constructors Methods
com.vladsch.flexmark.util.sequence.builder.tree

public Class SegmentTree

extends Object
Class Inheritance
Known Direct Subclasses
com.vladsch.flexmark.util.sequence.builder.tree.SegmentOffsetTree
Imports
com.vladsch.flexmark.util.misc.DelimitedBuilder, com.vladsch.flexmark.util.sequence.BasedSequence, com.vladsch.flexmark.util.sequence.builder.BasedSegmentBuilder, .IBasedSegmentBuilder, .Seg, org.jetbrains.annotations.NotNull, .Nullable, java.util.Arrays

Binary search tree of sequence segments

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
protected final byte[]
protected final int[]

Constructor Summary

AccessConstructor and Description
protected
SegmentTree(int[] treeData, byte[] segmentBytes)

Method Summary

Modifier and TypeMethod and Description
public void
addSegments(@NotNull IBasedSegmentBuilder<?>
based segment builder
builder
,
@NotNull SegmentTreeRange
treeRange for which to add segments
treeRange
)

Add segments selected by given treeRange

public void
addSegments(@NotNull IBasedSegmentBuilder<?>
builder to which to add the segments
builder
,
int
start index of sub-sequence of segment tree
startIndex
,
int
end index of sub-sequence of segment tree
endIndex
,
int
start offset of the subsequence to use as start anchor
startOffset
,
int
end offset of the subsequence to use as end anchor
endOffset
,
int
start pos of sub-sequence segments in tree
startPos
,
int
end pos of sub-sequence segments in tree
endPos
)

Add segments of subsequence of this tree to builder

public int
aggrLength(int pos)

public static int
aggrLength(int pos, int[] treeData)

public static @NotNull SegmentTree
public static @NotNull SegmentTree
public static @NotNull SegmentTree.SegmentTreeData

Returns:

segment tree instance with the data
buildTreeData
(@NotNull Iterable<Seg>
segments of the tree
segments
,
@NotNull CharSequence
all out of base text
allText
,
boolean
true to build index search data, false to build base offset tree data
buildIndexData
)

Build binary tree search data

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

public int
byteOffset(int pos)

public static int
byteOffset(int pos, int[] treeData)

public int
byteOffsetData(int pos)

public static int
byteOffsetData(int pos, int[] treeData)

public @Nullable Segment
public @Nullable Segment
findSegment(int index, int startPos, int endPos, @NotNull BasedSequence baseSeq, @Nullable Segment hint)

public static @Nullable Segment
findSegment(int index, int[] treeData, int startPos, int endPos, byte[] segmentBytes, @NotNull BasedSequence baseSeq)

public @Nullable SegmentTreePos
findSegmentPos(int index)

public @Nullable SegmentTreePos
findSegmentPos(int index, int startPos, int endPos)

public static @Nullable SegmentTreePos
findSegmentPos(int index, int[] treeData, int startPos, int endPos)

public static int
getAnchorOffset(int byteOffsetData)

public static int
getByteOffset(int byteOffsetData)

public static @NotNull CharSequence

Returns:

subsequence of segment corresponding to part of it which is in the sub-sequence of the tree
getCharSequence
(@NotNull Segment
segment
segment
,
int
start index of sub-sequence of segment tree
startIndex
,
int
end index of sub-sequence of segment tree
endIndex
,
int
start pos of sub-sequence segments in tree
startPos
,
int
end pos of sub-sequence segments in tree
endPos
)

Get char sequence of segment corresponding to sub-sequence in segment tree

public @Nullable Segment
public static @Nullable Segment
getPrevAnchor(int pos, int[] treeData, byte[] segmentBytes, @NotNull BasedSequence baseSeq)

public @NotNull Segment
getSegment(int byteOffset, int pos, int startIndex, @NotNull BasedSequence baseSeq)

public @NotNull Segment
getSegment(int pos, @NotNull BasedSequence baseSeq)

public static @NotNull Segment
getSegment(int pos, int[] treeData, byte[] segmentBytes, @NotNull BasedSequence baseSeq)

public byte[]
public @NotNull SegmentOffsetTree

Returns:

SegmentOffsetTree for this segment tree
getSegmentOffsetTree
(@NotNull BasedSequence
base sequence for the sequence for this segment tree
baseSeq
)

Build an offset segment tree from this index segment tree

Efficiently reuses segmentBytes and only computes offset treeData for BASE and ANCHOR segments

public @NotNull SegmentTreeRange
getSegmentRange(int startIndex, int endIndex, int startPos, int endPos, @NotNull BasedSequence baseSequence, @Nullable Segment hint)

public int
public int
public int[]
public boolean
public static boolean
hasPreviousAnchor(int pos, int[] treeData)

public int
public static int
previousAnchorOffset(int pos, int[] treeData)

public static void
setTreeData(int pos, int[] treeData, int agrrLength, int byteOffset, int prevAnchorOffset)

public int
size()

public @NotNull String
public @NotNull String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

F_ANCHOR_FLAGSback to summary
public static final int F_ANCHOR_FLAGS
MAX_VALUEback to summary
public static final int MAX_VALUE
segmentBytesback to summary
protected final byte[] segmentBytes
treeDataback to summary
protected final int[] treeData

Constructor Detail

SegmentTreeback to summary
protected SegmentTree(int[] treeData, byte[] segmentBytes)

Method Detail

addSegmentsback to summary
public void addSegments(@NotNull IBasedSegmentBuilder<?> builder, @NotNull SegmentTreeRange treeRange)

Add segments selected by given treeRange

Parameters
builder:@NotNull IBasedSegmentBuilder<?>

based segment builder

treeRange:@NotNull SegmentTreeRange

treeRange for which to add segments

addSegmentsback to summary
public 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

Parameters
builder:@NotNull IBasedSegmentBuilder<?>

builder to which to add the segments

startIndex:int

start index of sub-sequence of segment tree

endIndex:int

end index of sub-sequence of segment tree

startOffset:int

start offset of the subsequence to use as start anchor

endOffset:int

end offset of the subsequence to use as end anchor

startPos:int

start pos of sub-sequence segments in tree

endPos:int

end pos of sub-sequence segments in tree

aggrLengthback to summary
public int aggrLength(int pos)
aggrLengthback to summary
public static int aggrLength(int pos, int[] treeData)
buildback to summary
public static @NotNull SegmentTree build(@NotNull Iterable<Seg> segments, @NotNull CharSequence allText)
Annotations
@NotNull
buildback to summary
public static @NotNull SegmentTree build(@NotNull BasedSegmentBuilder builder)
Annotations
@NotNull
buildTreeDataback to summary
public static @NotNull SegmentTree.SegmentTreeData buildTreeData(@NotNull Iterable<Seg> segments, @NotNull CharSequence allText, boolean buildIndexData)

Build binary tree search data

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

Parameters
segments:@NotNull Iterable<Seg>

segments of the tree

allText:@NotNull CharSequence

all out of base text

buildIndexData:boolean

true to build index search data, false to build base offset tree data

Returns:@NotNull SegmentTree.SegmentTreeData

segment tree instance with the data

Annotations
@NotNull
byteOffsetback to summary
public int byteOffset(int pos)
byteOffsetback to summary
public static int byteOffset(int pos, int[] treeData)
byteOffsetDataback to summary
public int byteOffsetData(int pos)
byteOffsetDataback to summary
public static int byteOffsetData(int pos, int[] treeData)
findSegmentback to summary
public @Nullable Segment findSegment(int index, @NotNull BasedSequence baseSeq, @Nullable Segment hint)
Annotations
@Nullable
findSegmentback to summary
public @Nullable Segment findSegment(int index, int startPos, int endPos, @NotNull BasedSequence baseSeq, @Nullable Segment hint)
Annotations
@Nullable
findSegmentback to summary
public static @Nullable Segment findSegment(int index, int[] treeData, int startPos, int endPos, byte[] segmentBytes, @NotNull BasedSequence baseSeq)
Annotations
@Nullable
findSegmentPosback to summary
public @Nullable SegmentTreePos findSegmentPos(int index)
Annotations
@Nullable
findSegmentPosback to summary
public @Nullable SegmentTreePos findSegmentPos(int index, int startPos, int endPos)
Annotations
@Nullable
findSegmentPosback to summary
public static @Nullable SegmentTreePos findSegmentPos(int index, int[] treeData, int startPos, int endPos)
Annotations
@Nullable
getAnchorOffsetback to summary
public static int getAnchorOffset(int byteOffsetData)
getByteOffsetback to summary
public static int getByteOffset(int byteOffsetData)
getCharSequenceback to summary
public 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

Parameters
segment:@NotNull Segment

segment

startIndex:int

start index of sub-sequence of segment tree

endIndex:int

end index of sub-sequence of segment tree

startPos:int

start pos of sub-sequence segments in tree

endPos:int

end pos of sub-sequence segments in tree

Returns:@NotNull CharSequence

subsequence of segment corresponding to part of it which is in the sub-sequence of the tree

Annotations
@NotNull
getPrevAnchorback to summary
public @Nullable Segment getPrevAnchor(int pos, @NotNull BasedSequence baseSeq)
Annotations
@Nullable
getPrevAnchorback to summary
public static @Nullable Segment getPrevAnchor(int pos, int[] treeData, byte[] segmentBytes, @NotNull BasedSequence baseSeq)
Annotations
@Nullable
getSegmentback to summary
public @NotNull Segment getSegment(int byteOffset, int pos, int startIndex, @NotNull BasedSequence baseSeq)
Annotations
@NotNull
getSegmentback to summary
public @NotNull Segment getSegment(int pos, @NotNull BasedSequence baseSeq)
Annotations
@NotNull
getSegmentback to summary
public static @NotNull Segment getSegment(int pos, int[] treeData, byte[] segmentBytes, @NotNull BasedSequence baseSeq)
Annotations
@NotNull
getSegmentBytesback to summary
public byte[] getSegmentBytes()
getSegmentOffsetTreeback to summary
public @NotNull SegmentOffsetTree getSegmentOffsetTree(@NotNull BasedSequence baseSeq)

Build an offset segment tree from this index segment tree

Efficiently reuses segmentBytes and only computes offset treeData for BASE and ANCHOR segments

Parameters
baseSeq:@NotNull BasedSequence

base sequence for the sequence for this segment tree

Returns:@NotNull SegmentOffsetTree

SegmentOffsetTree for this segment tree

Annotations
@NotNull
getSegmentRangeback to summary
public @NotNull SegmentTreeRange getSegmentRange(int startIndex, int endIndex, int startPos, int endPos, @NotNull BasedSequence baseSequence, @Nullable Segment hint)
Annotations
@NotNull
getTextEndOffsetback to summary
public int getTextEndOffset(Segment segment, @NotNull BasedSequence baseSequence)
getTextStartOffsetback to summary
public int getTextStartOffset(Segment segment, @NotNull BasedSequence baseSequence)
getTreeDataback to summary
public int[] getTreeData()
hasPreviousAnchorback to summary
public boolean hasPreviousAnchor(int pos)
hasPreviousAnchorback to summary
public static boolean hasPreviousAnchor(int pos, int[] treeData)
previousAnchorOffsetback to summary
public int previousAnchorOffset(int pos)
previousAnchorOffsetback to summary
public static int previousAnchorOffset(int pos, int[] treeData)
setTreeDataback to summary
public static void setTreeData(int pos, int[] treeData, int agrrLength, int byteOffset, int prevAnchorOffset)
sizeback to summary
public int size()
toStringback to summary
public @NotNull String toString(@NotNull BasedSequence baseSeq)
Annotations
@NotNull
toStringback to summary
public @NotNull String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:@NotNull String

a string representation of the object

Annotations
@NotNull
@Override
com.vladsch.flexmark.util.sequence.builder.tree back to summary

protected Class SegmentTree.SegmentTreeData

extends Object
Class Inheritance
  • java.lang.Object
  • com.vladsch.flexmark.util.sequence.builder.tree.SegmentTree.SegmentTreeData

Field Summary

Modifier and TypeField and Description
public final @NotNull byte[]
public final @Nullable int[]
public final @NotNull int[]

Constructor Summary

AccessConstructor and Description
public
SegmentTreeData(@NotNull int[] treeData, @NotNull byte[] segmentBytes, @Nullable int[] startIndices)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

segmentBytesback to summary
public final @NotNull byte[] segmentBytes
Annotations
@NotNull
startIndicesback to summary
public final @Nullable int[] startIndices
Annotations
@Nullable
treeDataback to summary
public final @NotNull int[] treeData
Annotations
@NotNull

Constructor Detail

SegmentTreeDataback to summary
public SegmentTreeData(@NotNull int[] treeData, @NotNull byte[] segmentBytes, @Nullable int[] startIndices)