Class: FpGrowth::PrefixPath

Inherits:
Object
  • Object
show all
Defined in:
lib/fp_growth/prefix_path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(support = 1, array = []) ⇒ PrefixPath

Returns a new instance of PrefixPath.



5
6
7
8
# File 'lib/fp_growth/prefix_path.rb', line 5

def initialize(support = 1, array = [])
  @array = array
  @support = support
end

Instance Attribute Details

#supportObject (readonly)

Returns the value of attribute support.



3
4
5
# File 'lib/fp_growth/prefix_path.rb', line 3

def support
  @support
end

Instance Method Details

#+(other) ⇒ Object



25
26
27
28
# File 'lib/fp_growth/prefix_path.rb', line 25

def +(other)
  return self unless other
  FpGrowth::PrefixPath.new([@support, other.support].min, @array + other.to_a)
end

#<<(arg) ⇒ Object

delegate



16
17
18
# File 'lib/fp_growth/prefix_path.rb', line 16

def <<(arg)
  @array << arg
end

#==(other) ⇒ Object



38
39
40
# File 'lib/fp_growth/prefix_path.rb', line 38

def ==(other)
  (support == other.support) && (to_a.content_equal?(other.to_a))
end

#each(&block) ⇒ Object

delegate



11
12
13
# File 'lib/fp_growth/prefix_path.rb', line 11

def each(&block)
  @array.each(&block)
end

#sizeObject

delegate



21
22
23
# File 'lib/fp_growth/prefix_path.rb', line 21

def size
  @array.size
end

#to_aObject



34
35
36
# File 'lib/fp_growth/prefix_path.rb', line 34

def to_a
  @array
end

#to_sObject



30
31
32
# File 'lib/fp_growth/prefix_path.rb', line 30

def to_s
  "[#{@array}:#{support}]"
end