| Class | SimpleVector |
| In: |
lib/bloomfilter/simplevector.rb
|
| Parent: | Object |
This is a slower and more limited bitvector class. Please use the BitSet C-extension library from below instead:
| length | -> | size |
| bvec | [RW] | |
| length | [RW] |
# File lib/bloomfilter/simplevector.rb, line 17
17: def SimpleVector.from_str(n,hexstr)
18: bv = SimpleVector.new(n)
19: bv.bvec = hexstr.hex
20: bv
21: end
# File lib/bloomfilter/simplevector.rb, line 12
12: def initialize(arg)
13: @length = arg
14: @bvec = 1<<@length
15: end
# File lib/bloomfilter/simplevector.rb, line 78
78: def SimpleVector.restore(bfstr,n)
79: bytes = bfstr.size
80: sv = bfstr.reverse.unpack("H*")[0]
81: sv = sv.hex | 1<<n
82: nv = SimpleVector.new(n)
83: nv.bvec = sv
84: nv
85: end
# File lib/bloomfilter/simplevector.rb, line 45
45: def &(other)
46: self.dup.intersect(other)
47: end
# File lib/bloomfilter/simplevector.rb, line 49
49: def ==(other)
50: self.bvec == other.bvec
51: end
# File lib/bloomfilter/simplevector.rb, line 61
61: def [](pos)
62: (@bvec & 1<<pos ) == 0 ? 0 : 1
63: end
# File lib/bloomfilter/simplevector.rb, line 53
53: def []=(pos,val=1)
54: case val
55: when 1: @bvec |= 1<<pos
56: when 0: @bvec &= ~(1<<(length+1) | 1<<pos)
57: end
58: self
59: end
# File lib/bloomfilter/simplevector.rb, line 40
40: def intersect(other)
41: self.bvec &= other.bvec
42: self
43: end