optype simplify
This commit is contained in:
parent
610ddef016
commit
e7119e61f7
4 changed files with 24 additions and 33 deletions
automerge/src
|
@ -5,13 +5,11 @@ use crate::decoding;
|
|||
use crate::decoding::Decodable;
|
||||
use crate::encoding::{Encodable, DEFLATE_MIN_SIZE};
|
||||
use crate::expanded_op::ExpandedOpIterator;
|
||||
use crate::internal::InternalOpType;
|
||||
use crate::{AutomergeError, ElemId, IndexedCache, Key, ObjId, Op, OpId, Transaction, HEAD, ROOT};
|
||||
use automerge_protocol as amp;
|
||||
use core::ops::Range;
|
||||
use flate2::{bufread::DeflateEncoder, Compression};
|
||||
use itertools::Itertools;
|
||||
use nonzero_ext::nonzero;
|
||||
use sha2::Digest;
|
||||
use sha2::Sha256;
|
||||
use std::collections::HashMap;
|
||||
|
@ -347,12 +345,7 @@ impl EncodedChange {
|
|||
operations: self
|
||||
.iter_ops()
|
||||
.map(|op| amp::Op {
|
||||
action: match op.action {
|
||||
InternalOpType::Make(obj_type) => amp::OpType::Make(obj_type),
|
||||
InternalOpType::Del => amp::OpType::Del(nonzero!(1_u32)),
|
||||
InternalOpType::Inc(i) => amp::OpType::Inc(i),
|
||||
InternalOpType::Set(value) => amp::OpType::Set(value),
|
||||
},
|
||||
action: op.action.into(),
|
||||
obj: op.obj.clone().into_owned(),
|
||||
key: op.key.into_owned(),
|
||||
pred: op.pred.into_owned(),
|
||||
|
|
|
@ -73,17 +73,6 @@ where
|
|||
.map(|a| sorted.iter().position(|r| r == a).unwrap())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn decode_index(&self) -> Vec<usize> {
|
||||
let sorted = self.sorted();
|
||||
sorted.iter().map(|a| self.cache.iter().position(|r| r == a).unwrap()).collect()
|
||||
}
|
||||
|
||||
pub fn sorted(&self) -> Vec<T> {
|
||||
self.cache.iter().sorted().cloned().collect()
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
impl<T> IntoIterator for IndexedCache<T> {
|
||||
|
|
|
@ -100,3 +100,14 @@ impl From<&InternalOpType> for amp::OpType {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InternalOpType> for amp::OpType {
|
||||
fn from(i: InternalOpType) -> amp::OpType {
|
||||
match i {
|
||||
InternalOpType::Del => amp::OpType::Del(nonzero!(1_u32)),
|
||||
InternalOpType::Make(ot) => amp::OpType::Make(ot),
|
||||
InternalOpType::Set(v) => amp::OpType::Set(v.clone()),
|
||||
InternalOpType::Inc(i) => amp::OpType::Inc(i),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ impl Automerge {
|
|||
ops: Default::default(),
|
||||
deps: Default::default(),
|
||||
actor: None,
|
||||
seq: 0,
|
||||
seq: 0, // FIXME - need a clock
|
||||
max_op: 0,
|
||||
transaction: None,
|
||||
}
|
||||
|
@ -601,28 +601,26 @@ impl Automerge {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn apply_changes(&mut self, changes: &[amp::Change]) {
|
||||
pub fn apply_changes(&mut self, changes: &[EncodedChange]) {
|
||||
for c in changes {
|
||||
self.apply_change(c)
|
||||
self.apply_change(c.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_change(&mut self, change: &::Change) {
|
||||
let change_id = self.history.len();
|
||||
self.history.push(change.into());
|
||||
let ops = self.import_ops(change, change_id);
|
||||
pub fn apply_change(&mut self, change: EncodedChange) {
|
||||
let ops = self.import_ops(&change, self.history.len());
|
||||
self.history.push(change);
|
||||
for op in ops {
|
||||
self.insert_op(op, false)
|
||||
}
|
||||
}
|
||||
|
||||
fn import_ops(&mut self, change: &::Change, change_id: usize) -> Vec<Op> {
|
||||
fn import_ops(&mut self, change: &EncodedChange, change_id: usize) -> Vec<Op> {
|
||||
change
|
||||
.operations
|
||||
.iter()
|
||||
.iter_ops()
|
||||
.enumerate()
|
||||
.map(|(i, c)| {
|
||||
let actor = self.actors.cache(change.actor_id.clone());
|
||||
let actor = self.actors.cache(change.actor_id().clone());
|
||||
let id = OpId(change.start_op + i as u64, actor);
|
||||
let obj: ObjId = self.import(&c.obj.to_string()).unwrap();
|
||||
let pred = c
|
||||
|
@ -630,7 +628,7 @@ impl Automerge {
|
|||
.iter()
|
||||
.map(|i| self.import(&i.to_string()).unwrap())
|
||||
.collect();
|
||||
let key = match &c.key {
|
||||
let key = match &c.key.as_ref() {
|
||||
amp::Key::Map(n) => Key::Map(self.props.cache(n.to_string())),
|
||||
amp::Key::Seq(amp::ElementId::Head) => Key::Seq(HEAD),
|
||||
amp::Key::Seq(amp::ElementId::Id(i)) => Key::Seq(HEAD),
|
||||
|
@ -638,7 +636,7 @@ impl Automerge {
|
|||
Op {
|
||||
change: change_id,
|
||||
id,
|
||||
action: c.action.clone(),
|
||||
action: c.action.into(),
|
||||
obj,
|
||||
key,
|
||||
succ: vec![],
|
||||
|
@ -738,7 +736,7 @@ impl Automerge {
|
|||
.entry(change.actor_id().clone())
|
||||
.or_default()
|
||||
.push(history_index);
|
||||
*/
|
||||
*/
|
||||
|
||||
self.history_index.insert(change.hash, history_index);
|
||||
self.history.push(change);
|
||||
|
|
Loading…
Add table
Reference in a new issue