Skip to content
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
24 changes: 12 additions & 12 deletions ascent/src/c_lat_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ pub enum CLatIndex<K, V> {
impl<K: Clone + Hash + Eq, V: Clone + Hash + Eq> Freezable for CLatIndex<K, V> {
fn freeze(&mut self) {
update(self, |_self| match _self {
CLatIndex::Unfrozen(dm) => Self::Frozen(dm.into_read_only()),
CLatIndex::Frozen(_) => _self,
Self::Unfrozen(dm) => Self::Frozen(dm.into_read_only()),
Self::Frozen(_) => _self,
})
}

fn unfreeze(&mut self) {
update(self, |_self| match _self {
CLatIndex::Frozen(v) => Self::Unfrozen(v.into_inner()),
CLatIndex::Unfrozen(_) => _self,
Self::Frozen(v) => Self::Unfrozen(v.into_inner()),
Self::Unfrozen(_) => _self,
})
}
}
Expand All @@ -38,31 +38,31 @@ impl<K: Clone + Hash + Eq, V: Clone + Hash + Eq> CLatIndex<K, V> {
#[inline]
pub fn unwrap_frozen(&self) -> &dashmap::ReadOnlyView<K, SetType<V>, BuildHasherDefault<FxHasher>> {
match self {
CLatIndex::Frozen(v) => v,
CLatIndex::Unfrozen(_) => panic!("CRelIndex::unwrap_frozen(): object is Unfrozen"),
Self::Frozen(v) => v,
Self::Unfrozen(_) => panic!("CRelIndex::unwrap_frozen(): object is Unfrozen"),
}
}

#[inline]
pub fn unwrap_unfrozen(&self) -> &DashMap<K, SetType<V>, BuildHasherDefault<FxHasher>> {
match self {
CLatIndex::Unfrozen(dm) => dm,
CLatIndex::Frozen(_) => panic!("CRelIndex::unwrap_unfrozen(): object is Frozen"),
Self::Unfrozen(dm) => dm,
Self::Frozen(_) => panic!("CRelIndex::unwrap_unfrozen(): object is Frozen"),
}
}

#[inline]
pub fn unwrap_mut_unfrozen(&mut self) -> &mut DashMap<K, SetType<V>, BuildHasherDefault<FxHasher>> {
match self {
CLatIndex::Unfrozen(dm) => dm,
CLatIndex::Frozen(_) => panic!("CRelIndex::unwrap_unfrozen(): object is Frozen"),
Self::Unfrozen(dm) => dm,
Self::Frozen(_) => panic!("CRelIndex::unwrap_unfrozen(): object is Frozen"),
}
}

pub fn into_read_only(self) -> dashmap::ReadOnlyView<K, SetType<V>, BuildHasherDefault<FxHasher>> {
match self {
CLatIndex::Unfrozen(dm) => dm.into_read_only(),
CLatIndex::Frozen(f) => f,
Self::Unfrozen(dm) => dm.into_read_only(),
Self::Frozen(f) => f,
}
}

Expand Down
32 changes: 16 additions & 16 deletions ascent/src/c_rel_full_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,55 @@ pub enum CRelFullIndex<K, V> {
impl<K: Clone + Hash + Eq, V> Freezable for CRelFullIndex<K, V> {
fn freeze(&mut self) {
update(self, |_self| match _self {
CRelFullIndex::Unfrozen(dm) => Self::Frozen(dm.into_read_only()),
CRelFullIndex::Frozen(_) => _self,
Self::Unfrozen(dm) => Self::Frozen(dm.into_read_only()),
Self::Frozen(_) => _self,
})
}

fn unfreeze(&mut self) {
update(self, |_self| match _self {
CRelFullIndex::Frozen(v) => Self::Unfrozen(v.into_inner()),
CRelFullIndex::Unfrozen(dm) => CRelFullIndex::Unfrozen(dm),
Self::Frozen(v) => Self::Unfrozen(v.into_inner()),
Self::Unfrozen(dm) => Self::Unfrozen(dm),
})
}
}

impl<K: Clone + Hash + Eq, V> CRelFullIndex<K, V> {
pub fn exact_len(&self) -> usize {
match self {
CRelFullIndex::Unfrozen(uf) => uf.len(),
CRelFullIndex::Frozen(f) => f.len(),
Self::Unfrozen(uf) => uf.len(),
Self::Frozen(f) => f.len(),
}
}

#[inline]
pub fn unwrap_frozen(&self) -> &dashmap::ReadOnlyView<K, V, BuildHasherDefault<FxHasher>> {
match self {
CRelFullIndex::Frozen(v) => v,
CRelFullIndex::Unfrozen(_) => panic!("CRelFullIndex::unwrap_frozen(): object is Unfrozen"),
Self::Frozen(v) => v,
Self::Unfrozen(_) => panic!("CRelFullIndex::unwrap_frozen(): object is Unfrozen"),
}
}

#[inline]
pub fn unwrap_unfrozen(&self) -> &DashMap<K, V, BuildHasherDefault<FxHasher>> {
match self {
CRelFullIndex::Unfrozen(dm) => dm,
CRelFullIndex::Frozen(_) => panic!("CRelFullIndex::unwrap_unfrozen(): object is Frozen"),
Self::Unfrozen(dm) => dm,
Self::Frozen(_) => panic!("CRelFullIndex::unwrap_unfrozen(): object is Frozen"),
}
}

#[inline]
pub fn unwrap_mut_unfrozen(&mut self) -> &mut DashMap<K, V, BuildHasherDefault<FxHasher>> {
match self {
CRelFullIndex::Frozen(_) => panic!("CRelFullIndex::unwrap_mut_unfrozen(): object is Frozen"),
CRelFullIndex::Unfrozen(dm) => dm,
Self::Frozen(_) => panic!("CRelFullIndex::unwrap_mut_unfrozen(): object is Frozen"),
Self::Unfrozen(dm) => dm,
}
}

pub fn into_read_only(self) -> dashmap::ReadOnlyView<K, V, BuildHasherDefault<FxHasher>> {
match self {
CRelFullIndex::Unfrozen(dm) => dm.into_read_only(),
CRelFullIndex::Frozen(f) => f,
Self::Unfrozen(dm) => dm.into_read_only(),
Self::Frozen(f) => f,
}
}

Expand All @@ -79,8 +79,8 @@ impl<K: Clone + Hash + Eq, V> CRelFullIndex<K, V> {
pub fn get_cloned(&self, key: &K) -> Option<V>
where V: Clone {
match self {
CRelFullIndex::Unfrozen(uf) => uf.get(key).map(|x| x.value().clone()),
CRelFullIndex::Frozen(f) => f.get(key).cloned(),
Self::Unfrozen(uf) => uf.get(key).map(|x| x.value().clone()),
Self::Frozen(f) => f.get(key).cloned(),
}
}

Expand Down
24 changes: 12 additions & 12 deletions ascent/src/c_rel_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ pub enum CRelIndex<K, V> {
impl<K: Clone + Hash + Eq, V> Freezable for CRelIndex<K, V> {
fn freeze(&mut self) {
update(self, |_self| match _self {
CRelIndex::Unfrozen(dm) => Self::Frozen(dm.into_read_only()),
CRelIndex::Frozen(_) => _self,
Self::Unfrozen(dm) => Self::Frozen(dm.into_read_only()),
Self::Frozen(_) => _self,
})
}

fn unfreeze(&mut self) {
update(self, |_self| match _self {
CRelIndex::Frozen(v) => Self::Unfrozen(v.into_inner()),
CRelIndex::Unfrozen(_) => _self,
Self::Frozen(v) => Self::Unfrozen(v.into_inner()),
Self::Unfrozen(_) => _self,
})
}
}
Expand All @@ -39,31 +39,31 @@ impl<K: Clone + Hash + Eq, V> CRelIndex<K, V> {
#[inline]
pub fn unwrap_frozen(&self) -> &dashmap::ReadOnlyView<K, VecType<V>, BuildHasherDefault<FxHasher>> {
match self {
CRelIndex::Frozen(v) => v,
CRelIndex::Unfrozen(_) => panic!("CRelIndex::unwrap_frozen(): object is Unfrozen"),
Self::Frozen(v) => v,
Self::Unfrozen(_) => panic!("CRelIndex::unwrap_frozen(): object is Unfrozen"),
}
}

#[inline]
pub fn unwrap_unfrozen(&self) -> &DashMap<K, VecType<V>, BuildHasherDefault<FxHasher>> {
match self {
CRelIndex::Unfrozen(dm) => dm,
CRelIndex::Frozen(_) => panic!("CRelIndex::unwrap_unfrozen(): object is Frozen"),
Self::Unfrozen(dm) => dm,
Self::Frozen(_) => panic!("CRelIndex::unwrap_unfrozen(): object is Frozen"),
}
}

#[inline]
pub fn unwrap_mut_unfrozen(&mut self) -> &mut DashMap<K, VecType<V>, BuildHasherDefault<FxHasher>> {
match self {
CRelIndex::Unfrozen(dm) => dm,
CRelIndex::Frozen(_) => panic!("CRelIndex::unwrap_unfrozen(): object is Frozen"),
Self::Unfrozen(dm) => dm,
Self::Frozen(_) => panic!("CRelIndex::unwrap_unfrozen(): object is Frozen"),
}
}

pub fn into_read_only(self) -> dashmap::ReadOnlyView<K, VecType<V>, BuildHasherDefault<FxHasher>> {
match self {
CRelIndex::Unfrozen(dm) => dm.into_read_only(),
CRelIndex::Frozen(f) => f,
Self::Unfrozen(dm) => dm.into_read_only(),
Self::Frozen(f) => f,
}
}

Expand Down
4 changes: 2 additions & 2 deletions ascent/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<K: Eq + Hash, V> RelIndexWrite for RelIndexType1<K, V> {
}

impl<K: Eq + Hash, V> RelIndexMerge for RelIndexType1<K, V> {
fn move_index_contents(from: &mut RelIndexType1<K, V>, to: &mut RelIndexType1<K, V>) {
fn move_index_contents(from: &mut Self, to: &mut Self) {
let before = Instant::now();
if from.len() > to.len() {
std::mem::swap(from, to);
Expand Down Expand Up @@ -161,7 +161,7 @@ impl<K: Eq + Hash, V: Hash + Eq> RelIndexWrite for LatticeIndexType<K, V> {

impl<K: Eq + Hash, V: Hash + Eq> RelIndexMerge for LatticeIndexType<K, V> {
#[inline(always)]
fn move_index_contents(hm1: &mut LatticeIndexType<K, V>, hm2: &mut LatticeIndexType<K, V>) {
fn move_index_contents(hm1: &mut Self, hm2: &mut Self) {
for (k, v) in hm1.drain() {
let set = hm2.entry(k).or_default();
set.extend(v);
Expand Down
16 changes: 8 additions & 8 deletions ascent_base/src/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl<T: Lattice + Clone> Lattice for Rc<T> {
},
// Stable in 1.76:
// None => Rc::make_mut(self).meet_mut(Rc::unwrap_or_clone(other))
None => Rc::make_mut(self).meet_mut(Rc::try_unwrap(other).unwrap_or_else(|rc| (*rc).clone())),
None => Self::make_mut(self).meet_mut(Self::try_unwrap(other).unwrap_or_else(|rc| (*rc).clone())),
}
}

Expand All @@ -156,7 +156,7 @@ impl<T: Lattice + Clone> Lattice for Rc<T> {
},
// Stable in 1.76:
// None => Rc::make_mut(self).join_mut(Rc::unwrap_or_clone(other))
None => Rc::make_mut(self).join_mut(Rc::try_unwrap(other).unwrap_or_else(|rc| (*rc).clone())),
None => Self::make_mut(self).join_mut(Self::try_unwrap(other).unwrap_or_else(|rc| (*rc).clone())),
}
}
}
Expand All @@ -171,7 +171,7 @@ impl<T: Lattice + Clone> Lattice for Arc<T> {
},
// Stable in 1.76:
// None => Arc::make_mut(self).meet_mut(Arc::unwrap_or_clone(other))
None => Arc::make_mut(self).meet_mut(Arc::try_unwrap(other).unwrap_or_else(|rc| (*rc).clone())),
None => Self::make_mut(self).meet_mut(Self::try_unwrap(other).unwrap_or_else(|rc| (*rc).clone())),
}
}

Expand All @@ -184,7 +184,7 @@ impl<T: Lattice + Clone> Lattice for Arc<T> {
},
// Stable in 1.76:
// None => Arc::make_mut(self).join_mut(Arc::unwrap_or_clone(other))
None => Arc::make_mut(self).join_mut(Arc::try_unwrap(other).unwrap_or_else(|rc| (*rc).clone())),
None => Self::make_mut(self).join_mut(Self::try_unwrap(other).unwrap_or_else(|rc| (*rc).clone())),
}
}
}
Expand All @@ -197,10 +197,10 @@ impl<T: Lattice + Sized> Lattice for Box<T> {

impl<T: Lattice> Lattice for Reverse<T> {
#[inline]
fn meet(self, other: Self) -> Self { Reverse(self.0.join(other.0)) }
fn meet(self, other: Self) -> Self { Self(self.0.join(other.0)) }

#[inline]
fn join(self, other: Self) -> Self { Reverse(self.0.meet(other.0)) }
fn join(self, other: Self) -> Self { Self(self.0.meet(other.0)) }

#[inline]
fn meet_mut(&mut self, other: Self) -> bool { self.0.join_mut(other.0) }
Expand All @@ -211,10 +211,10 @@ impl<T: Lattice> Lattice for Reverse<T> {

impl<T: BoundedLattice> BoundedLattice for Reverse<T> {
#[inline]
fn bottom() -> Self { Reverse(T::top()) }
fn bottom() -> Self { Self(T::top()) }

#[inline]
fn top() -> Self { Reverse(T::bottom()) }
fn top() -> Self { Self(T::bottom()) }
}

#[cfg(test)]
Expand Down
22 changes: 11 additions & 11 deletions ascent_base/src/lattice/bounded_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ impl<const BOUND: usize, T: PartialEq + Eq + Hash + Ord> Default for BoundedSet<

impl<const BOUND: usize, T: PartialEq + Eq + Hash + Ord> BoundedSet<BOUND, T> {
/// A set containing everything
pub const TOP: Self = BoundedSet(None);
pub const TOP: Self = Self(None);

/// Creates an empty `BoundedSet`
pub fn new() -> Self { BoundedSet(Some(Set::default())) }
pub fn new() -> Self { Self(Some(Set::default())) }

/// Creates a `BoundedSet` containing only `item`
pub fn singleton(item: T) -> Self { Self::from_set(Set::singleton(item)) }

/// Creates a `BoundedSet` from a `Set`, ensuring the `BOUND` is not exceeded
pub fn from_set(set: Set<T>) -> Self { if set.len() <= BOUND { BoundedSet(Some(set)) } else { BoundedSet(None) } }
pub fn from_set(set: Set<T>) -> Self { if set.len() <= BOUND { Self(Some(set)) } else { Self(None) } }

/// Returns the size of the set. In case of the set being `TOP`, returns `None`
pub fn count(&self) -> Option<usize> { self.0.as_ref().map(|s| s.len()) }
Expand Down Expand Up @@ -86,23 +86,23 @@ impl<const BOUND: usize, T: PartialEq + Eq + Hash + Ord> Lattice for BoundedSet<
}
fn meet(self, other: Self) -> Self {
match (self.0, other.0) {
(None, None) => BoundedSet(None),
(None, set2 @ Some(_)) => BoundedSet(set2),
(set1 @ Some(_), None) => BoundedSet(set1),
(None, None) => Self(None),
(None, set2 @ Some(_)) => Self(set2),
(set1 @ Some(_), None) => Self(set1),
(Some(set1), Some(set2)) => {
let res = set1.meet(set2);
BoundedSet(Some(res))
Self(Some(res))
},
}
}

fn join(self, other: Self) -> Self {
match (self.0, other.0) {
(None, _) => BoundedSet(None),
(_, None) => BoundedSet(None),
(None, _) => Self(None),
(_, None) => Self(None),
(Some(set1), Some(set2)) => {
let res = set1.join(set2);
if res.len() > BOUND { BoundedSet(None) } else { BoundedSet(Some(res)) }
if res.len() > BOUND { Self(None) } else { Self(Some(res)) }
},
}
}
Expand All @@ -112,7 +112,7 @@ impl<const BOUND: usize, T: PartialEq + Eq + Hash + Ord> BoundedLattice for Boun
fn bottom() -> Self { Self::new() }

/// top is meant to represent a set containing everything
fn top() -> Self { BoundedSet(None) }
fn top() -> Self { Self(None) }
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion ascent_base/src/lattice/constant_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<T: PartialEq> Lattice for ConstPropagation<T> {
}

impl<T: Lattice> BoundedLattice for ConstPropagation<T>
where ConstPropagation<T>: Lattice
where Self: Lattice
{
fn top() -> Self { Self::Top }
fn bottom() -> Self { Self::Bottom }
Expand Down
8 changes: 4 additions & 4 deletions ascent_base/src/lattice/dual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ where T: Ord

impl<T: Lattice> Lattice for Dual<T> {
#[inline]
fn meet(self, other: Self) -> Self { Dual(self.0.join(other.0)) }
fn meet(self, other: Self) -> Self { Self(self.0.join(other.0)) }

#[inline]
fn join(self, other: Self) -> Self { Dual(self.0.meet(other.0)) }
fn join(self, other: Self) -> Self { Self(self.0.meet(other.0)) }

#[inline]
fn meet_mut(&mut self, other: Self) -> bool { self.0.join_mut(other.0) }
Expand All @@ -59,8 +59,8 @@ impl<T: Lattice> Lattice for Dual<T> {

impl<T: BoundedLattice> BoundedLattice for Dual<T> {
#[inline]
fn top() -> Self { Dual(T::bottom()) }
fn top() -> Self { Self(T::bottom()) }

#[inline]
fn bottom() -> Self { Dual(T::top()) }
fn bottom() -> Self { Self(T::top()) }
}
4 changes: 2 additions & 2 deletions ascent_base/src/lattice/product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ impl<const N: usize, T: BoundedLattice> BoundedLattice for Product<[T; N]> {
fn bottom() -> Self {
// unstable:
// Product(std::array::from_fn(|_| T::bottom()))
Product([(); N].map(|_| T::bottom()))
Self([(); N].map(|_| T::bottom()))
}

fn top() -> Self { Product([(); N].map(|_| T::top())) }
fn top() -> Self { Self([(); N].map(|_| T::top())) }
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion ascent_base/src/lattice/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<T: PartialEq + Eq + Hash + Ord> Set<T> {
pub fn singleton(item: T) -> Self {
let mut set = BTreeSet::new();
set.insert(item);
Set(set)
Self(set)
}
}

Expand Down
Loading