use anyhow::Result;
use tracing::info;
use serde::{Serialize, Deserialize};
use std::collections::{HashMap, BTreeMap};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum BaseOperation {
Insert { id: String, position: usize, text: String },
Delete { id: String, position: usize, length: usize },
}
pub struct OperationTransformer {
history: Vec<BaseOperation>,
}
impl OperationTransformer {
pub fn new() -> Self {
info!("đ ĺĺ§ĺćä˝ĺć˘ĺ¨");
Self {
history: Vec::new(),
}
}
pub fn transform(&self, op1: &BaseOperation, op2: &BaseOperation) -> (BaseOperation, BaseOperation) {
(op1.clone(), op2.clone())
}
pub fn add_operation(&self, operation: BaseOperation) {
}
}
#[derive(Debug, Clone)]
pub struct CRDTList {
nodes: Vec<String>,
max_nodes: usize,
}
impl CRDTList {
pub fn new(max_nodes: usize) -> Self {
info!("đ ĺĺťş CRDT ĺ襨 (ć大čçšć°: {})", max_nodes);
Self {
nodes: Vec::new(),
max_nodes,
}
}
pub fn insert(&mut self, position: usize, value: String) -> Result<()> {
if position <= self.nodes.len() {
self.nodes.insert(position, value);
}
Ok(())
}
pub fn get_all(&self) -> Vec<String> {
self.nodes.clone()
}
pub fn len(&self) -> usize {
self.nodes.len()
}
}