### Home Classes Methods

### In Files

- lib/amqp/bit_set.rb

### Parent

Object

### Methods

- ::new
- #[]
- #clear
- #get
- #init_words
- #set
- #unset
- #word_index

### Class/Module Index

Quicksearch

- AMQP
- AMQP::BitSet
- AMQP::BlankSlate
- AMQP::Broker
- AMQP::Channel
- AMQP::ChannelClosedError
- AMQP::Client
- AMQP::Consumer
- AMQP::Error
- AMQP::Exchange
- AMQP::Header
- AMQP::IncompatibleOptionsError
- AMQP::IntAllocator
- AMQP::Integration
- AMQP::Integration::Rails
- AMQP::Logger
- AMQP::PossibleAuthenticationFailureError
- AMQP::Queue
- AMQP::RPC
- AMQP::RPC::Client
- AMQP::RPC::Server
- AMQP::Session
- AMQP::TCPConnectionFailed
- AMQP::Utilities
- AMQP::Utilities::EventLoopHelper
- AMQP::Utilities::ServerType
- MQ
- MQ::Exchange
- MQ::Logger
- MQ::Queue
- EM
- Object

No matching classes.

# 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 17
    def initialize(nbits)
      @nbits = nbits

      self.init_words(nbits)
    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 57
    def clear
      self.init_words(@nbits)
    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 37
    def get(i)
      w = self.word_index(i)

      (@words[w] & (1 << i)) != 0
    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 27
    def set(i)
      w = self.word_index(i)
      @words[w] |= (1 << i)
    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 48
    def unset(i)
      w = self.word_index(i)
      return if w.nil?

      @words[w] &= ~(1 << i)
    end

### Protected Instance Methods

init_words(nbits) click to toggle source

@private

    # File lib/amqp/bit_set.rb, line 69
    def init_words(nbits)
      n      = word_index(nbits-1) + 1
      @words = Array.new(n) { 1 }
    end

word_index(i) click to toggle source

@private

    # File lib/amqp/bit_set.rb, line 75
    def word_index(i)
      i >> ADDRESS_BITS_PER_WORD
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.