class Concurrent::ThreadSafe::Util::PowerOfTwoTuple
@!visibility private
Public Class Methods
Source
# File lib/concurrent-ruby/concurrent/thread_safe/util/power_of_two_tuple.rb, line 15 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
Calls superclass method
Concurrent::Tuple::new
Public Instance Methods
Source
# File lib/concurrent-ruby/concurrent/thread_safe/util/power_of_two_tuple.rb, line 20 def hash_to_index(hash) (size - 1) & hash end
Source
# File lib/concurrent-ruby/concurrent/thread_safe/util/power_of_two_tuple.rb, line 32 def next_in_size_table self.class.new(size << 1) end
Source
# File lib/concurrent-ruby/concurrent/thread_safe/util/power_of_two_tuple.rb, line 24 def volatile_get_by_hash(hash) volatile_get(hash_to_index(hash)) end
Source
# File lib/concurrent-ruby/concurrent/thread_safe/util/power_of_two_tuple.rb, line 28 def volatile_set_by_hash(hash, value) volatile_set(hash_to_index(hash), value) end