Sha256: 2a9a23a9935f9f3761d992f186ce719deb541fdf7ae7d13feba44acd37356499

Contents?: true

Size: 610 Bytes

Versions: 152

Compression:

Stored size: 610 Bytes

Contents

module ThreadSafe
  module Util
    class PowerOfTwoTuple < VolatileTuple
      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

      def hash_to_index(hash)
        (size - 1) & hash
      end

      def volatile_get_by_hash(hash)
        volatile_get(hash_to_index(hash))
      end

      def volatile_set_by_hash(hash, value)
        volatile_set(hash_to_index(hash), value)
      end

      def next_in_size_table
        self.class.new(size << 1)
      end
    end
  end
end

Version data entries

152 entries across 144 versions & 47 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/thread_safe-0.3.6/lib/thread_safe/util/power_of_two_tuple.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/thread_safe-0.3.6/lib/thread_safe/util/power_of_two_tuple.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/thread_safe-0.3.6/lib/thread_safe/util/power_of_two_tuple.rb
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/thread_safe-0.3.6/lib/thread_safe/util/power_of_two_tuple.rb
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/thread_safe-0.3.6/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/thread_safe-0.3.6/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/thread_safe-0.3.6-java/lib/thread_safe/util/power_of_two_tuple.rb