diff --git a/lib/tinyset.rs b/lib/tinyset.rs index 84cb9e281..86ad0bede 100644 --- a/lib/tinyset.rs +++ b/lib/tinyset.rs @@ -1,6 +1,6 @@ extern crate tinyset; -use self::tinyset::u64set; +use self::tinyset::set64; use __std::option2std; use differential_datalog::record::*; use serde; @@ -21,8 +21,8 @@ use flatbuf::{FBIter, FromFlatBuffer, ToFlatBuffer, ToFlatBufferVectorElement}; use flatbuffers as fbrt; #[derive(Eq, Clone, Hash, PartialEq)] -pub struct tinyset_Set64 { - pub x: u64set::Set64, +pub struct tinyset_Set64 { + pub x: set64::Set64, } /* This is needed so we can support for-loops over `Set64`'s. @@ -31,11 +31,11 @@ pub struct tinyset_Set64 { * This can be costly, but is necessary to make sure that all `Set64` * operations are deterministic. */ -pub struct Set64Iter { +pub struct Set64Iter { iter: vec::IntoIter, } -impl Set64Iter { +impl Set64Iter { pub fn new(set: &tinyset_Set64) -> Set64Iter { let mut v: Vec<_> = set.x.iter().collect(); v.sort(); @@ -45,7 +45,7 @@ impl Set64Iter { } } -impl Iterator for Set64Iter { +impl Iterator for Set64Iter { type Item = X; fn next(&mut self) -> Option { @@ -67,12 +67,12 @@ impl tinyset_Set64 { /* In cases when order really, definitely, 100% does not matter, * a more efficient iterator can be used. */ - pub fn unsorted_iter(&self) -> u64set::Iter64 { + pub fn unsorted_iter<'a>(&'a self) -> impl Iterator + 'a { self.x.iter() } } -impl Ord for tinyset_Set64 { +impl Ord for tinyset_Set64 { fn cmp(&self, other: &Self) -> cmp::Ordering { let size_cmp = self.x.len().cmp(&other.x.len()); if size_cmp != cmp::Ordering::Equal { @@ -83,21 +83,21 @@ impl Ord for tinyset_Set64 { } } -impl PartialOrd for tinyset_Set64 { +impl PartialOrd for tinyset_Set64 { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl Default for tinyset_Set64 { +impl Default for tinyset_Set64 { fn default() -> Self { tinyset_Set64 { - x: u64set::Set64::default(), + x: set64::Set64::default(), } } } -impl serde::Serialize for tinyset_Set64 { +impl serde::Serialize for tinyset_Set64 { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -106,7 +106,7 @@ impl serde::Serialize for tinyset_Se } } -impl<'de, T: u64set::Fits64 + serde::Deserialize<'de> + Ord> serde::Deserialize<'de> +impl<'de, T: set64::Fits64 + serde::Deserialize<'de> + Ord> serde::Deserialize<'de> for tinyset_Set64 { fn deserialize(deserializer: D) -> Result @@ -117,10 +117,10 @@ impl<'de, T: u64set::Fits64 + serde::Deserialize<'de> + Ord> serde::Deserialize< } } -impl tinyset_Set64 { +impl tinyset_Set64 { pub fn new() -> Self { tinyset_Set64 { - x: u64set::Set64::new(), + x: set64::Set64::new(), } } pub fn insert(&mut self, v: T) { @@ -131,15 +131,15 @@ impl tinyset_Set64 { } } -impl FromRecord for tinyset_Set64 { +impl FromRecord for tinyset_Set64 { fn from_record(val: &Record) -> Result { vec::Vec::from_record(val).map(|v| tinyset_Set64 { - x: u64set::Set64::from_iter(v), + x: set64::Set64::from_iter(v), }) } } -impl IntoRecord for tinyset_Set64 { +impl IntoRecord for tinyset_Set64 { fn into_record(self) -> Record { Record::Array( CollectionKind::Set, @@ -148,7 +148,7 @@ impl IntoRecord for tinyset_Set64 { } } -impl Mutator> for Record { +impl Mutator> for Record { fn mutate(&self, set: &mut tinyset_Set64) -> Result<(), String> { let upd = >::from_record(self)?; for v in upd.into_iter() { @@ -160,7 +160,7 @@ impl Mutator> for Record } } -impl iter::IntoIterator for &tinyset_Set64 { +impl iter::IntoIterator for &tinyset_Set64 { type Item = T; type IntoIter = Set64Iter; fn into_iter(self) -> Self::IntoIter { @@ -168,18 +168,18 @@ impl iter::IntoIterator for &tinyset_Set64 { } } -impl FromIterator for tinyset_Set64 { +impl FromIterator for tinyset_Set64 { fn from_iter(iter: I) -> Self where I: iter::IntoIterator, { tinyset_Set64 { - x: u64set::Set64::from_iter(iter), + x: set64::Set64::from_iter(iter), } } } -impl fmt::Display for tinyset_Set64 { +impl fmt::Display for tinyset_Set64 { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { let len = self.x.len(); formatter.write_str("[")?; @@ -194,7 +194,7 @@ impl fmt::Display for tinyset_Set64 { } } -impl fmt::Debug for tinyset_Set64 { +impl fmt::Debug for tinyset_Set64 { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { let len = self.x.len(); formatter.write_str("[")?; @@ -212,7 +212,7 @@ impl fmt::Debug for tinyset_Set64 { #[cfg(feature = "flatbuf")] impl<'a, T, F> FromFlatBuffer> for tinyset_Set64 where - T: Ord + FromFlatBuffer + u64set::Fits64, + T: Ord + FromFlatBuffer + set64::Fits64, F: fbrt::Follow<'a> + 'a, { fn from_flatbuf(fb: fbrt::Vector<'a, F>) -> Response { @@ -228,7 +228,7 @@ where #[cfg(feature = "flatbuf")] impl<'a, T> FromFlatBuffer<&'a [T]> for tinyset_Set64 where - T: Ord + u64set::Fits64, + T: Ord + set64::Fits64, { fn from_flatbuf(fb: &'a [T]) -> Response { let mut set = tinyset_Set64::new(); @@ -242,7 +242,7 @@ where #[cfg(feature = "flatbuf")] impl<'b, T> ToFlatBuffer<'b> for tinyset_Set64 where - T: Ord + u64set::Fits64 + ToFlatBufferVectorElement<'b>, + T: Ord + set64::Fits64 + ToFlatBufferVectorElement<'b>, { type Target = fbrt::WIPOffset::Output>>; @@ -255,25 +255,25 @@ where } } -pub fn tinyset_size(s: &tinyset_Set64) -> u64 { +pub fn tinyset_size(s: &tinyset_Set64) -> u64 { s.x.len() as u64 } -pub fn tinyset_empty() -> tinyset_Set64 { +pub fn tinyset_empty() -> tinyset_Set64 { tinyset_Set64::new() } -pub fn tinyset_singleton(v: &X) -> tinyset_Set64 { +pub fn tinyset_singleton(v: &X) -> tinyset_Set64 { let mut s = tinyset_Set64::new(); s.insert(v.clone()); s } -pub fn tinyset_insert(s: &mut tinyset_Set64, v: &X) { +pub fn tinyset_insert(s: &mut tinyset_Set64, v: &X) { s.x.insert((*v).clone()); } -pub fn tinyset_insert_imm( +pub fn tinyset_insert_imm( s: &tinyset_Set64, v: &X, ) -> tinyset_Set64 { @@ -282,28 +282,25 @@ pub fn tinyset_insert_imm( s2 } -pub fn tinyset_contains(s: &tinyset_Set64, v: &X) -> bool { +pub fn tinyset_contains(s: &tinyset_Set64, v: &X) -> bool { s.x.contains(*v) } -pub fn tinyset_is_empty(s: &tinyset_Set64) -> bool { +pub fn tinyset_is_empty(s: &tinyset_Set64) -> bool { s.x.len() == 0 } -pub fn tinyset_nth( - s: &tinyset_Set64, - n: &u64, -) -> std_Option { +pub fn tinyset_nth(s: &tinyset_Set64, n: &u64) -> std_Option { option2std(s.iter().nth(*n as usize)) } -pub fn tinyset_set2vec(s: &tinyset_Set64) -> std_Vec { +pub fn tinyset_set2vec(s: &tinyset_Set64) -> std_Vec { let mut v: Vec<_> = s.x.iter().collect(); v.sort(); std_Vec { x: v } } -pub fn tinyset_union( +pub fn tinyset_union( s1: &tinyset_Set64, s2: &tinyset_Set64, ) -> tinyset_Set64 { @@ -311,10 +308,10 @@ pub fn tinyset_union( tinyset_Set64 { x: s.bitor(&s2.x) } } -pub fn tinyset_unions( +pub fn tinyset_unions( sets: &std_Vec>, ) -> tinyset_Set64 { - let mut s = u64set::Set64::new(); + let mut s = set64::Set64::new(); for si in sets.x.iter() { for v in si.unsorted_iter() { s.insert(v); @@ -323,11 +320,11 @@ pub fn tinyset_unions( tinyset_Set64 { x: s } } -pub fn tinyset_intersection( +pub fn tinyset_intersection( s1: &tinyset_Set64, s2: &tinyset_Set64, ) -> tinyset_Set64 { - let mut s = u64set::Set64::new(); + let mut s = set64::Set64::new(); for v in s1.unsorted_iter() { if s2.x.contains(v) { s.insert(v); @@ -336,7 +333,7 @@ pub fn tinyset_intersection( tinyset_Set64 { x: s } } -pub fn tinyset_difference( +pub fn tinyset_difference( s1: &tinyset_Set64, s2: &tinyset_Set64, ) -> tinyset_Set64 { @@ -345,7 +342,7 @@ pub fn tinyset_difference( } } -pub fn tinyset_group2set(g: &std_Group) -> tinyset_Set64 { +pub fn tinyset_group2set(g: &std_Group) -> tinyset_Set64 { let mut res = tinyset_Set64::new(); for ref v in g.iter() { tinyset_insert(&mut res, v); @@ -353,10 +350,10 @@ pub fn tinyset_group2set(g: &std_Group) -> tinyset_S res } -pub fn tinyset_group_set_unions( +pub fn tinyset_group_set_unions( g: &std_Group>, ) -> tinyset_Set64 { - let mut res = u64set::Set64::new(); + let mut res = set64::Set64::new(); for gr in g.iter() { for v in gr.unsorted_iter() { res.insert(v.clone()); @@ -367,14 +364,14 @@ pub fn tinyset_group_set_unions( tinyset_Set64 { x: res } } -pub fn tinyset_group_setref_unions( +pub fn tinyset_group_setref_unions( g: &std_Group>>, ) -> std_Ref> { if std_group_count(g) == 1 { std_group_first(g) } else { let mut res = std_ref_new(&tinyset_Set64 { - x: u64set::Set64::new(), + x: set64::Set64::new(), }); { let rres = std_Ref::get_mut(&mut res).unwrap(); diff --git a/lib/tinyset.toml b/lib/tinyset.toml index 1a788a280..8d2d127c6 100644 --- a/lib/tinyset.toml +++ b/lib/tinyset.toml @@ -1,2 +1,2 @@ [dependencies.tinyset] -version = "0.2.2" +version = "0.4.3" diff --git a/rust/template/src/main.rs b/rust/template/src/main.rs index 321387ae1..5626c6070 100644 --- a/rust/template/src/main.rs +++ b/rust/template/src/main.rs @@ -29,7 +29,7 @@ use cpuprofiler::PROFILER; #[allow(clippy::let_and_return)] fn handle_cmd( - start_time: &Instant, + start_time: Instant, hddlog: &HDDlog, print_deltas: bool, interactive: bool, @@ -224,7 +224,7 @@ fn run(mut hddlog: HDDlog, print_deltas: bool) -> Result<(), String> { let start_time = Instant::now(); interact(|cmd, interactive| { handle_cmd( - &start_time, + start_time, &hddlog, print_deltas, interactive,