Class: Stamina::Induction::UnionFind::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/stamina-induction/stamina/induction/union_find.rb

Overview

An element of the union find, keeping the index of its leader element as well as mergeable user data. This class is not intended to be used by external users of the UnionFind data structure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, data) ⇒ Node

Creates a default Node instance with a specific parent index and attached user data.



123
124
125
126
# File 'lib/stamina-induction/stamina/induction/union_find.rb', line 123

def initialize(parent, data)
  @parent = parent
  @data = data
end

Instance Attribute Details

#dataObject

Attached user data



117
118
119
# File 'lib/stamina-induction/stamina/induction/union_find.rb', line 117

def data
  @data
end

#parentObject

Index of the parent element (on the way to the leader)



114
115
116
# File 'lib/stamina-induction/stamina/induction/union_find.rb', line 114

def parent
  @parent
end

Instance Method Details

#dupObject

Duplicates this node, ensuring that future changes will not affect the copy. Please note that the user data itself is not duplicated and is not expected to change. This property (not changing user data) is respected by the RPNI and BlueFringe classes as implemented in this library.



134
135
136
# File 'lib/stamina-induction/stamina/induction/union_find.rb', line 134

def dup
  Node.new(@parent, @data)
end