class Riak::Crdt::HyperLogLog
A distributed set containing strings, using the Riak
2 Data Types feature and Hyper Log Log algorithm
Public Class Methods
new(bucket, key, bucket_type = nil, options = {})
click to toggle source
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
@param bucket [Bucket] the {Riak::Bucket} for this set @param [String, nil] key The name of the set. A nil key makes
Riak assign a key.
@param [String] bucket_type The bucket type for this HLL datatype @param options [Hash]
Calls superclass method
Riak::Crdt::Base::new
# File lib/riak/crdt/hyper_log_log.rb, line 22 def initialize(bucket, key, bucket_type = nil, options = {}) super(bucket, key, bucket_type || :hll, options) end
Public Instance Methods
add(element, options = {})
click to toggle source
Add a {String} to the {Riak::Crdt::HyperLogLog}
@param [String] element the element to add to the set @param [Hash] options
# File lib/riak/crdt/hyper_log_log.rb, line 47 def add(element, options = {}) operate operation(:add, element), options end
batch() { |batcher| ... }
click to toggle source
# 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)
click to toggle source
Calls superclass method
Riak::Crdt::Base#pretty_print
# 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()
click to toggle source
Gets the current HLL value from Riak
@return [Integer]
# File lib/riak/crdt/hyper_log_log.rb, line 29 def value reload if dirty? @value end
Also aliased as: cardinality
Private Instance Methods
operation(direction, element)
click to toggle source
# File lib/riak/crdt/hyper_log_log.rb, line 63 def operation(direction, element) Operation::Update.new.tap do |op| op.type = :hll op.value = { direction => element } end end
vivify(value)
click to toggle source
# File lib/riak/crdt/hyper_log_log.rb, line 59 def vivify(value) @value = value end