Class: Concurrent::Edge::LockFreeLinkedSet::Node — Concurrent

Class List Method List File List

# Class: Concurrent::Edge::LockFreeLinkedSet::Node

Inherits:
  Synchronization::Object
  - Object
  - Synchronization::Object
  - Concurrent::Edge::LockFreeLinkedSet::Node
  show all
Includes:
  Comparable
Defined in:
  lib/concurrent/edge/lock_free_linked_set/node.rb

## Direct Known Subclasses

Head, Tail

## Instance Method Summary (collapse)

- - (undocumented) <=>(other)

  We use `Object#hash` as a way to enforce ordering on the nodes.

- - (undocumented) data
- - (Node) initialize(data = nil, successor = nil) constructor

  A new instance of Node.

- - (undocumented) key
- - (undocumented) key_for(data)

  This method provides a unqiue key for the data which will be used for ordering.

- - (Boolean) last?

  Check to see if the node is the last in the list.

- - (undocumented) next_node

  Next node in the list.

- - (undocumented) successor_reference

## Constructor Details

### - (`Node`) initialize(data = nil, successor = nil)

Returns a new instance of Node

    11
    12
    13
    14
    15
    16
    # File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 11

    def initialize(data = nil, successor = nil)
      super()
      @SuccessorReference = AtomicMarkableReference.new(successor || Tail.new)
      @Data                = data
      @Key                 = key_for data
    end

## Instance Method Details

### - (`undocumented`) <=>(other)

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.

    51
    52
    53
    # File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 51

    def <=>(other)
      @Key <=> other.hash
    end

### - (`undocumented`) data

    18
    19
    20
    # File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 18

    def data
      @Data
    end

### - (`undocumented`) key

    26
    27
    28
    # File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 26

    def key
      @Key
    end

### - (`undocumented`) key_for(data)

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.

    44
    45
    46
    # File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 44

    def key_for(data)
      data.hash
    end

### - (`Boolean`) last?

Check to see if the node is the last in the list.

Returns:

- (`Boolean`)

    31
    32
    33
    # File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 31

    def last?
      @SuccessorReference.value.is_a? Tail
    end

### - (`undocumented`) next_node

Next node in the list. Note: this is not the AtomicMarkableReference of the next node, this is the actual Node itself.

    37
    38
    39
    # File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 37

    def next_node
      @SuccessorReference.value
    end

### - (`undocumented`) successor_reference

    22
    23
    24
    # File 'lib/concurrent/edge/lock_free_linked_set/node.rb', line 22

    def successor_reference
      @SuccessorReference
    end