Class Rope
java.lang.Object
io.lacuna.bifurcan.Rope
- All Implemented Interfaces:
Comparable<Rope>
A tree-based immutable string representation, indexed on both full Unicode code points and Java's UTF-16 code
units. Storage at the leaves uses UTF-8 encoding. It allows for efficient
insert
, remove
,
slice
, and concat
calls, and can be converted in constant time to a Java CharSequence
via toCharSequence()
.-
Field Summary
Fields -
Method Summary
-
Field Details
-
EMPTY
-
-
Method Details
-
from
- Returns:
- a rope corresponding to
cs
-
concat
-
nth
public int nth(int idx) - Returns:
- the nth code point within the rope
- Throws:
IndexOutOfBoundsException
- ifidx
is not within[0, size)
-
size
public int size()- Returns:
- the number of code points in the rope
-
remove
- Returns:
- a rope without the code points within
[start, end)
- Throws:
IllegalArgumentException
- ifstart
orend
are not within[0, size)
-
insert
-
insert
- Returns:
- a new rope with
cs
inserted after the firstindex
code points
-
slice
- Returns:
- a new rope representing the code points within
[start, end)
- Throws:
IllegalArgumentException
- ifend
<start
, orstart
andend
are not within[0, size)
-
isLinear
public boolean isLinear() -
forked
-
linear
-
bytes
- Returns:
- a sequence of bytes representing the UTF-8 encoding of the rope
-
reverseChars
- Returns:
- a sequence of integers representing the UTF-16 code units from back to front
-
chars
- Returns:
- a sequence of integers representing the UTF-16 code units from front to back
-
reverseCodePoints
- Returns:
- a sequence of integers representing the code points from back to front
-
codePoints
- Returns:
- a sequence of integers representing the code points from front to back
-
toString
-
toCharSequence
- Returns:
- a corresponding Java-style
CharSequence
inO(1)
time
-
hashCode
-
equals
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Rope>
- Returns:
- a value representing the lexicographic comparison of the code points
-