Class: AMQ::BitSet

### Home Classes Methods

### In Files

- lib/amq/bit_set.rb

### Parent

Object

### Methods

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

### Class/Module Index

Quicksearch

- AMQ
- AMQ::BitSet
- AMQ::Endianness
- AMQ::Hacks
- AMQ::IntAllocator
- AMQ::Pack
- AMQ::Protocol
- AMQ::Protocol::AccessRefused
- AMQ::Protocol::BadResponseError
- AMQ::Protocol::Basic
- AMQ::Protocol::Basic::Ack
- AMQ::Protocol::Basic::Cancel
- AMQ::Protocol::Basic::CancelOk
- AMQ::Protocol::Basic::Consume
- AMQ::Protocol::Basic::ConsumeOk
- AMQ::Protocol::Basic::Deliver
- AMQ::Protocol::Basic::Get
- AMQ::Protocol::Basic::GetEmpty
- AMQ::Protocol::Basic::GetOk
- AMQ::Protocol::Basic::Nack
- AMQ::Protocol::Basic::Publish
- AMQ::Protocol::Basic::Qos
- AMQ::Protocol::Basic::QosOk
- AMQ::Protocol::Basic::Recover
- AMQ::Protocol::Basic::RecoverAsync
- AMQ::Protocol::Basic::RecoverOk
- AMQ::Protocol::Basic::Reject
- AMQ::Protocol::Basic::Return
- AMQ::Protocol::BodyFrame
- AMQ::Protocol::Channel
- AMQ::Protocol::Channel::Close
- AMQ::Protocol::Channel::CloseOk
- AMQ::Protocol::Channel::Flow
- AMQ::Protocol::Channel::FlowOk
- AMQ::Protocol::Channel::Open
- AMQ::Protocol::Channel::OpenOk
- AMQ::Protocol::ChannelError
- AMQ::Protocol::Class
- AMQ::Protocol::CommandInvalid
- AMQ::Protocol::Confirm
- AMQ::Protocol::Confirm::Select
- AMQ::Protocol::Confirm::SelectOk
- AMQ::Protocol::Connection
- AMQ::Protocol::Connection::Blocked
- AMQ::Protocol::Connection::Close
- AMQ::Protocol::Connection::CloseOk
- AMQ::Protocol::Connection::Open
- AMQ::Protocol::Connection::OpenOk
- AMQ::Protocol::Connection::Secure
- AMQ::Protocol::Connection::SecureOk
- AMQ::Protocol::Connection::Start
- AMQ::Protocol::Connection::StartOk
- AMQ::Protocol::Connection::Tune
- AMQ::Protocol::Connection::TuneOk
- AMQ::Protocol::Connection::Unblocked
- AMQ::Protocol::ConnectionForced
- AMQ::Protocol::ContentTooLarge
- AMQ::Protocol::EmptyResponseError
- AMQ::Protocol::Error
- AMQ::Protocol::Exchange
- AMQ::Protocol::Exchange::Bind
- AMQ::Protocol::Exchange::BindOk
- AMQ::Protocol::Exchange::Declare
- AMQ::Protocol::Exchange::DeclareOk
- AMQ::Protocol::Exchange::Delete
- AMQ::Protocol::Exchange::DeleteOk
- AMQ::Protocol::Exchange::Unbind
- AMQ::Protocol::Exchange::UnbindOk
- AMQ::Protocol::Float32Bit
- AMQ::Protocol::Frame
- AMQ::Protocol::FrameError
- AMQ::Protocol::FrameSubclass
- AMQ::Protocol::FrameTypeError
- AMQ::Protocol::HardError
- AMQ::Protocol::HeaderFrame
- AMQ::Protocol::HeartbeatFrame
- AMQ::Protocol::InternalError
- AMQ::Protocol::InvalidPath
- AMQ::Protocol::Method
- AMQ::Protocol::MethodFrame
- AMQ::Protocol::NoConsumers
- AMQ::Protocol::NoRoute
- AMQ::Protocol::NotAllowed
- AMQ::Protocol::NotFound
- AMQ::Protocol::NotImplemented
- AMQ::Protocol::PreconditionFailed
- AMQ::Protocol::Queue
- AMQ::Protocol::Queue::Bind
- AMQ::Protocol::Queue::BindOk
- AMQ::Protocol::Queue::Declare
- AMQ::Protocol::Queue::DeclareOk
- AMQ::Protocol::Queue::Delete
- AMQ::Protocol::Queue::DeleteOk
- AMQ::Protocol::Queue::Purge
- AMQ::Protocol::Queue::PurgeOk
- AMQ::Protocol::Queue::Unbind
- AMQ::Protocol::Queue::UnbindOk
- AMQ::Protocol::ResourceError
- AMQ::Protocol::ResourceLocked
- AMQ::Protocol::SoftError
- AMQ::Protocol::SyntaxError
- AMQ::Protocol::Table
- AMQ::Protocol::Table::InvalidTableError
- AMQ::Protocol::TableValueDecoder
- AMQ::Protocol::TableValueEncoder
- AMQ::Protocol::Tx
- AMQ::Protocol::Tx::Commit
- AMQ::Protocol::Tx::CommitOk
- AMQ::Protocol::Tx::Rollback
- AMQ::Protocol::Tx::RollbackOk
- AMQ::Protocol::Tx::Select
- AMQ::Protocol::Tx::SelectOk
- AMQ::Protocol::TypeConstants
- AMQ::Protocol::UnexpectedFrame

No matching classes.

# AMQ::BitSet

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

Originally part of amqp gem. Extracted to make it possible for Bunny to use it.

### 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/amq/bit_set.rb, line 19
    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/amq/bit_set.rb, line 59
    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/amq/bit_set.rb, line 39
    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/amq/bit_set.rb, line 29
    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/amq/bit_set.rb, line 50
    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/amq/bit_set.rb, line 71
    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/amq/bit_set.rb, line 77
    def word_index(i)
      i >> ADDRESS_BITS_PER_WORD
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.