Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constructor with site id #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ impl Counter {

/// Constructs and returns a new Counter with site id 1.
pub fn new(value: i64) -> Self {
let site_id = 1;
Self::new_with_id(value,1)
}

/// Constructs and returns a new Counter with the given site id.
pub fn new_with_id(value: i64, site_id: u32) -> Self {
let inner = CounterInner::new(value, site_id);
Counter{inner, site_id, awaiting_site_id: None}
}
Expand Down
6 changes: 5 additions & 1 deletion src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ impl<T: Clone> List<T> {

/// Constructs and returns a new List with site id 1.
pub fn new() -> Self {
Self::new_with_id(1)
}

/// Constructs and returns a new List with the given site id.
pub fn new_with_id(site_id: u32) -> Self {
let inner = Inner::new();
let summary = Summary::default();
let site_id = 1;
List{inner, summary, site_id, cached_ops: vec![]}
}

Expand Down
6 changes: 5 additions & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ impl<K: Key, V: Value> Map<K, V> {
/// Constructs and returns a new map.
/// The map has site id 1.
pub fn new() -> Self {
Self::new_with_id(1)
}

/// Constructs and returns a new map with the given site id.
pub fn new_with_id(site_id: u32) -> Self {
let inner = Inner::new();
let summary = Summary::default();
let site_id = 1;
Map{inner, summary, site_id, cached_ops: vec![]}
}

Expand Down
6 changes: 5 additions & 1 deletion src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ impl<T: Clone> Register<T> {

/// Constructs and returns a new `Register` with site id 1.
pub fn new(value: T) -> Self {
let site_id = 1;
Self::new_with_id(value,1)
}

/// Constructs and returns a new `Register` with the given site id.
pub fn new_with_id(value: T, site_id: u32) -> Self {
let counter = 1;
let mut elements = BTreeMap::new();
let mut summary = Summary::default();
Expand Down
6 changes: 5 additions & 1 deletion src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ impl<T: SetElement> Set<T> {
/// Constructs and returns a new set CRDT.
/// The set has site 1 and counter 0.
pub fn new() -> Self {
Self::new_with_id(1)
}

/// Constructs and returns a new set CRDT with the given site id.
pub fn new_with_id(site_id: u32) -> Self {
let inner = Inner::new();
let summary = Summary::default();
let site_id = 1;
Set{inner, summary, site_id, cached_ops: vec![]}
}

Expand Down
6 changes: 5 additions & 1 deletion src/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ pub struct Op {
impl Text {
/// Constructs and returns a new Text CRDT with site id 1.
pub fn new() -> Self {
Self::new_with_id(1)
}

/// Constructs and returns a new Text CRDT with the given site id.
pub fn new_with_id(site_id: u32) -> Self {
let inner = Inner::new();
let summary = Summary::default();
let site_id = 1;
Text{inner, summary, site_id, cached_ops: vec![]}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ fn test_new() {
assert_eq!(counter.site_id(), 1);
}

#[test]
fn test_new_with_id() {
let counter = Counter::new_with_id(4012, 5);
assert_eq!(counter.site_id(), 5);
}

#[test]
fn test_increment() {
let mut counter = Counter::new(0);
Expand Down
7 changes: 7 additions & 0 deletions tests/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ use ditto::list::*;
#[test]
fn test_new() {
let list: List<i64> = List::new();
assert_eq!(list.site_id(), 1);
assert_eq!(list.len(), 0);
}

#[test]
fn test_new_with_id() {
let list: List<i64> = List::new_with_id(5);
assert_eq!(list.site_id(), 5);
}

#[test]
fn test_get() {
let mut list: List<i64> = List::new();
Expand Down
6 changes: 6 additions & 0 deletions tests/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ fn test_new() {
assert_eq!(map.summary().get(1), 0);
}

#[test]
fn test_new_with_id() {
let map: Map<i64, bool> = Map::new_with_id(5);
assert_eq!(map.site_id(), 5);
}

#[test]
fn test_contains_key() {
let mut map: Map<usize, isize> = Map::new();
Expand Down
6 changes: 6 additions & 0 deletions tests/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ fn test_new() {
assert_eq!(register.summary().get(1), 1);
}

#[test]
fn test_new_with_id() {
let register = Register::new_with_id(8142i64,5);
assert_eq!(register.site_id(), 5);
}

#[test]
fn test_update() {
let mut register = Register::new(8142i64);
Expand Down
6 changes: 6 additions & 0 deletions tests/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ fn test_new() {
assert_eq!(set.summary().get(1), 0);
}

#[test]
fn test_new_with_id() {
let set: Set<u8> = Set::new_with_id(5);
assert_eq!(set.site_id(), 5);
}

#[test]
fn test_contains() {
let mut set: Set<u8> = Set::new();
Expand Down
7 changes: 7 additions & 0 deletions tests/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ use ditto::text::*;
#[test]
fn test_new() {
let text = Text::new();
assert_eq!(text.site_id(), 1);
assert_eq!(text.len(), 0);
assert_eq!(text.local_value(), "");
}

#[test]
fn test_new_with_id() {
let text = Text::new_with_id(5);
assert_eq!(text.site_id(), 5);
}

#[test]
fn test_replace() {
let mut text = Text::new();
Expand Down