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: {})


36
37
38
# File 'lib/riak/crdt/hyper_log_log.rb', line 36

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: {})


61
62
63
# File 'lib/riak/crdt/hyper_log_log.rb', line 61

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

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

Yields:

  • (batcher)


49
50
51
52
53
54
55
# File 'lib/riak/crdt/hyper_log_log.rb', line 49

def batch
  batcher = BatchHyperLogLog.new self

  yield batcher

  operate batcher.operations
end

#pretty_print(pp) ⇒ Object



65
66
67
68
69
70
# File 'lib/riak/crdt/hyper_log_log.rb', line 65

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)


43
44
45
46
# File 'lib/riak/crdt/hyper_log_log.rb', line 43

def value
  reload if dirty?
  @value
end