9
9
// except according to those terms.
10
10
11
11
use array_vec:: ArrayVec ;
12
- use std:: borrow:: { Borrow , BorrowMut , ToOwned } ;
13
12
use std:: fmt;
14
13
use std:: iter;
15
14
use std:: marker:: PhantomData ;
16
15
use std:: mem;
17
- use std:: ops:: { Deref , DerefMut , Range } ;
18
16
use std:: slice;
19
17
use bitslice:: { BitSlice , Word } ;
20
18
use bitslice:: { bitwise, Union , Subtract , Intersect } ;
21
19
use indexed_vec:: Idx ;
22
20
use rustc_serialize;
23
21
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`.
26
24
///
27
25
/// In other words, `T` is the type used to index into the bitvector
28
26
/// this type uses to represent the set of object it holds.
@@ -34,6 +32,9 @@ pub struct IdxSetBuf<T: Idx> {
34
32
bits : Vec < Word > ,
35
33
}
36
34
35
+ // FIXME: temporary
36
+ pub type IdxSet < T > = IdxSetBuf < T > ;
37
+
37
38
impl < T : Idx > Clone for IdxSetBuf < T > {
38
39
fn clone ( & self ) -> Self {
39
40
IdxSetBuf { _pd : PhantomData , bits : self . bits . clone ( ) }
@@ -59,40 +60,6 @@ impl<T: Idx> rustc_serialize::Decodable for IdxSetBuf<T> {
59
60
}
60
61
}
61
62
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
-
96
63
const BITS_PER_WORD : usize = mem:: size_of :: < Word > ( ) * 8 ;
97
64
98
65
impl < T : Idx > fmt:: Debug for IdxSetBuf < T > {
@@ -103,14 +70,6 @@ impl<T: Idx> fmt::Debug for IdxSetBuf<T> {
103
70
}
104
71
}
105
72
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
-
114
73
impl < T : Idx > IdxSetBuf < T > {
115
74
fn new ( init : Word , universe_size : usize ) -> Self {
116
75
let num_words = ( universe_size + ( BITS_PER_WORD - 1 ) ) / BITS_PER_WORD ;
@@ -131,38 +90,6 @@ impl<T: Idx> IdxSetBuf<T> {
131
90
pub fn new_empty ( universe_size : usize ) -> Self {
132
91
Self :: new ( 0 , universe_size)
133
92
}
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
- }
166
93
167
94
/// Duplicates as a hybrid set.
168
95
pub fn to_hybrid ( & self ) -> HybridIdxSetBuf < T > {
@@ -219,16 +146,6 @@ impl<T: Idx> IdxSet<T> {
219
146
self . bits . set_bit ( elem. index ( ) )
220
147
}
221
148
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
-
232
149
/// Returns true iff set `self` contains `elem`.
233
150
pub fn contains ( & self , elem : & T ) -> bool {
234
151
self . bits . get_bit ( elem. index ( ) )
0 commit comments