Class: Concurrent::Edge::LockFreeLinkedSet::Node
- Inherits:
-
Synchronization::Object
- Object
- Synchronization::Object
- Concurrent::Edge::LockFreeLinkedSet::Node
- Includes:
- Comparable
- Defined in:
- lib/concurrent/edge/lock_free_linked_set/node.rb
Instance Attribute Summary collapse
-
#Data ⇒ Object
readonly
Returns the value of attribute Data.
-
#Key ⇒ Object
readonly
Returns the value of attribute Key.
-
#Successor_reference ⇒ Object
readonly
Returns the value of attribute Successor_reference.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
We use ‘Object#hash` as a way to enforce ordering on the nodes.
-
#initialize(data = nil, successor = nil) ⇒ Node
constructor
A new instance of Node.
-
#key_for(data) ⇒ Object
This method provides a unqiue key for the data which will be used for ordering.
-
#last? ⇒ Boolean
Check to see if the node is the last in the list.
-
#next_node ⇒ Object
Next node in the list.
Constructor Details
#initialize(data = nil, successor = nil) ⇒ Node
11 12 13 14 15 16 17 18 19 |
# File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 11 def initialize(data = nil, successor = nil) super() @Successor_reference = AtomicMarkableReference.new(successor || Tail.new) @Data = data @Key = key_for data ensure_ivar_visibility! end |
Instance Attribute Details
#Data ⇒ Object (readonly)
Returns the value of attribute Data.
9 10 11 |
# File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 9 def Data @Data end |
#Key ⇒ Object (readonly)
Returns the value of attribute Key.
9 10 11 |
# File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 9 def Key @Key end |
#Successor_reference ⇒ Object (readonly)
Returns the value of attribute Successor_reference.
9 10 11 |
# File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 9 def Successor_reference @Successor_reference end |
Instance Method Details
#<=>(other) ⇒ Object
We use ‘Object#hash` as a way to enforce ordering on the nodes. This can be configurable in the future; for example, you could enforce a split-ordering on the nodes in the set.
42 43 44 |
# File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 42 def <=>(other) @Key <=> other.hash end |
#key_for(data) ⇒ Object
This method provides a unqiue key for the data which will be used for ordering. This is configurable, and changes depending on how you wish the nodes to be ordered.
35 36 37 |
# File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 35 def key_for(data) data.hash end |
#last? ⇒ Boolean
Check to see if the node is the last in the list.
22 23 24 |
# File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 22 def last? @Successor_reference.value.is_a? Tail end |
#next_node ⇒ Object
Next node in the list. Note: this is not the AtomicMarkableReference of the next node, this is the actual Node itself.
28 29 30 |
# File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 28 def next_node @Successor_reference.value end |