Class: ActiveHll::Hll
- Inherits:
-
Object
- Object
- ActiveHll::Hll
- Defined in:
- lib/active_hll/hll.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #data ⇒ Object
- #expthresh ⇒ Object
-
#initialize(value) ⇒ Hll
constructor
A new instance of Hll.
- #inspect ⇒ Object
- #log2m ⇒ Object
- #regwidth ⇒ Object
- #schema_version ⇒ Object
- #sparseon ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(value) ⇒ Hll
Returns a new instance of Hll.
7 8 9 10 11 12 13 |
# File 'lib/active_hll/hll.rb', line 7 def initialize(value) unless value.is_a?(String) && value.encoding == Encoding::BINARY raise ArgumentError, "Expected binary string" end @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/active_hll/hll.rb', line 5 def value @value end |
Instance Method Details
#data ⇒ Object
44 45 46 47 48 49 |
# File 'lib/active_hll/hll.rb', line 44 def data case type when 2 value[3..-1].unpack("q>*") end end |
#expthresh ⇒ Object
39 40 41 42 |
# File 'lib/active_hll/hll.rb', line 39 def expthresh t = value[2].unpack1("C") & 0b00111111 t == 63 ? -1 : 2**(t - 1) end |
#inspect ⇒ Object
15 16 17 |
# File 'lib/active_hll/hll.rb', line 15 def inspect "(hll)" end |
#log2m ⇒ Object
31 32 33 |
# File 'lib/active_hll/hll.rb', line 31 def log2m value[1].unpack1("C") & 0b00011111 end |
#regwidth ⇒ Object
27 28 29 |
# File 'lib/active_hll/hll.rb', line 27 def regwidth (value[1].unpack1("C") >> 5) + 1 end |
#schema_version ⇒ Object
19 20 21 |
# File 'lib/active_hll/hll.rb', line 19 def schema_version value[0].unpack1("C") >> 4 end |
#sparseon ⇒ Object
35 36 37 |
# File 'lib/active_hll/hll.rb', line 35 def sparseon (value[2].unpack1("C") & 0b01000000) >> 6 end |
#type ⇒ Object
23 24 25 |
# File 'lib/active_hll/hll.rb', line 23 def type value[0].unpack1("C") & 0b00001111 end |