Skip to content

Commit ab8dfbc

Browse files
committed
Merge IdxSet and IdxSetBuf.
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.
1 parent 04b50e2 commit ab8dfbc

File tree

1 file changed

+5
-88
lines changed

1 file changed

+5
-88
lines changed

src/librustc_data_structures/indexed_set.rs

+5-88
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@
99
// except according to those terms.
1010

1111
use array_vec::ArrayVec;
12-
use std::borrow::{Borrow, BorrowMut, ToOwned};
1312
use std::fmt;
1413
use std::iter;
1514
use std::marker::PhantomData;
1615
use std::mem;
17-
use std::ops::{Deref, DerefMut, Range};
1816
use std::slice;
1917
use bitslice::{BitSlice, Word};
2018
use bitslice::{bitwise, Union, Subtract, Intersect};
2119
use indexed_vec::Idx;
2220
use rustc_serialize;
2321

24-
/// Represents a set (or packed family of sets), of some element type
25-
/// E, where each E is identified by some unique index type `T`.
22+
/// Represents a set of some element type E, where each E is identified by some
23+
/// unique index type `T`.
2624
///
2725
/// In other words, `T` is the type used to index into the bitvector
2826
/// this type uses to represent the set of object it holds.
@@ -34,6 +32,9 @@ pub struct IdxSetBuf<T: Idx> {
3432
bits: Vec<Word>,
3533
}
3634

35+
// FIXME: temporary
36+
pub type IdxSet<T> = IdxSetBuf<T>;
37+
3738
impl<T: Idx> Clone for IdxSetBuf<T> {
3839
fn clone(&self) -> Self {
3940
IdxSetBuf { _pd: PhantomData, bits: self.bits.clone() }
@@ -59,40 +60,6 @@ impl<T: Idx> rustc_serialize::Decodable for IdxSetBuf<T> {
5960
}
6061
}
6162

62-
63-
// pnkfelix wants to have this be `IdxSet<T>([Word]) and then pass
64-
// around `&mut IdxSet<T>` or `&IdxSet<T>`.
65-
66-
/// Represents a set (or packed family of sets), of some element type
67-
/// E, where each E is identified by some unique index type `T`.
68-
///
69-
/// In other words, `T` is the type used to index into the bitslice
70-
/// this type uses to represent the set of object it holds.
71-
#[repr(transparent)]
72-
pub struct IdxSet<T: Idx> {
73-
_pd: PhantomData<fn(&T)>,
74-
bits: [Word],
75-
}
76-
77-
impl<T: Idx> Borrow<IdxSet<T>> for IdxSetBuf<T> {
78-
fn borrow(&self) -> &IdxSet<T> {
79-
&*self
80-
}
81-
}
82-
83-
impl<T: Idx> BorrowMut<IdxSet<T>> for IdxSetBuf<T> {
84-
fn borrow_mut(&mut self) -> &mut IdxSet<T> {
85-
&mut *self
86-
}
87-
}
88-
89-
impl<T: Idx> ToOwned for IdxSet<T> {
90-
type Owned = IdxSetBuf<T>;
91-
fn to_owned(&self) -> Self::Owned {
92-
IdxSet::to_owned(self)
93-
}
94-
}
95-
9663
const BITS_PER_WORD: usize = mem::size_of::<Word>() * 8;
9764

9865
impl<T: Idx> fmt::Debug for IdxSetBuf<T> {
@@ -103,14 +70,6 @@ impl<T: Idx> fmt::Debug for IdxSetBuf<T> {
10370
}
10471
}
10572

106-
impl<T: Idx> fmt::Debug for IdxSet<T> {
107-
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
108-
w.debug_list()
109-
.entries(self.iter())
110-
.finish()
111-
}
112-
}
113-
11473
impl<T: Idx> IdxSetBuf<T> {
11574
fn new(init: Word, universe_size: usize) -> Self {
11675
let num_words = (universe_size + (BITS_PER_WORD - 1)) / BITS_PER_WORD;
@@ -131,38 +90,6 @@ impl<T: Idx> IdxSetBuf<T> {
13190
pub fn new_empty(universe_size: usize) -> Self {
13291
Self::new(0, universe_size)
13392
}
134-
}
135-
136-
impl<T: Idx> IdxSet<T> {
137-
unsafe fn from_slice(s: &[Word]) -> &Self {
138-
&*(s as *const [Word] as *const Self)
139-
}
140-
141-
unsafe fn from_slice_mut(s: &mut [Word]) -> &mut Self {
142-
&mut *(s as *mut [Word] as *mut Self)
143-
}
144-
}
145-
146-
impl<T: Idx> Deref for IdxSetBuf<T> {
147-
type Target = IdxSet<T>;
148-
fn deref(&self) -> &IdxSet<T> {
149-
unsafe { IdxSet::from_slice(&self.bits) }
150-
}
151-
}
152-
153-
impl<T: Idx> DerefMut for IdxSetBuf<T> {
154-
fn deref_mut(&mut self) -> &mut IdxSet<T> {
155-
unsafe { IdxSet::from_slice_mut(&mut self.bits) }
156-
}
157-
}
158-
159-
impl<T: Idx> IdxSet<T> {
160-
pub fn to_owned(&self) -> IdxSetBuf<T> {
161-
IdxSetBuf {
162-
_pd: Default::default(),
163-
bits: self.bits.to_owned(),
164-
}
165-
}
16693

16794
/// Duplicates as a hybrid set.
16895
pub fn to_hybrid(&self) -> HybridIdxSetBuf<T> {
@@ -219,16 +146,6 @@ impl<T: Idx> IdxSet<T> {
219146
self.bits.set_bit(elem.index())
220147
}
221148

222-
pub fn range(&self, elems: &Range<T>) -> &Self {
223-
let elems = elems.start.index()..elems.end.index();
224-
unsafe { Self::from_slice(&self.bits[elems]) }
225-
}
226-
227-
pub fn range_mut(&mut self, elems: &Range<T>) -> &mut Self {
228-
let elems = elems.start.index()..elems.end.index();
229-
unsafe { Self::from_slice_mut(&mut self.bits[elems]) }
230-
}
231-
232149
/// Returns true iff set `self` contains `elem`.
233150
pub fn contains(&self, elem: &T) -> bool {
234151
self.bits.get_bit(elem.index())

0 commit comments

Comments
 (0)