### Home Classes Methods

### In Files

- lib/thread_safe/util/power_of_two_tuple.rb

### Parent

VolatileTuple

### Methods

- ::new
- #hash_to_index
- #next_in_size_table
- #volatile_get_by_hash
- #volatile_set_by_hash

### Class/Module Index

Quicksearch

- ThreadSafe
- ThreadSafe::Array
- ThreadSafe::AtomicReferenceCacheBackend
- ThreadSafe::AtomicReferenceCacheBackend::Node
- ThreadSafe::AtomicReferenceCacheBackend::Table
- ThreadSafe::Cache
- ThreadSafe::Hash
- ThreadSafe::MriCacheBackend
- ThreadSafe::NonConcurrentCacheBackend
- ThreadSafe::SynchronizedCacheBackend
- ThreadSafe::Util
- ThreadSafe::Util::Adder
- ThreadSafe::Util::CheapLockable
- ThreadSafe::Util::PowerOfTwoTuple
- ThreadSafe::Util::Striped64
- ThreadSafe::Util::Striped64::Cell
- ThreadSafe::Util::Volatile
- ThreadSafe::Util::VolatileTuple
- ThreadSafe::Util::XorShiftRandom
- SynchronizedDelegator
- Threadsafe

No matching classes.

# ThreadSafe::Util::PowerOfTwoTuple

### Public Class Methods

new(size) click to toggle source

    # File lib/thread_safe/util/power_of_two_tuple.rb, line 4
    def initialize(size)
      raise ArgumentError, "size must be a power of 2 (#{size.inspect} provided)" unless size > 0 && size & (size - 1) == 0
      super(size)
    end

### Public Instance Methods

hash_to_index(hash) click to toggle source

    # File lib/thread_safe/util/power_of_two_tuple.rb, line 9
    def hash_to_index(hash)
      (size - 1) & hash
    end

next_in_size_table() click to toggle source

    # File lib/thread_safe/util/power_of_two_tuple.rb, line 21
    def next_in_size_table
      self.class.new(size << 1)
    end

volatile_get_by_hash(hash) click to toggle source

    # File lib/thread_safe/util/power_of_two_tuple.rb, line 13
    def volatile_get_by_hash(hash)
      volatile_get(hash_to_index(hash))
    end

volatile_set_by_hash(hash, value) click to toggle source

    # File lib/thread_safe/util/power_of_two_tuple.rb, line 17
    def volatile_set_by_hash(hash, value)
      volatile_set(hash_to_index(hash), value)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.