Skip to content

Commit

Permalink
refactor: avoid footgun of impl ord for cid
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Sep 30, 2024
1 parent 37ed452 commit 6d04066
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 89 deletions.
55 changes: 0 additions & 55 deletions crates/loro-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,61 +186,6 @@ pub enum ContainerID {
},
}

/// Root is less than Normal.
/// The same ContainerType should be grouped together.
impl Ord for ContainerID {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match (self, other) {
(
Self::Root {
name,
container_type,
},
Self::Root {
name: name2,
container_type: container_type2,
},
) => {
if container_type == container_type2 {
name.cmp(name2)
} else {
container_type.cmp(container_type2)
}
}
(
Self::Normal {
peer,
counter,
container_type,
},
Self::Normal {
peer: peer2,
counter: counter2,
container_type: container_type2,
},
) => {
if container_type == container_type2 {
if peer == peer2 {
counter.cmp(counter2)
} else {
peer.cmp(peer2)
}
} else {
container_type.cmp(container_type2)
}
}
(Self::Root { .. }, Self::Normal { .. }) => std::cmp::Ordering::Less,
(Self::Normal { .. }, Self::Root { .. }) => std::cmp::Ordering::Greater,
}
}
}

impl PartialOrd for ContainerID {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl ContainerID {
pub fn encode<W: Write>(&self, writer: &mut W) -> Result<(), std::io::Error> {
match self {
Expand Down
7 changes: 3 additions & 4 deletions crates/loro-internal/src/diff_calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ use itertools::Itertools;
use enum_dispatch::enum_dispatch;
use fxhash::{FxHashMap, FxHashSet};
use loro_common::{
CompactIdLp, ContainerID, Counter, HasCounter, HasCounterSpan, IdFull, IdLp, IdSpan, LoroValue,
PeerID, ID,
CompactIdLp, ContainerID, Counter, HasCounterSpan, IdFull, IdLp, IdSpan, LoroValue, PeerID, ID,
};
use loro_delta::DeltaRope;
use smallvec::SmallVec;
use tracing::{debug, info_span, instrument};
use tracing::{info_span, instrument};

use crate::{
change::Lamport,
Expand All @@ -37,7 +36,7 @@ use crate::{
event::{DiffVariant, InternalDiff},
op::{InnerContent, RichOp, SliceRange, SliceWithId},
span::{HasId, HasLamport},
version::{Frontiers, VersionRange},
version::Frontiers,
InternalString, VersionVector,
};

Expand Down
15 changes: 0 additions & 15 deletions crates/loro-internal/src/oplog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,21 +399,6 @@ impl OpLog {
decode_oplog(self, data)
}

/// Iterates over all changes between `a` and `b` peer by peer (not in causal order, fast)
pub(crate) fn for_each_change_within(
&self,
a: &VersionVector,
b: &VersionVector,
mut f: impl FnMut(&Change, (Counter, Counter)),
) {
let spans = b.iter_between(a);
for span in spans {
for c in self.change_store.iter_changes(span) {
f(&c, (span.ctr_start(), span.ctr_end()));
}
}
}

/// iterates over all changes between LCA(common ancestors) to the merged version of (`from` and `to`) causally
///
/// Tht iterator will include a version vector when the change is applied
Expand Down
19 changes: 4 additions & 15 deletions crates/loro-internal/src/state/container_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,11 @@ pub(crate) use container_wrapper::ContainerWrapper;
mod container_wrapper;
mod inner_store;

/// Encoding Schema for Container Store
///
/// ┌───────────────┬───────────────────────────────────┐
/// │ 4B Container │ N CID + Offsets │
/// │ Binary Offset │ (EncodedBy DeltaRLE) │
/// └───────────────┴───────────────────────────────────┘
/// ┌───────────────────────────────────────────────────┐
/// │ │
/// │ │
/// │ │
/// │ All Containers' Binary │
/// │ │
/// │ │
/// │ │
/// └───────────────────────────────────────────────────┘
/// Encoding Schema for Container Store
///
/// KV-Store:
/// - Key: Encoded Container ID
/// - Value: Encoded Container State
///
/// ─ ─ ─ ─ ─ ─ ─ For Each Container Type ─ ─ ─ ─ ─ ─ ─ ─
///
Expand Down

0 comments on commit 6d04066

Please sign in to comment.