Permalink
Browse files

Iterate through elements. This is probably wrong. :-/

  • Loading branch information...
1 parent 70fde3b commit da5284415c12563734bfeff1267a514bea7f8aba @phf committed Apr 15, 2010
Showing with 18 additions and 0 deletions.
  1. +18 −0 bitset.go
View
@@ -35,3 +35,21 @@ func (self *Bitset) Has(i int) (b bool) {
bucket, mask := locate(i)
return (self.data[bucket] & mask) != 0
}
+
+func (self *Bitset) iterate(c chan<- int) {
+ for bucket, value := range self.data {
+ for i := 0; i < bits_per_int; i++ {
+ if value & 1 == 1 {
+ c <- bucket*bits_per_int + i
+ }
+ value >>= 1
+ }
+ }
+}
+
+func (self *Bitset) Iter() <-chan int {
+ c := make(chan int)
+ go self.iterate(c)
+ return c
+}
+

0 comments on commit da52844

Please sign in to comment.