Class: Riak::Crdt::HyperLogLog
- Includes:
- Util::String
- Defined in:
- lib/riak/crdt/hyper_log_log.rb
Overview
A distributed set containing strings, using the Riak 2 Data Types feature and Hyper Log Log algorithm
Defined Under Namespace
Classes: BatchHyperLogLog
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#add(element, options = {}) ⇒ Object
Add a String to the HyperLogLog.
- #batch {|batcher| ... } ⇒ Object
-
#initialize(bucket, key, bucket_type = nil, options = {}) ⇒ HyperLogLog
constructor
Create a HLL instance.
- #pretty_print(pp) ⇒ Object
-
#value ⇒ Integer
(also: #cardinality)
Gets the current HLL value from Riak.
Methods included from Util::String
Methods inherited from Base
#==, #context?, #dirty?, #inspect_name, #pretty_print_cycle, #reload
Methods included from Util::Translation
Constructor Details
#initialize(bucket, key, bucket_type = nil, options = {}) ⇒ HyperLogLog
Create a HLL instance. The bucket type is determined by the first of these sources:
-
The ‘bucket_type` String argument
-
A BucketTyped::Bucket as the ‘bucket` argument
-
The ‘Crdt::Base::DEFAULT_BUCKET_TYPES` entry
22 23 24 |
# File 'lib/riak/crdt/hyper_log_log.rb', line 22 def initialize(bucket, key, bucket_type = nil, = {}) super(bucket, key, bucket_type || :hll, ) end |
Instance Method Details
#add(element, options = {}) ⇒ Object
Add a String to the Riak::Crdt::HyperLogLog
47 48 49 |
# File 'lib/riak/crdt/hyper_log_log.rb', line 47 def add(element, = {}) operate operation(:add, element), end |
#batch {|batcher| ... } ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/riak/crdt/hyper_log_log.rb', line 35 def batch batcher = BatchHyperLogLog.new self yield batcher operate batcher.operations end |
#pretty_print(pp) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/riak/crdt/hyper_log_log.rb', line 51 def pretty_print(pp) super pp do pp.comma_breakable pp.pp to_a end end |
#value ⇒ Integer Also known as: cardinality
Gets the current HLL value from Riak
29 30 31 32 |
# File 'lib/riak/crdt/hyper_log_log.rb', line 29 def value reload if dirty? @value end |