Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • sweng-group-15/drawing-crdt
1 result
Show changes
Commits on Source (1)
No preview for this file type
...@@ -8,14 +8,16 @@ use std::collections::hash_map::Entry::{Occupied, Vacant}; ...@@ -8,14 +8,16 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryInto; use std::convert::TryInto;
use std::fmt; use std::fmt;
use std::fmt::Debug;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use twox_hash::XxHash64 as XXHasher; use twox_hash::XxHash64 as XXHasher;
use uuid::Uuid; use uuid::Uuid;
use vec_map::VecMap; use vec_map::VecMap;
#[derive(Debug)] #[cfg(debug_assertions)]
use std::fmt::Debug;
#[cfg_attr(debug_assertions, derive(Debug))]
struct Dirty<T> { struct Dirty<T> {
value: T, value: T,
dirty_events: bool, dirty_events: bool,
...@@ -67,7 +69,8 @@ impl<T> Dirty<T> { ...@@ -67,7 +69,8 @@ impl<T> Dirty<T> {
} }
} }
#[derive(Clone, Debug)] #[derive(Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct Point { pub struct Point {
x: i32, x: i32,
y: i32, y: i32,
...@@ -160,7 +163,14 @@ impl Point { ...@@ -160,7 +163,14 @@ impl Point {
} }
} }
pub trait IntervalBound: Debug + Copy + Clone + Default + Ord + Hash { #[cfg(debug_assertions)]
pub trait IntervalBound: Copy + Clone + Default + Ord + Hash + Debug {
fn up(self) -> Self;
fn down(self) -> Self;
fn sub(self, nom: u8, denom: u8) -> Self;
}
#[cfg(not(debug_assertions))]
pub trait IntervalBound: Copy + Clone + Default + Ord + Hash {
fn up(self) -> Self; fn up(self) -> Self;
fn down(self) -> Self; fn down(self) -> Self;
fn sub(self, nom: u8, denom: u8) -> Self; fn sub(self, nom: u8, denom: u8) -> Self;
...@@ -195,7 +205,8 @@ impl IntervalBound for usize { ...@@ -195,7 +205,8 @@ impl IntervalBound for usize {
} }
} }
#[derive(Copy, Clone, PartialEq, Hash, Debug)] #[derive(Copy, Clone, PartialEq, Hash)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct Interval<T> pub struct Interval<T>
where where
T: IntervalBound, T: IntervalBound,
...@@ -230,7 +241,8 @@ where ...@@ -230,7 +241,8 @@ where
} }
} }
#[derive(Clone, Hash, Debug)] #[derive(Clone, Hash)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct IntervalUnion<T>(Vec<Interval<T>>) pub struct IntervalUnion<T>(Vec<Interval<T>>)
where where
T: IntervalBound; T: IntervalBound;
...@@ -341,8 +353,10 @@ where ...@@ -341,8 +353,10 @@ where
let mut intervals: Vec<Interval<T>> = Vec::new(); let mut intervals: Vec<Interval<T>> = Vec::new();
while si < self.0.len() && oi < other.0.len() { while si < self.0.len() || oi < other.0.len() {
let interval = if self.0[si].from < other.0[oi].from { let interval = if (oi >= other.0.len())
|| ((si < self.0.len()) && (self.0[si].from < other.0[oi].from))
{
let interval = self.0[si]; let interval = self.0[si];
si += 1; si += 1;
interval interval
...@@ -364,25 +378,6 @@ where ...@@ -364,25 +378,6 @@ where
}; };
} }
let (interval, tail) = if si < self.0.len() {
(self.0[si], &self.0[si + 1..])
} else {
(other.0[oi], &other.0[oi + 1..])
};
match intervals.last_mut() {
Some(top) => {
if interval.from <= top.to.up() {
top.to = cmp::max(top.to, interval.to)
} else {
intervals.push(interval)
}
}
None => intervals.push(interval),
};
intervals.extend_from_slice(tail);
let changed = intervals != self.0; let changed = intervals != self.0;
self.0 = intervals; self.0 = intervals;
...@@ -452,7 +447,7 @@ where ...@@ -452,7 +447,7 @@ where
} }
} }
#[derive(Debug)] #[cfg_attr(debug_assertions, derive(Debug))]
struct Stroke { struct Stroke {
index: usize, index: usize,
points: Dirty<VecMap<Point>>, points: Dirty<VecMap<Point>>,
...@@ -469,7 +464,7 @@ impl Stroke { ...@@ -469,7 +464,7 @@ impl Stroke {
} }
} }
#[derive(Debug)] #[cfg_attr(debug_assertions, derive(Debug))]
pub struct StrokeDelta { pub struct StrokeDelta {
points: HashMap<usize, Point>, points: HashMap<usize, Point>,
intervals: IntervalUnion<NotNan<f32>>, intervals: IntervalUnion<NotNan<f32>>,
...@@ -531,7 +526,7 @@ impl StrokeDelta { ...@@ -531,7 +526,7 @@ impl StrokeDelta {
} }
} }
#[derive(Debug)] #[cfg_attr(debug_assertions, derive(Debug))]
struct User { struct User {
strokes: Vec<Stroke>, strokes: Vec<Stroke>,
} }
...@@ -550,7 +545,8 @@ impl User { ...@@ -550,7 +545,8 @@ impl User {
} }
} }
#[derive(Clone, Hash, Eq, PartialEq, Debug)] #[derive(Clone, Hash, Eq, PartialEq)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct StrokeID(u128, usize); pub struct StrokeID(u128, usize);
impl Serialize for StrokeID { impl Serialize for StrokeID {
...@@ -610,7 +606,8 @@ impl StrokeID { ...@@ -610,7 +606,8 @@ impl StrokeID {
} }
} }
#[derive(Clone, PartialEq, Eq, Debug)] #[derive(Clone, PartialEq, Eq)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct IntervalUnionState<T> pub struct IntervalUnionState<T>
where where
T: IntervalBound, T: IntervalBound,
...@@ -811,7 +808,7 @@ where ...@@ -811,7 +808,7 @@ where
} }
} }
#[derive(Debug)] #[cfg_attr(debug_assertions, derive(Debug))]
pub struct DeltaVec(HashMap<StrokeID, StrokeDelta>); pub struct DeltaVec(HashMap<StrokeID, StrokeDelta>);
impl Serialize for DeltaVec { impl Serialize for DeltaVec {
...@@ -952,7 +949,7 @@ impl<'de> Deserialize<'de> for DeltaVec { ...@@ -952,7 +949,7 @@ impl<'de> Deserialize<'de> for DeltaVec {
} }
} }
#[derive(Debug)] #[cfg_attr(debug_assertions, derive(Debug))]
pub struct StateVec { pub struct StateVec {
strokes: HashMap<u128, IntervalUnion<usize>>, strokes: HashMap<u128, IntervalUnion<usize>>,
intervals: HashMap<StrokeID, IntervalUnionState<NotNan<f32>>>, intervals: HashMap<StrokeID, IntervalUnionState<NotNan<f32>>>,
......