A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Tuple.html below:

Class: Concurrent::Tuple — Concurrent Ruby

Class: Concurrent::Tuple
Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/concurrent-ruby/concurrent/tuple.rb
Overview

A fixed size array with volatile (synchronized, thread safe) getters/setters. Mixes in Ruby's Enumerable module for enhanced search, sort, and traversal.

Instance Attribute Summary collapse Instance Method Summary collapse Constructor Details #initialize(size) ⇒ Tuple

Create a new tuple of the given size.

29
30
31
32
33
34
35
36
37
# File 'lib/concurrent-ruby/concurrent/tuple.rb', line 29

def initialize(size)
  @size = size
  @tuple = tuple = ::Array.new(size)
  i = 0
  while i < size
    tuple[i] = Concurrent::AtomicReference.new
    i += 1
  end
end
Instance Attribute Details #size ⇒ undocumented

The (fixed) size of the tuple.

24
25
26
# File 'lib/concurrent-ruby/concurrent/tuple.rb', line 24

def size
  @size
end
Instance Method Details #compare_and_set(i, old_value, new_value) ⇒ Boolean Also known as: cas

Set the value at the given index to the new value if and only if the current value matches the given old value.

69
70
71
72
# File 'lib/concurrent-ruby/concurrent/tuple.rb', line 69

def compare_and_set(i, old_value, new_value)
  return false if i >= @size || i < 0
  @tuple[i].compare_and_set(old_value, new_value)
end
#each {|ref| ... } ⇒ undocumented

Calls the given block once for each element in self, passing that element as a parameter.

78
79
80
# File 'lib/concurrent-ruby/concurrent/tuple.rb', line 78

def each
  @tuple.each {|ref| yield ref.get}
end
#get(i) ⇒ Object Also known as: volatile_get

Get the value of the element at the given index.

43
44
45
46
# File 'lib/concurrent-ruby/concurrent/tuple.rb', line 43

def get(i)
  return nil if i >= @size || i < 0
  @tuple[i].get
end
#set(i, value) ⇒ Object Also known as: volatile_set

Set the element at the given index to the given value

55
56
57
58
# File 'lib/concurrent-ruby/concurrent/tuple.rb', line 55

def set(i, value)
  return nil if i >= @size || i < 0
  @tuple[i].set(value)
end

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4