]> git.lizzy.rs Git - rust.git/commitdiff
Merge `IdxSet` and `IdxSetBuf`.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 17 Aug 2018 03:32:11 +0000 (13:32 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Mon, 20 Aug 2018 04:00:51 +0000 (14:00 +1000)
The `Buf` vs. non-`Buf` distinction is no longer necessary, and the
nastiest code in this file can be removed.

To minimize this patch, `IdxSet` is made a typedef of `IdxSetBuf`. The
next patch will remove this typedef.

src/librustc_data_structures/indexed_set.rs

index a7672d1ffe8911595c9bc19f94fc4abed22c2bbd..6c64e5de378078e188d92719225bb09b0c6527ee 100644 (file)
@@ -9,20 +9,18 @@
 // except according to those terms.
 
 use array_vec::ArrayVec;
-use std::borrow::{Borrow, BorrowMut, ToOwned};
 use std::fmt;
 use std::iter;
 use std::marker::PhantomData;
 use std::mem;
-use std::ops::{Deref, DerefMut, Range};
 use std::slice;
 use bitslice::{BitSlice, Word};
 use bitslice::{bitwise, Union, Subtract, Intersect};
 use indexed_vec::Idx;
 use rustc_serialize;
 
-/// Represents a set (or packed family of sets), of some element type
-/// E, where each E is identified by some unique index type `T`.
+/// Represents a set of some element type E, where each E is identified by some
+/// unique index type `T`.
 ///
 /// In other words, `T` is the type used to index into the bitvector
 /// this type uses to represent the set of object it holds.
@@ -34,6 +32,9 @@ pub struct IdxSetBuf<T: Idx> {
     bits: Vec<Word>,
 }
 
+// FIXME: temporary
+pub type IdxSet<T> = IdxSetBuf<T>;
+
 impl<T: Idx> Clone for IdxSetBuf<T> {
     fn clone(&self) -> Self {
         IdxSetBuf { _pd: PhantomData, bits: self.bits.clone() }
@@ -59,40 +60,6 @@ fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<IdxSetBuf<T>, D::Err
     }
 }
 
-
-// pnkfelix wants to have this be `IdxSet<T>([Word]) and then pass
-// around `&mut IdxSet<T>` or `&IdxSet<T>`.
-
-/// Represents a set (or packed family of sets), of some element type
-/// E, where each E is identified by some unique index type `T`.
-///
-/// In other words, `T` is the type used to index into the bitslice
-/// this type uses to represent the set of object it holds.
-#[repr(transparent)]
-pub struct IdxSet<T: Idx> {
-    _pd: PhantomData<fn(&T)>,
-    bits: [Word],
-}
-
-impl<T: Idx> Borrow<IdxSet<T>> for IdxSetBuf<T> {
-    fn borrow(&self) -> &IdxSet<T> {
-        &*self
-    }
-}
-
-impl<T: Idx> BorrowMut<IdxSet<T>> for IdxSetBuf<T> {
-    fn borrow_mut(&mut self) -> &mut IdxSet<T> {
-        &mut *self
-    }
-}
-
-impl<T: Idx> ToOwned for IdxSet<T> {
-    type Owned = IdxSetBuf<T>;
-    fn to_owned(&self) -> Self::Owned {
-        IdxSet::to_owned(self)
-    }
-}
-
 const BITS_PER_WORD: usize = mem::size_of::<Word>() * 8;
 
 impl<T: Idx> fmt::Debug for IdxSetBuf<T> {
@@ -103,14 +70,6 @@ fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-impl<T: Idx> fmt::Debug for IdxSet<T> {
-    fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
-        w.debug_list()
-         .entries(self.iter())
-         .finish()
-    }
-}
-
 impl<T: Idx> IdxSetBuf<T> {
     fn new(init: Word, universe_size: usize) -> Self {
         let num_words = (universe_size + (BITS_PER_WORD - 1)) / BITS_PER_WORD;
@@ -131,38 +90,6 @@ pub fn new_filled(universe_size: usize) -> Self {
     pub fn new_empty(universe_size: usize) -> Self {
         Self::new(0, universe_size)
     }
-}
-
-impl<T: Idx> IdxSet<T> {
-    unsafe fn from_slice(s: &[Word]) -> &Self {
-        &*(s as *const [Word] as *const Self)
-    }
-
-    unsafe fn from_slice_mut(s: &mut [Word]) -> &mut Self {
-        &mut *(s as *mut [Word] as *mut Self)
-    }
-}
-
-impl<T: Idx> Deref for IdxSetBuf<T> {
-    type Target = IdxSet<T>;
-    fn deref(&self) -> &IdxSet<T> {
-        unsafe { IdxSet::from_slice(&self.bits) }
-    }
-}
-
-impl<T: Idx> DerefMut for IdxSetBuf<T> {
-    fn deref_mut(&mut self) -> &mut IdxSet<T> {
-        unsafe { IdxSet::from_slice_mut(&mut self.bits) }
-    }
-}
-
-impl<T: Idx> IdxSet<T> {
-    pub fn to_owned(&self) -> IdxSetBuf<T> {
-        IdxSetBuf {
-            _pd: Default::default(),
-            bits: self.bits.to_owned(),
-        }
-    }
 
     /// Duplicates as a hybrid set.
     pub fn to_hybrid(&self) -> HybridIdxSetBuf<T> {
@@ -219,16 +146,6 @@ pub fn add(&mut self, elem: &T) -> bool {
         self.bits.set_bit(elem.index())
     }
 
-    pub fn range(&self, elems: &Range<T>) -> &Self {
-        let elems = elems.start.index()..elems.end.index();
-        unsafe { Self::from_slice(&self.bits[elems]) }
-    }
-
-    pub fn range_mut(&mut self, elems: &Range<T>) -> &mut Self {
-        let elems = elems.start.index()..elems.end.index();
-        unsafe { Self::from_slice_mut(&mut self.bits[elems]) }
-    }
-
     /// Returns true iff set `self` contains `elem`.
     pub fn contains(&self, elem: &T) -> bool {
         self.bits.get_bit(elem.index())