Class: Entropy::Dict
- Inherits:
-
Object
- Object
- Entropy::Dict
- Defined in:
- lib/entropy/dict.rb
Instance Method Summary collapse
-
#freq(k) ⇒ Object
Compute frequency of the element.
-
#initialize ⇒ Dict
constructor
A new instance of Dict.
-
#scan_keys ⇒ Object
Return all the elements of the space.
-
#upd(k) ⇒ Object
Add an element to the space.
Constructor Details
#initialize ⇒ Dict
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_keys ⇒ Object
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 |