@@ -18,6 +18,7 @@ use core::iter::{Enumerate, Repeat, Map, Zip};
1818use core:: ops;
1919use core:: slice;
2020use core:: uint;
21+ use std:: hash;
2122
2223use vec:: Vec ;
2324
@@ -34,12 +35,12 @@ fn small_mask(nbits: uint) -> uint {
3435}
3536
3637impl SmallBitv {
37- pub fn new ( bits : uint ) -> SmallBitv {
38+ fn new ( bits : uint ) -> SmallBitv {
3839 SmallBitv { bits : bits}
3940 }
4041
4142 #[ inline]
42- pub fn bits_op ( & mut self ,
43+ fn bits_op ( & mut self ,
4344 right_bits : uint ,
4445 nbits : uint ,
4546 f : |uint , uint| -> uint)
@@ -52,32 +53,32 @@ impl SmallBitv {
5253 }
5354
5455 #[ inline]
55- pub fn union ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
56+ fn union ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
5657 self . bits_op ( s. bits , nbits, |u1, u2| u1 | u2)
5758 }
5859
5960 #[ inline]
60- pub fn intersect ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
61+ fn intersect ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
6162 self . bits_op ( s. bits , nbits, |u1, u2| u1 & u2)
6263 }
6364
6465 #[ inline]
65- pub fn become ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
66+ fn become ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
6667 self . bits_op ( s. bits , nbits, |_u1, u2| u2)
6768 }
6869
6970 #[ inline]
70- pub fn difference ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
71+ fn difference ( & mut self , s : & SmallBitv , nbits : uint ) -> bool {
7172 self . bits_op ( s. bits , nbits, |u1, u2| u1 & !u2)
7273 }
7374
7475 #[ inline]
75- pub fn get ( & self , i : uint ) -> bool {
76+ fn get ( & self , i : uint ) -> bool {
7677 ( self . bits & ( 1 << i) ) != 0
7778 }
7879
7980 #[ inline]
80- pub fn set ( & mut self , i : uint , x : bool ) {
81+ fn set ( & mut self , i : uint , x : bool ) {
8182 if x {
8283 self . bits |= 1 <<i;
8384 }
@@ -87,29 +88,29 @@ impl SmallBitv {
8788 }
8889
8990 #[ inline]
90- pub fn equals ( & self , b : & SmallBitv , nbits : uint ) -> bool {
91+ fn equals ( & self , b : & SmallBitv , nbits : uint ) -> bool {
9192 let mask = small_mask ( nbits) ;
9293 mask & self . bits == mask & b. bits
9394 }
9495
9596 #[ inline]
96- pub fn clear ( & mut self ) { self . bits = 0 ; }
97+ fn clear ( & mut self ) { self . bits = 0 ; }
9798
9899 #[ inline]
99- pub fn set_all ( & mut self ) { self . bits = !0 ; }
100+ fn set_all ( & mut self ) { self . bits = !0 ; }
100101
101102 #[ inline]
102- pub fn all ( & self , nbits : uint ) -> bool {
103+ fn all ( & self , nbits : uint ) -> bool {
103104 small_mask ( nbits) & !self . bits == 0
104105 }
105106
106107 #[ inline]
107- pub fn none ( & self , nbits : uint ) -> bool {
108+ fn none ( & self , nbits : uint ) -> bool {
108109 small_mask ( nbits) & self . bits == 0
109110 }
110111
111112 #[ inline]
112- pub fn negate ( & mut self ) { self . bits = !self . bits ; }
113+ fn negate ( & mut self ) { self . bits = !self . bits ; }
113114}
114115
115116#[ deriving( Clone ) ]
@@ -134,12 +135,12 @@ fn big_mask(nbits: uint, elem: uint) -> uint {
134135}
135136
136137impl BigBitv {
137- pub fn new ( storage : Vec < uint > ) -> BigBitv {
138+ fn new ( storage : Vec < uint > ) -> BigBitv {
138139 BigBitv { storage : storage}
139140 }
140141
141142 #[ inline]
142- pub fn process ( & mut self ,
143+ fn process ( & mut self ,
143144 b : & BigBitv ,
144145 nbits : uint ,
145146 op : |uint , uint| -> uint)
@@ -163,45 +164,45 @@ impl BigBitv {
163164 }
164165
165166 #[ 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 {
167168 self . storage . mut_iter ( ) . advance ( |elt| op ( elt) )
168169 }
169170
170171 #[ inline]
171- pub fn negate ( & mut self ) {
172+ fn negate ( & mut self ) {
172173 self . each_storage ( |w| { * w = !* w; true } ) ;
173174 }
174175
175176 #[ inline]
176- pub fn union ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
177+ fn union ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
177178 self . process ( b, nbits, |w1, w2| w1 | w2)
178179 }
179180
180181 #[ inline]
181- pub fn intersect ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
182+ fn intersect ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
182183 self . process ( b, nbits, |w1, w2| w1 & w2)
183184 }
184185
185186 #[ inline]
186- pub fn become ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
187+ fn become ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
187188 self . process ( b, nbits, |_, w| w)
188189 }
189190
190191 #[ inline]
191- pub fn difference ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
192+ fn difference ( & mut self , b : & BigBitv , nbits : uint ) -> bool {
192193 self . process ( b, nbits, |w1, w2| w1 & !w2)
193194 }
194195
195196 #[ inline]
196- pub fn get ( & self , i : uint ) -> bool {
197+ fn get ( & self , i : uint ) -> bool {
197198 let w = i / uint:: BITS ;
198199 let b = i % uint:: BITS ;
199200 let x = 1 & self . storage . get ( w) >> b;
200201 x == 1
201202 }
202203
203204 #[ inline]
204- pub fn set ( & mut self , i : uint , x : bool ) {
205+ fn set ( & mut self , i : uint , x : bool ) {
205206 let w = i / uint:: BITS ;
206207 let b = i % uint:: BITS ;
207208 let flag = 1 << b;
@@ -210,7 +211,7 @@ impl BigBitv {
210211 }
211212
212213 #[ inline]
213- pub fn equals ( & self , b : & BigBitv , nbits : uint ) -> bool {
214+ fn equals ( & self , b : & BigBitv , nbits : uint ) -> bool {
214215 for ( i, elt) in b. storage . iter ( ) . enumerate ( ) {
215216 let mask = big_mask ( nbits, i) ;
216217 if mask & * self . storage . get ( i) != mask & * elt {
@@ -596,6 +597,20 @@ impl fmt::Show for Bitv {
596597 }
597598}
598599
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+
599614#[ inline]
600615fn iterate_bits ( base : uint , bits : uint , f: |uint| -> bool) -> bool {
601616 if bits == 0 {
@@ -834,6 +849,14 @@ impl fmt::Show for BitvSet {
834849 }
835850}
836851
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+
837860impl Container for BitvSet {
838861 #[ inline]
839862 fn len ( & self ) -> uint { self . size }
0 commit comments