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

public final Class SegmentedSequenceTree

extends SegmentedSequence
Class Inheritance
Imports
com.vladsch.flexmark.util.sequence.builder.IBasedSegmentBuilder, .ISegmentBuilder, .SegmentedSequenceStats, com.vladsch.flexmark.util.sequence.builder.tree.Segment, .SegmentTree, .SegmentTreeRange, org.jetbrains.annotations.NotNull, .Nullable

A BasedSequence which consists of segments of other BasedSequences NOTE: very efficient for random access but extremely wasteful with space by allocating 4 bytes per character in the sequence with corresponding construction penalty use SegmentedSequenceTree which is binary tree based segmented sequence with minimal overhead and optimized to give penalty free random access for most applications.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final ThreadLocal<SegmentedSequenceTree.Cache>
private final int
private final SegmentTree
private final int
private final int
Inherited from com.vladsch.flexmark.util.sequence.SegmentedSequence:
baseSeqendOffsetlengthstartOffset

Constructor Summary

AccessConstructor and Description
private
SegmentedSequenceTree(BasedSequence baseSeq, int startOffset, int endOffset, int length, @NotNull SegmentTree segmentTree)

private

Method Summary

Modifier and TypeMethod and Description
public void
public char
charAt(int
the index of the char value to be returned
index
)

Implements java.lang.CharSequence.charAt.

Returns the char value at the specified index.

public static SegmentedSequenceTree

Returns:

segmented sequence
create
(@NotNull BasedSequence
base sequence
baseSeq
,
ISegmentBuilder<?>
builder containing segments for this sequence
builder
)

Base Constructor

private @NotNull SegmentedSequenceTree.Cache
getCache(int index)

private @Nullable Segment
public int
getIndexOffset(int
index for which to get the offset in original source
index
)

Implements com.vladsch.flexmark.util.sequence.BasedSequence.getIndexOffset.

Get the offset of index in this sequence mapped to offset into getBaseSequence() and getBase() original text source.

public @NotNull SegmentTree
public @NotNull BasedSequence
subSequence(int
offset from startIndex of this sequence
startIndex
,
int
offset from startIndex of this sequence
endIndex
)

Implements com.vladsch.flexmark.util.sequence.BasedSequence.subSequence, com.vladsch.flexmark.util.sequence.IRichSequence.subSequence.

Get a portion of this sequence

Inherited from com.vladsch.flexmark.util.sequence.SegmentedSequence:
allOptionsanyOptionsbaseSubSequencecreatecreatecreategetBasegetBaseSequencegetEndOffsetgetOptiongetOptionFlagsgetOptionsgetSourceRangegetStartOffsetlengthofof

Field Detail

cacheback to summary
private final ThreadLocal<SegmentedSequenceTree.Cache> cache
endPosback to summary
private final int endPos
segmentTreeback to summary
private final SegmentTree segmentTree
startIndexback to summary
private final int startIndex
startPosback to summary
private final int startPos

Constructor Detail

SegmentedSequenceTreeback to summary
private SegmentedSequenceTree(BasedSequence baseSeq, int startOffset, int endOffset, int length, @NotNull SegmentTree segmentTree)
SegmentedSequenceTreeback to summary
private SegmentedSequenceTree(BasedSequence baseSeq, @NotNull SegmentTree segmentTree, @NotNull SegmentTreeRange subSequenceRange)

Method Detail

addSegmentsback to summary
public void addSegments(@NotNull IBasedSegmentBuilder<?> builder)
Annotations
@Override
charAtback to summary
public char charAt(int index)

Implements java.lang.CharSequence.charAt.

Doc from java.lang.CharSequence.charAt.

Returns the char value at the specified index. An index ranges from zero to length() - 1. The first char value of the sequence is at index zero, the next at index one, and so on, as for array indexing.

If the char value specified by the index is a surrogate, the surrogate value is returned.

Parameters
index:int

the index of the char value to be returned

Returns:char

the specified char value

Annotations
@Override
createback to summary
public static SegmentedSequenceTree create(@NotNull BasedSequence baseSeq, ISegmentBuilder<?> builder)

Base Constructor

Parameters
baseSeq:@NotNull BasedSequence

base sequence

builder:ISegmentBuilder<?>

builder containing segments for this sequence

Returns:SegmentedSequenceTree

segmented sequence

getCacheback to summary
private @NotNull SegmentedSequenceTree.Cache getCache(int index)
Annotations
@NotNull
getCachedSegmentback to summary
private @Nullable Segment getCachedSegment()
Annotations
@Nullable
getIndexOffsetback to summary
public int getIndexOffset(int index)

Implements com.vladsch.flexmark.util.sequence.BasedSequence.getIndexOffset.

Doc from com.vladsch.flexmark.util.sequence.BasedSequence.getIndexOffset.

Get the offset of index in this sequence mapped to offset into getBaseSequence() and getBase() original text source.

Note

if the character at given index does not equal the corresponding character in the base sequence then this method should return -1 otherwise segmented based sequence will be created for original base character

Parameters
index:int

index for which to get the offset in original source

Returns:int

offset of index of this sequence in original text

Annotations
@Override
getSegmentTreeback to summary
public @NotNull SegmentTree getSegmentTree()

Overrides com.vladsch.flexmark.util.sequence.BasedSequenceImpl.getSegmentTree.

Implements com.vladsch.flexmark.util.sequence.BasedSequence.getSegmentTree.

Doc from com.vladsch.flexmark.util.sequence.BasedSequence.getSegmentTree.

Get the segment tree for this sequence

Returns:@NotNull SegmentTree

segment tree

Annotations
@NotNull
@Override
subSequenceback to summary
public @NotNull BasedSequence subSequence(int startIndex, int endIndex)

Implements com.vladsch.flexmark.util.sequence.BasedSequence.subSequence, com.vladsch.flexmark.util.sequence.IRichSequence.subSequence.

Doc from com.vladsch.flexmark.util.sequence.BasedSequence.subSequence.

Get a portion of this sequence

Parameters
startIndex:int

offset from startIndex of this sequence

endIndex:int

offset from startIndex of this sequence

Returns:@NotNull BasedSequence

based sequence which represents the requested range of this sequence.

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

private Class SegmentedSequenceTree.Cache

extends Object
Class Inheritance
  • java.lang.Object
  • com.vladsch.flexmark.util.sequence.SegmentedSequenceTree.Cache

Field Summary

Modifier and TypeField and Description
pack-priv final @NotNull CharSequence
pack-priv final int
pack-priv final @NotNull Segment

Constructor Summary

AccessConstructor and Description
public
Cache(@NotNull Segment segment, @NotNull CharSequence chars, int startIndex)

Method Summary

Modifier and TypeMethod and Description
public char
charAt(int index)

public int
charIndex(int index)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charsback to summary
pack-priv final @NotNull CharSequence chars
Annotations
@NotNull
indexDeltaback to summary
pack-priv final int indexDelta
segmentback to summary
pack-priv final @NotNull Segment segment
Annotations
@NotNull

Constructor Detail

Cacheback to summary
public Cache(@NotNull Segment segment, @NotNull CharSequence chars, int startIndex)

Method Detail

charAtback to summary
public char charAt(int index)
charIndexback to summary
public int charIndex(int index)