pub struct RGAText {
nodes: HashMap<TextId, TextNode>,
children: HashMap<TextId, Vec<TextId>>,
replica_id: String,
seq: u64,
pending_delta: Option<RGATextDelta>,
}Expand description
Collaborative text CRDT using RGA algorithm.
Supports character-level insert and delete with deterministic conflict resolution.
Fields§
§nodes: HashMap<TextId, TextNode>All nodes indexed by their ID.
children: HashMap<TextId, Vec<TextId>>Children of each node (characters inserted after it). Maps origin -> list of children sorted by ID (descending for RGA).
replica_id: StringThe replica ID for this instance.
seq: u64Sequence counter for generating IDs.
pending_delta: Option<RGATextDelta>Pending delta for replication.
Implementations§
Source§impl RGAText
impl RGAText
Sourcepub fn replica_id(&self) -> &str
pub fn replica_id(&self) -> &str
Get the replica ID.
Sourcepub fn delete(&mut self, start: usize, length: usize)
pub fn delete(&mut self, start: usize, length: usize)
Delete characters from start to start+length.
Sourcefn delete_by_id(&mut self, id: &TextId) -> Option<char>
fn delete_by_id(&mut self, id: &TextId) -> Option<char>
Delete a character by its ID.
Sourcepub fn splice(&mut self, position: usize, delete_count: usize, insert: &str)
pub fn splice(&mut self, position: usize, delete_count: usize, insert: &str)
Splice: delete some characters and insert new ones.
Sourcefn id_at_index(&self, index: usize) -> Option<TextId>
fn id_at_index(&self, index: usize) -> Option<TextId>
Get the ID at a visible index.
Sourcefn visible_ids(&self) -> impl Iterator<Item = &TextId> + '_
fn visible_ids(&self) -> impl Iterator<Item = &TextId> + '_
Iterate over visible IDs.
Sourcepub fn id_to_position(&self, id: &TextId) -> Option<usize>
pub fn id_to_position(&self, id: &TextId) -> Option<usize>
Convert a TextId to a visible position.
Sourcepub fn position_to_id(&self, position: usize) -> Option<TextId>
pub fn position_to_id(&self, position: usize) -> Option<TextId>
Convert a visible position to a TextId.
Sourcefn iter_nodes(&self) -> impl Iterator<Item = &TextNode> + '_
fn iter_nodes(&self) -> impl Iterator<Item = &TextNode> + '_
Iterate over all nodes in order.
Sourcefn integrate_node(&mut self, node: TextNode)
fn integrate_node(&mut self, node: TextNode)
Integrate a node into the text.
Sourcepub fn take_delta(&mut self) -> Option<RGATextDelta>
pub fn take_delta(&mut self) -> Option<RGATextDelta>
Take the pending delta.
Sourcepub fn apply_delta(&mut self, delta: &RGATextDelta)
pub fn apply_delta(&mut self, delta: &RGATextDelta)
Apply a delta from another replica.