Class PText
t
leaf of runs (TextLeaf). Positions and lengths count Unicode code points, as the runs do.
An insert follows Fugue: the new characters hang as the right child of the character before
the position when it has no right children, else as the left child of the next character in
Fugue order (deleted ones included), and each further character as the right child of the one
before it. A replica numbers its characters from one more than the largest counter it holds,
so typing at the cursor extends one run. A delete keeps the characters' ids and drops their
text. merge(PText) is the union of two texts, which every replica computes alike, so two
replicas converge whatever they did concurrently, and Fugue keeps each insert's characters
together.
The value is immutable: every edit returns a new text. A replica is any non-empty text that
no other writer of the document uses; replicaOf(AgentId) derives eight base32 characters from
an agent's id, so the runs stay small.
As a value, a text is the wire encoding of its leaf's map, {k:"t", r:[run...], v:1}
with the map indefinite as every embedded item is (rule S8), and codec(String) writes and reads
that form strictly. A map value of text above 1 KiB spills to a t node that holds the
canonical node bytes of the same leaf (P2-T-02), two texts that meet in a merge take their
union (P2-T-03), and a head whose value holds a text is PRef.v 2 (§6.10.3, rule 3).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe codeccodec(String)returns; a ref whose values pass through it writesPRef.v2 heads (§6.10.3, rule 3). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe characters this release lets one text hold, live and deleted: the leaf bound.static final intThe length of a replica idreplicaOf(AgentId)derives. -
Method Summary
Modifier and TypeMethodDescriptionThe codec of texts edited by a replica: a text encodes as the wire encoding of its leaf's map and decodes from exactly that form.delete(long pos, long len) The text with characters deleted.static PTextThe empty text, edited by a replica.booleanEquality by the leaf: the same characters, ids, and deletions, whatever the replica.inthashCode()The text with characters inserted before a position.leaf()The canonical leaf of the characters, maximal runs in id order.longlength()The live characters, in code points.The union of two texts (P2-T-03): every character of either, deleted when either deleted it, in Fugue order, edited by this text's replica.static PTextThe text of a leaf, edited by a replica.order()Every character id in Fugue order, deleted ones included.replica()The replica that edits this text.static StringThe replica id of an agent (P2-T-02): the first five bytes of the SHA-256 of its encoded id, as eight lower-case base32 characters.toString()The live text.withReplica(String other) This text edited by another replica.
-
Field Details
-
MAX_CHARS
public static final long MAX_CHARSThe characters this release lets one text hold, live and deleted: the leaf bound.- See Also:
-
REPLICA_LENGTH
public static final int REPLICA_LENGTHThe length of a replica idreplicaOf(AgentId)derives.- See Also:
-
-
Method Details
-
empty
-
of
-
replicaOf
-
codec
-
replica
The replica that edits this text. -
length
public long length()The live characters, in code points. -
toString
-
order
Every character id in Fugue order, deleted ones included. -
leaf
The canonical leaf of the characters, maximal runs in id order. -
withReplica
-
insert
The text with characters inserted before a position.- Parameters:
pos- 0 tolength()text- the characters, without a lone surrogate- Returns:
- the text, or this one when
textis empty - Throws:
IllegalArgumentException- when the text would hold more thanMAX_CHARScharacters
-
delete
The text with characters deleted.- Parameters:
pos- the first deleted positionlen- how many live characters to delete- Returns:
- the text, or this one when
lenis 0
-
merge
The union of two texts (P2-T-03): every character of either, deleted when either deleted it, in Fugue order, edited by this text's replica.- Throws:
IllegalArgumentException- when the two texts give one character id two parents, sides, or characters
-
equals
-
hashCode
-