Class: FpGrowth::FpTree::HeaderTable

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHeaderTable

Returns a new instance of HeaderTable.



12
13
14
15
# File 'lib/fpgrowth/fp_tree/header_table.rb', line 12

def initialize()
  @count = Hash.new 0
  @nodes = Hash.new { Set.new() }
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



17
18
19
# File 'lib/fpgrowth/fp_tree/header_table.rb', line 17

def count
  @count
end

#nodesObject

Returns the value of attribute nodes.



17
18
19
# File 'lib/fpgrowth/fp_tree/header_table.rb', line 17

def nodes
  @nodes
end

Class Method Details

.build(item, header_table) ⇒ Object



6
7
8
9
# File 'lib/fpgrowth/fp_tree/header_table.rb', line 6

def self.build(item, header_table)
  builder = Builder::HeaderTableBuilder.new(item, header_table)
  return builder.execute()
end

Instance Method Details

#<<(row) ⇒ Object

Append a Row

Parameters:

  • row

    Array as [item, support, node]



26
27
28
29
30
31
# File 'lib/fpgrowth/fp_tree/header_table.rb', line 26

def << (row)
  # Add a link for m in HeaderTable
  @nodes[row[0]] = @nodes[row[0]] << row[2]
  # Add support m = previous + n
  @count[row[0]] += row[1]
end

#keysObject



19
20
21
# File 'lib/fpgrowth/fp_tree/header_table.rb', line 19

def keys
  @nodes.keys
end