Class: Entropy::Dict

Inherits:
Object
  • Object
show all
Defined in:
lib/entropy/dict.rb

Instance Method Summary collapse

Constructor Details

#initializeDict

Returns a new instance of Dict.



8
9
10
11
# File 'lib/entropy/dict.rb', line 8

def initialize
  @bucket = Hash.new(0)
  @space_size = 0
end

Instance Method Details

#freq(k) ⇒ Object

Compute frequency of the element



20
21
22
# File 'lib/entropy/dict.rb', line 20

def freq(k)
  (@bucket[k].to_d / @space_size)
end

#scan_keysObject

Return all the elements of the space



25
26
27
# File 'lib/entropy/dict.rb', line 25

def scan_keys
  @bucket.keys
end

#upd(k) ⇒ Object

Add an element to the space



14
15
16
17
# File 'lib/entropy/dict.rb', line 14

def upd(k)
  @bucket[k] += 1
  @space_size += 1
end