Class: Aerospike::Exp::HLL

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/exp/exp_hll.rb

Overview

HyperLogLog (HLL) expression generator. See Aerospike::Exp.

The bin expression argument in these methods can be a reference to a bin or the result of another expression. Expressions that modify bin values are only used for temporary expression evaluation and are not permanently applied to the bin. HLL modify expressions return the HLL bin’s value.

Class Method Summary collapse

Class Method Details

.add(list, bin, policy: CDT::HLLPolicy::DEFAULT, index_bit_count: Exp.val(-1), min_hash_bit_count: Exp.val(-1)) ⇒ Object

Create expression that adds values to a HLL set and returns HLL set. If HLL bin does not exist, use index_bit_count and min_hash_bit_count to create HLL set.

Examples

# Add values to HLL bin “a” and check count > 7 Exp.gt(

HLLExp.getCount(
  HLLExp.add(HLLPolicy.Default, Exp.val(list), Exp.val(10), Exp.val(20), Exp.hllBin("a"))),
Exp.val(7))

Parameters:

  • policy (defaults to: CDT::HLLPolicy::DEFAULT)

    write policy, use HLLPolicy#Default for default

  • list

    list bin or value expression of values to be added

  • index_bit_count (defaults to: Exp.val(-1))

    number of index bits expression. Must be between 4 and 16 inclusive.

  • min_hash_bit_count (defaults to: Exp.val(-1))

    number of min hash bits expression. Must be between 4 and 51 inclusive. Also, index_bit_count + min_hash_bit_count must be <= 64.

  • bin

    HLL bin or value expression



54
55
56
57
# File 'lib/aerospike/exp/exp_hll.rb', line 54

def self.add(list, bin, policy: CDT::HLLPolicy::DEFAULT, index_bit_count: Exp.val(-1), min_hash_bit_count: Exp.val(-1))
  bytes = Exp.pack(nil, ADD, list, index_bit_count, min_hash_bit_count, policy.flags)
  add_write(bin, bytes)
end

.describe(bin) ⇒ Object

Create expression that returns index_bit_count and min_hash_bit_count used to create HLL bin in a list of longs. list is index_bit_count and list is min_hash_bit_count.

Examples

# Bin “a” index_bit_count < 10 Exp.lt(

ListExp.getByIndex(ListReturnType.VALUE, Exp::Type::INT, Exp.val(0),
  HLLExp.describe(Exp.hllBin("a"))),
Exp.val(10))


131
132
133
134
# File 'lib/aerospike/exp/exp_hll.rb', line 131

def self.describe(bin)
  bytes = Exp.pack(nil, DESCRIBE)
  add_read(bin, bytes, Exp::Type::LIST)
end

.get_count(bin) ⇒ Object

Create expression that returns estimated number of elements in the HLL bin.

Examples

# HLL bin “a” count > 7 Exp.gt(HLLExp.getCount(Exp.hllBin(“a”)), Exp.val(7))



64
65
66
67
# File 'lib/aerospike/exp/exp_hll.rb', line 64

def self.get_count(bin)
  bytes = Exp.pack(nil, COUNT)
  add_read(bin, bytes, Exp::Type::INT)
end

.get_intersect_count(list, bin) ⇒ Object

Create expression that returns estimated number of elements that would be contained by the intersection of these HLL objects.

Examples

# Intersect count of HLL bins “a” and “b” HLLExp.getIntersectCount(Exp.hllBin(“a”), Exp.hllBin(“b”))

# Intersect count of local HLL list with bin “b” HLLExp.getIntersectCount(Exp.val(list), Exp.hllBin(“b”))



106
107
108
109
# File 'lib/aerospike/exp/exp_hll.rb', line 106

def self.get_intersect_count(list, bin)
  bytes = Exp.pack(nil, INTERSECT_COUNT, list)
  add_read(bin, bytes, Exp::Type::INT)
end

.get_similarity(list, bin) ⇒ Object

Create expression that returns estimated similarity of these HLL objects as a 64 bit float.

Examples

# Similarity of HLL bins “a” and “b” >= 0.75 Exp.ge(HLLExp.getSimilarity(Exp.hllBin(“a”), Exp.hllBin(“b”)), Exp.val(0.75))



117
118
119
120
# File 'lib/aerospike/exp/exp_hll.rb', line 117

def self.get_similarity(list, bin)
  bytes = Exp.pack(nil, SIMILARITY, list)
  add_read(bin, bytes, Exp::Type::FLOAT)
end

.get_union(list, bin) ⇒ Object

Create expression that returns a HLL object that is the union of all specified HLL objects in the list with the HLL bin.

Examples

# Union of HLL bins “a” and “b” HLLExp.getUnion(Exp.hllBin(“a”), Exp.hllBin(“b”))

# Union of local HLL list with bin “b” HLLExp.getUnion(Exp.val(list), Exp.hllBin(“b”))



78
79
80
81
# File 'lib/aerospike/exp/exp_hll.rb', line 78

def self.get_union(list, bin)
  bytes = Exp.pack(nil, UNION, list)
  add_read(bin, bytes, Exp::Type::HLL)
end

.get_union_count(list, bin) ⇒ Object

Create expression that returns estimated number of elements that would be contained by the union of these HLL objects.

Examples

# Union count of HLL bins “a” and “b” HLLExp.getUnionCount(Exp.hllBin(“a”), Exp.hllBin(“b”))

# Union count of local HLL list with bin “b” HLLExp.getUnionCount(Exp.val(list), Exp.hllBin(“b”))



92
93
94
95
# File 'lib/aerospike/exp/exp_hll.rb', line 92

def self.get_union_count(list, bin)
  bytes = Exp.pack(nil, UNION_COUNT, list)
  add_read(bin, bytes, Exp::Type::INT)
end

.init(index_bit_count, bin, min_hash_bit_count: Exp.int_val(-1), policy: CDT::HLLPolicy::DEFAULT) ⇒ Object

Create expression that creates a new HLL or resets an existing HLL with minhash bits.

Parameters:

  • policy (defaults to: CDT::HLLPolicy::DEFAULT)

    write policy, use HLLPolicy#Default for default

  • index_bit_count

    number of index bits. Must be between 4 and 16 inclusive.

  • min_hash_bit_count (defaults to: Exp.int_val(-1))

    number of min hash bits. Must be between 4 and 51 inclusive. Also, index_bit_count + min_hash_bit_count must be <= 64. Optional.

  • bin

    HLL bin or value expression



33
34
35
36
# File 'lib/aerospike/exp/exp_hll.rb', line 33

def self.init(index_bit_count, bin, min_hash_bit_count: Exp.int_val(-1), policy: CDT::HLLPolicy::DEFAULT)
  bytes = Exp.pack(nil, INIT, index_bit_count, min_hash_bit_count, policy.flags)
  add_write(bin, bytes)
end

.may_contain(list, bin) ⇒ Object

Create expression that returns one if HLL bin may contain all items in the list.

Examples

# Bin “a” may contain value “x” ArrayList<Value> list = new ArrayList<Value>() list.add(Value.get(“x”)) Exp.eq(HLLExp.mayContain(Exp.val(list), Exp.hllBin(“a”)), Exp.val(1))



143
144
145
146
# File 'lib/aerospike/exp/exp_hll.rb', line 143

def self.may_contain(list, bin)
  bytes = Exp.pack(nil, MAY_CONTAIN, list)
  add_read(bin, bytes, Exp::Type::INT)
end