Class: Riak::Crdt::HyperLogLog

Inherits:
Base show all
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

#bucket, #bucket_type, #key

Instance Method Summary collapse

Methods included from Util::String

equal_bytes?

Methods inherited from Base

#==, #context?, #dirty?, #inspect_name, #pretty_print_cycle, #reload

Methods included from Util::Translation

#i18n_scope, #t

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:

  1. The ‘bucket_type` String argument

  2. A BucketTyped::Bucket as the ‘bucket` argument

  3. The ‘Crdt::Base::DEFAULT_BUCKET_TYPES` entry

Parameters:

  • bucket (Bucket)

    the Bucket for this set

  • key (String, nil)

    The name of the set. A nil key makes Riak assign a key.

  • bucket_type (String) (defaults to: nil)

    The bucket type for this HLL datatype

  • options (Hash) (defaults to: {})


22
23
24
# 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

Instance Method Details

#add(element, options = {}) ⇒ Object

Parameters:

  • element (String)

    the element to add to the set

  • options (Hash) (defaults to: {})


47
48
49
# File 'lib/riak/crdt/hyper_log_log.rb', line 47

def add(element, options = {})
  operate operation(:add, element), options
end

#batch {|batcher| ... } ⇒ Object

Yields:

  • (batcher)


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

#valueInteger Also known as: cardinality

Gets the current HLL value from Riak

Returns:

  • (Integer)


29
30
31
32
# File 'lib/riak/crdt/hyper_log_log.rb', line 29

def value
  reload if dirty?
  @value
end