Class: FpGrowth::FpTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/fpgrowth/fp_tree/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item = nil, support = 1) ⇒ Node

Returns a new instance of Node.



6
7
8
9
10
11
12
# File 'lib/fpgrowth/fp_tree/node.rb', line 6

def initialize(item=nil, support=1)
  @item = item
  @support = support
  @children = []
  @lateral = nil
  @parent = nil
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



4
5
6
# File 'lib/fpgrowth/fp_tree/node.rb', line 4

def children
  @children
end

#itemObject

Returns the value of attribute item.



4
5
6
# File 'lib/fpgrowth/fp_tree/node.rb', line 4

def item
  @item
end

#lateralObject

Returns the value of attribute lateral.



4
5
6
# File 'lib/fpgrowth/fp_tree/node.rb', line 4

def lateral
  @lateral
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/fpgrowth/fp_tree/node.rb', line 4

def parent
  @parent
end

#supportObject

Returns the value of attribute support.



4
5
6
# File 'lib/fpgrowth/fp_tree/node.rb', line 4

def support
  @support
end

Instance Method Details

#==(other_object) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/fpgrowth/fp_tree/node.rb', line 35

def ==(other_object)
  return false unless other_object
  flag = true
  flag = false if @item != other_object.item
  flag = false if @support != other_object.support
  flag = false if @children != other_object.children
  return flag
end

#clone_deepObject

Clone Node, deeply Must ignore parent and lateral, which are relative to this node in his tree, not to the clone



27
28
29
30
31
32
33
# File 'lib/fpgrowth/fp_tree/node.rb', line 27

def clone_deep
  clone = Node.new()
  clone.item = @item
  clone.support = @support
  clone.children = clone_tail_deep()
  return clone
end

#clone_tail_deepObject

Clone childrens, deeply



16
17
18
19
20
21
22
# File 'lib/fpgrowth/fp_tree/node.rb', line 16

def clone_tail_deep
  cloned_tail = []
  for child in children
    cloned_tail << child.clone_deep()
  end
  return cloned_tail
end