Sha256: 7eb1494b59029cfa6b6a44a9628f083c91edad62bda865ca9cf4b3fe434d2e35
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
JsonBloomfilter.BitArray = (size, field = null) -> @ELEMENT_WIDTH = 32 @size = size @field = field || [] arrayLength = Math.floor(((size - 1) / @ELEMENT_WIDTH) + 1) @field[i] = 0 for i in [0..arrayLength] unless field this JsonBloomfilter.BitArray.prototype.add = (position) -> @set(position, 1) JsonBloomfilter.BitArray.prototype.remove = (position) -> @set(position, 0) JsonBloomfilter.BitArray.prototype.set = (position, value) -> aPos = @arrayPosition(position) bChange = @bitChange(position) if value == 1 @field[aPos] |= bChange else if @field[aPos] & bChange != 0 @field[aPos] ^= bChange true JsonBloomfilter.BitArray.prototype.get = (position) -> aPos = @arrayPosition(position) bChange = @bitChange(position) if (@field[aPos] & bChange) > 0 return 1 else return 0 JsonBloomfilter.BitArray.prototype.arrayPosition = (position) -> Math.floor(position / @ELEMENT_WIDTH) JsonBloomfilter.BitArray.prototype.bitChange = (position) -> Math.abs(1 << position % @ELEMENT_WIDTH) JsonBloomfilter.BitArray.prototype.toString = -> output = "" output += @get(i) for i in [0..@size-1] output
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
json-bloomfilter-0.0.3 | coffee/bitarray.coffee |