Class: Concurrent::ThreadSafe::Util::PowerOfTwoTuple
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Tuple
|
|
|
Instance Chain:
self,
Tuple,
Enumerable
|
|
| Inherits: |
Concurrent::Tuple
|
| Defined in: | lib/concurrent-ruby/concurrent/thread_safe/util/power_of_two_tuple.rb |
Class Method Summary
- .new(size) ⇒ PowerOfTwoTuple constructor
Tuple - Inherited
| .new | Create a new tuple of the given size. |
Instance Attribute Summary
Instance Method Summary
- #hash_to_index(hash)
- #next_in_size_table
- #volatile_get_by_hash(hash)
- #volatile_set_by_hash(hash, value)
Tuple - Inherited
| #cas | Alias for Concurrent::Tuple#compare_and_set. |
| #compare_and_set |
|
| #each | Calls the given block once for each element in self, passing that element as a parameter. |
| #get | Get the value of the element at the given index. |
| #set |
|
| #volatile_get | Alias for Concurrent::Tuple#get. |
| #volatile_set | Alias for Concurrent::Tuple#set. |
Constructor Details
.new(size) ⇒ PowerOfTwoTuple
# 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
Instance Method Details
#hash_to_index(hash)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/thread_safe/util/power_of_two_tuple.rb', line 20
def hash_to_index(hash) (size - 1) & hash end
#next_in_size_table
[ GitHub ]# 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
#volatile_get_by_hash(hash)
[ GitHub ]# 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
#volatile_set_by_hash(hash, value)
[ GitHub ]# 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