@@ -18,6 +18,7 @@ use core::iter::{Enumerate, Repeat, Map, Zip};
18
18
use core:: ops;
19
19
use core:: slice;
20
20
use core:: uint;
21
+ use std:: hash;
21
22
22
23
use vec:: Vec ;
23
24
@@ -34,12 +35,12 @@ fn small_mask(nbits: uint) -> uint {
34
35
}
35
36
36
37
impl SmallBitv {
37
- pub fn new ( bits : uint ) -> SmallBitv {
38
+ fn new ( bits : uint ) -> SmallBitv {
38
39
SmallBitv { bits : bits}
39
40
}
40
41
41
42
#[ inline]
42
- pub fn bits_op ( & mut self ,
43
+ fn bits_op ( & mut self ,
43
44
right_bits : uint ,
44
45
nbits : uint ,
45
46
f : |uint , uint| -> uint)
@@ -52,32 +53,32 @@ impl SmallBitv {
52
53
}
53
54
54
55
#[ inline]
55
- pub fn union ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
56
+ fn union ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
56
57
self . bits_op ( s. bits , nbits, |u1, u2| u1 | u2)
57
58
}
58
59
59
60
#[ inline]
60
- pub fn intersect ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
61
+ fn intersect ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
61
62
self . bits_op ( s. bits , nbits, |u1, u2| u1 & u2)
62
63
}
63
64
64
65
#[ inline]
65
- pub fn become ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
66
+ fn become ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
66
67
self . bits_op ( s. bits , nbits, |_u1, u2| u2)
67
68
}
68
69
69
70
#[ inline]
70
- pub fn difference ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
71
+ fn difference ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
71
72
self . bits_op ( s. bits , nbits, |u1, u2| u1 & !u2)
72
73
}
73
74
74
75
#[ inline]
75
- pub fn get ( & self , i : uint ) -> bool {
76
+ fn get ( & self , i : uint ) -> bool {
76
77
( self . bits & ( 1 << i) ) != 0
77
78
}
78
79
79
80
#[ inline]
80
- pub fn set ( & mut self , i : uint , x : bool ) {
81
+ fn set ( & mut self , i : uint , x : bool ) {
81
82
if x {
82
83
self . bits |= 1 <<i;
83
84
}
@@ -87,29 +88,29 @@ impl SmallBitv {
87
88
}
88
89
89
90
#[ inline]
90
- pub fn equals ( & self , b : & SmallBitv , nbits : uint ) -> bool {
91
+ fn equals ( & self , b : & SmallBitv , nbits : uint ) -> bool {
91
92
let mask = small_mask ( nbits) ;
92
93
mask & self . bits == mask & b. bits
93
94
}
94
95
95
96
#[ inline]
96
- pub fn clear ( & mut self ) { self . bits = 0 ; }
97
+ fn clear ( & mut self ) { self . bits = 0 ; }
97
98
98
99
#[ inline]
99
- pub fn set_all ( & mut self ) { self . bits = !0 ; }
100
+ fn set_all ( & mut self ) { self . bits = !0 ; }
100
101
101
102
#[ inline]
102
- pub fn all ( & self , nbits : uint ) -> bool {
103
+ fn all ( & self , nbits : uint ) -> bool {
103
104
small_mask ( nbits) & !self . bits == 0
104
105
}
105
106
106
107
#[ inline]
107
- pub fn none ( & self , nbits : uint ) -> bool {
108
+ fn none ( & self , nbits : uint ) -> bool {
108
109
small_mask ( nbits) & self . bits == 0
109
110
}
110
111
111
112
#[ inline]
112
- pub fn negate ( & mut self ) { self . bits = !self . bits ; }
113
+ fn negate ( & mut self ) { self . bits = !self . bits ; }
113
114
}
114
115
115
116
#[ deriving( Clone ) ]
@@ -134,12 +135,12 @@ fn big_mask(nbits: uint, elem: uint) -> uint {
134
135
}
135
136
136
137
impl BigBitv {
137
- pub fn new ( storage : Vec < uint > ) -> BigBitv {
138
+ fn new ( storage : Vec < uint > ) -> BigBitv {
138
139
BigBitv { storage : storage}
139
140
}
140
141
141
142
#[ inline]
142
- pub fn process ( & mut self ,
143
+ fn process ( & mut self ,
143
144
b : & BigBitv ,
144
145
nbits : uint ,
145
146
op : |uint , uint| -> uint)
@@ -163,45 +164,45 @@ impl BigBitv {
163
164
}
164
165
165
166
#[ inline]
166
- pub fn each_storage ( & mut self , op: |v: & mut uint | -> bool ) -> bool {
167
+ fn each_storage ( & mut self , op: |v: & mut uint | -> bool ) -> bool {
167
168
self . storage . mut_iter ( ) . advance ( |elt| op ( elt) )
168
169
}
169
170
170
171
#[ inline]
171
- pub fn negate ( & mut self ) {
172
+ fn negate ( & mut self ) {
172
173
self . each_storage ( |w| { * w = !* w; true } ) ;
173
174
}
174
175
175
176
#[ inline]
176
- pub fn union ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
177
+ fn union ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
177
178
self . process ( b, nbits, |w1, w2| w1 | w2)
178
179
}
179
180
180
181
#[ inline]
181
- pub fn intersect ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
182
+ fn intersect ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
182
183
self . process ( b, nbits, |w1, w2| w1 & w2)
183
184
}
184
185
185
186
#[ inline]
186
- pub fn become ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
187
+ fn become ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
187
188
self . process ( b, nbits, |_, w| w)
188
189
}
189
190
190
191
#[ inline]
191
- pub fn difference ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
192
+ fn difference ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
192
193
self . process ( b, nbits, |w1, w2| w1 & !w2)
193
194
}
194
195
195
196
#[ inline]
196
- pub fn get ( & self , i : uint ) -> bool {
197
+ fn get ( & self , i : uint ) -> bool {
197
198
let w = i / uint:: BITS ;
198
199
let b = i % uint:: BITS ;
199
200
let x = 1 & self . storage . get ( w) >> b;
200
201
x == 1
201
202
}
202
203
203
204
#[ inline]
204
- pub fn set ( & mut self , i : uint , x : bool ) {
205
+ fn set ( & mut self , i : uint , x : bool ) {
205
206
let w = i / uint:: BITS ;
206
207
let b = i % uint:: BITS ;
207
208
let flag = 1 << b;
@@ -210,7 +211,7 @@ impl BigBitv {
210
211
}
211
212
212
213
#[ inline]
213
- pub fn equals ( & self , b : & BigBitv , nbits : uint ) -> bool {
214
+ fn equals ( & self , b : & BigBitv , nbits : uint ) -> bool {
214
215
for ( i, elt) in b. storage . iter ( ) . enumerate ( ) {
215
216
let mask = big_mask ( nbits, i) ;
216
217
if mask & * self . storage . get ( i) != mask & * elt {
@@ -596,6 +597,20 @@ impl fmt::Show for Bitv {
596
597
}
597
598
}
598
599
600
+ impl < S : hash:: Writer > hash:: Hash < S > for Bitv {
601
+ fn hash ( & self , state : & mut S ) {
602
+ self . nbits . hash ( state) ;
603
+ match self . rep {
604
+ Small ( ref s) => ( s. bits & small_mask ( self . nbits ) ) . hash ( state) ,
605
+ Big ( ref b) => {
606
+ for ( i, ele) in b. storage . iter ( ) . enumerate ( ) {
607
+ ( ele & big_mask ( self . nbits , i) ) . hash ( state) ;
608
+ }
609
+ }
610
+ }
611
+ }
612
+ }
613
+
599
614
#[ inline]
600
615
fn iterate_bits ( base : uint , bits : uint , f: |uint| -> bool) -> bool {
601
616
if bits == 0 {
@@ -834,6 +849,14 @@ impl fmt::Show for BitvSet {
834
849
}
835
850
}
836
851
852
+ impl < S : hash:: Writer > hash:: Hash < S > for BitvSet {
853
+ fn hash ( & self , state : & mut S ) {
854
+ for pos in self . iter ( ) {
855
+ pos. hash ( state) ;
856
+ }
857
+ }
858
+ }
859
+
837
860
impl Container for BitvSet {
838
861
#[ inline]
839
862
fn len ( & self ) -> uint { self . size }
0 commit comments