Parent

AMQP::BitSet

Very minimalistic, pure Ruby implementation of bit set. Inspired by java.util.BitSet, although significantly smaller in scope.

Constants

ADDRESS_BITS_PER_WORD

API

BITS_PER_WORD
WORD_MASK

Public Class Methods

new(nbits) click to toggle source

@param [Integer] Number of bits in the set @api public

    # File lib/amqp/bit_set.rb, line 18
18:     def initialize(nbits)
19:       @nbits = nbits
20: 
21:       self.init_words(nbits)
22:     end

Public Instance Methods

[](i) click to toggle source
Alias for: get
clear() click to toggle source

Clears all bits in the set @api public

    # File lib/amqp/bit_set.rb, line 58
58:     def clear
59:       self.init_words(@nbits)
60:     end
get(i) click to toggle source

Fetches flag value for given bit.

@param [Integer] A bit to fetch @return [Boolean] true if given bit is set, false otherwise @api public

    # File lib/amqp/bit_set.rb, line 38
38:     def get(i)
39:       w = self.word_index(i)
40: 
41:       (@words[w] & (1 << i)) != 0
42:     end
Also aliased as: []
set(i) click to toggle source

Sets (flags) given bit. This method allows bits to be set more than once in a row, no exception will be raised.

@param [Integer] A bit to set @api public

    # File lib/amqp/bit_set.rb, line 28
28:     def set(i)
29:       w = self.word_index(i)
30:       @words[w] |= (1 << i)
31:     end
unset(i) click to toggle source

Unsets (unflags) given bit. This method allows bits to be unset more than once in a row, no exception will be raised.

@param [Integer] A bit to unset @api public

    # File lib/amqp/bit_set.rb, line 49
49:     def unset(i)
50:       w = self.word_index(i)
51:       return if w.nil?
52: 
53:       @words[w] &= ~(1 << i)
54:     end

Protected Instance Methods

init_words(nbits) click to toggle source

@private

    # File lib/amqp/bit_set.rb, line 70
70:     def init_words(nbits)
71:       n      = word_index(nbits-1) + 1
72:       @words = Array.new(n) { 1 }
73:     end
word_index(i) click to toggle source

@private

    # File lib/amqp/bit_set.rb, line 76
76:     def word_index(i)
77:       i >> ADDRESS_BITS_PER_WORD
78:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.