Loading...
Searching...
No Matches
as_hll_operations.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2022 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
19/**
20 * @defgroup hll_operations HyperLogLog Operations
21 * @ingroup client_operations
22 *
23 * HyperLogLog (HLL) operations.
24 *
25 * HyperLogLog operations on HLL items nested in lists/maps are not currently
26 * supported by the server. The as_cdt_ctx argument in HLL operations must
27 * be set to NULL.
28 */
29
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/******************************************************************************
37 * TYPES
38 *****************************************************************************/
39
40/**
41 * HyperLogLog write flags.
42 *
43 * @ingroup hll_operations
44 */
45typedef enum as_hll_write_flags_e {
46 /**
47 * Default. Allow create or update.
48 */
50
51 /**
52 * If the bin already exists, the operation will be denied.
53 * If the bin does not exist, a new bin will be created.
54 */
56
57 /**
58 * If the bin already exists, the bin will be overwritten.
59 * If the bin does not exist, the operation will be denied.
60 */
62
63 /**
64 * Do not raise error if operation is denied.
65 */
67
68 /**
69 * Allow the resulting set to be the minimum of provided index bits.
70 * Also, allow the usage of less precise HLL algorithms when minhash bits
71 * of all participating sets do not match.
72 */
75
76/**
77 * HLL operation policy.
78 *
79 * @ingroup hll_operations
80 */
81typedef struct as_hll_policy_s {
82 uint64_t flags;
84
85/**
86 * @private
87 * HLL operation codes.
88 */
103
104/******************************************************************************
105 * PRIVATE FUNCTIONS
106 *****************************************************************************/
107
108AS_EXTERN bool
110 as_operations* ops, const char* name, as_cdt_ctx* ctx, uint16_t command
111 );
112
113AS_EXTERN bool
115 as_operations* ops, const char* name, as_cdt_ctx* ctx, uint16_t command, as_list* list
116 );
117
118/******************************************************************************
119 * PUBLIC FUNCTIONS
120 *****************************************************************************/
121
122/**
123 * Initialize HLL policy to default.
124 *
125 * @ingroup hll_operations
126 */
127static inline void
132
133/**
134 * Set HLL write flags in HLL policy.
135 *
136 * @ingroup hll_operations
137 */
138static inline void
140{
141 policy->flags = flags;
142}
143
144/**
145 * Create HLL init operation with minhash bits.
146 * Server creates a new HLL or resets an existing HLL.
147 * Server does not return a value.
148 *
149 * @param ops Operations array.
150 * @param name Name of bin.
151 * @param ctx Must set to NULL.
152 * @param policy Write policy. Use NULL for default.
153 * @param index_bit_count Number of index bits. Must be between 4 and 16 inclusive.
154 * @param mh_bit_count Number of min hash bits. Must be between 4 and 51 inclusive.
155 * Also, index_bit_count + mh_bit_count must be <= 64.
156 * @ingroup hll_operations
157 */
158AS_EXTERN bool
160 as_operations* ops, const char* name, as_cdt_ctx* ctx, as_hll_policy* policy,
161 int index_bit_count, int mh_bit_count
162 );
163
164/**
165 * Create HLL init operation.
166 * Server creates a new HLL or resets an existing HLL.
167 * Server does not return a value.
168 *
169 * @param ops Operations array.
170 * @param name Name of bin.
171 * @param ctx Must set to NULL.
172 * @param policy Write policy. Use NULL for default.
173 * @param index_bit_count Number of index bits. Must be between 4 and 16 inclusive.
174 * @ingroup hll_operations
175 */
176static inline bool
178 as_operations* ops, const char* name, as_cdt_ctx* ctx, as_hll_policy* policy,
179 int index_bit_count
180 )
181{
182 return as_operations_hll_init_mh(ops, name, ctx, policy, index_bit_count, -1);
183}
184
185/**
186 * Create HLL add operation with minhash bits.
187 * Server adds values to HLL set. If HLL bin does not exist, use bit counts to create HLL bin.
188 * Server returns number of entries that caused HLL to update a register.
189 *
190 * @param ops Operations array.
191 * @param name Name of bin.
192 * @param ctx Must set to NULL.
193 * @param policy Write policy. Use NULL for default.
194 * @param list List of values to be added.
195 * @param index_bit_count Number of index bits. Must be between 4 and 16 inclusive.
196 * @param mh_bit_count Number of min hash bits. Must be between 4 and 51 inclusive.
197 * Also, index_bit_count + mh_bit_count must be <= 64.
198 * @ingroup hll_operations
199 */
200AS_EXTERN bool
202 as_operations* ops, const char* name, as_cdt_ctx* ctx, as_hll_policy* policy,
203 as_list* list, int index_bit_count, int mh_bit_count
204 );
205
206/**
207 * Create HLL add operation with index bits.
208 * Server adds values to HLL set. If HLL bin does not exist, use bit counts to create HLL bin.
209 * Server returns number of entries that caused HLL to update a register.
210 *
211 * @param ops Operations array.
212 * @param name Name of bin.
213 * @param ctx Must set to NULL.
214 * @param policy Write policy. Use NULL for default.
215 * @param list List of values to be added.
216 * @param index_bit_count Number of index bits. Must be between 4 and 16 inclusive.
217 * @ingroup hll_operations
218 */
219static inline bool
221 as_operations* ops, const char* name, as_cdt_ctx* ctx, as_hll_policy* policy,
222 as_list* list, int index_bit_count
223 )
224{
225 return as_operations_hll_add_mh(ops, name, ctx, policy, list, index_bit_count, -1);
226}
227
228/**
229 * Create HLL update operation. This operation assumes HLL bin already exists.
230 * Server adds values to HLL set.
231 * Server returns number of entries that caused HLL to update a register.
232 *
233 * @param ops Operations array.
234 * @param name Name of bin.
235 * @param ctx Must set to NULL.
236 * @param policy Write policy. Use NULL for default.
237 * @param list List of values to be added.
238 * @ingroup hll_operations
239 */
240static inline bool
242 as_operations* ops, const char* name, as_cdt_ctx* ctx, as_hll_policy* policy,
243 as_list* list
244 )
245{
246 return as_operations_hll_add_mh(ops, name, ctx, policy, list, -1, -1);
247}
248
249/**
250 * Create HLL set union operation.
251 * Server sets union of specified HLL objects with HLL bin.
252 * Server does not return a value.
253 *
254 * @param ops Operations array.
255 * @param name Name of bin.
256 * @param ctx Must set to NULL.
257 * @param policy Write policy. Use NULL for default.
258 * @param list List of HLL as_bytes objects.
259 * @ingroup hll_operations
260 */
261AS_EXTERN bool
263 as_operations* ops, const char* name, as_cdt_ctx* ctx, as_hll_policy* policy,
264 as_list* list
265 );
266
267/**
268 * Create HLL refresh operation.
269 * Server updates the cached count (if stale) and returns the count.
270 *
271 * @param ops Operations array.
272 * @param name Name of bin.
273 * @param ctx Must set to NULL.
274 * @ingroup hll_operations
275 */
276AS_EXTERN bool
278 as_operations* ops, const char* name, as_cdt_ctx* ctx
279 );
280
281/**
282 * Create HLL fold operation.
283 * Servers folds index_bit_count to the specified value.
284 * This can only be applied when minhash bit count on the HLL bin is 0.
285 * Server does not return a value.
286 *
287 * @param ops Operations array.
288 * @param name Name of bin.
289 * @param ctx Must set to NULL.
290 * @param index_bit_count Number of index bits. Must be between 4 and 16 inclusive.
291 * @ingroup hll_operations
292 */
293AS_EXTERN bool
295 as_operations* ops, const char* name, as_cdt_ctx* ctx, int index_bit_count
296 );
297
298/**
299 * Create HLL get count operation.
300 * Server returns estimated number of elements in the HLL bin.
301 *
302 * @param ops Operations array.
303 * @param name Name of bin.
304 * @param ctx Must set to NULL.
305 * @ingroup hll_operations
306 */
307static inline bool
309 as_operations* ops, const char* name, as_cdt_ctx* ctx
310 )
311{
312 return as_operations_hll_read(ops, name, ctx, AS_HLL_OP_COUNT);
313}
314
315/**
316 * Create HLL get union operation.
317 * Server returns an HLL object that is the union of all specified HLL objects in the list
318 * with the HLL bin.
319 *
320 * @param ops Operations array.
321 * @param name Name of bin.
322 * @param ctx Must set to NULL.
323 * @param list List of HLL as_bytes objects.
324 * @ingroup hll_operations
325 */
326static inline bool
328 as_operations* ops, const char* name, as_cdt_ctx* ctx, as_list* list
329 )
330{
331 return as_operations_hll_read_list(ops, name, ctx, AS_HLL_OP_GET_UNION, list);
332}
333
334/**
335 * Create HLL get union count operation.
336 * Server returns estimated number of elements that would be contained by the union of these
337 * HLL objects.
338 *
339 * @param ops Operations array.
340 * @param name Name of bin.
341 * @param ctx Must set to NULL.
342 * @param list List of HLL as_bytes objects.
343 * @ingroup hll_operations
344 */
345static inline bool
347 as_operations* ops, const char* name, as_cdt_ctx* ctx, as_list* list
348 )
349{
350 return as_operations_hll_read_list(ops, name, ctx, AS_HLL_OP_UNION_COUNT, list);
351}
352
353/**
354 * Create HLL get intersect count operation.
355 * Server returns estimated number of elements that would be contained by the intersection of
356 * these HLL objects.
357 *
358 * @param ops Operations array.
359 * @param name Name of bin.
360 * @param ctx Must set to NULL.
361 * @param list List of HLL as_bytes objects.
362 * @ingroup hll_operations
363 */
364static inline bool
366 as_operations* ops, const char* name, as_cdt_ctx* ctx, as_list* list
367 )
368{
369 return as_operations_hll_read_list(ops, name, ctx, AS_HLL_OP_INTERSECT_COUNT, list);
370}
371
372/**
373 * Create HLL get similarity operation.
374 * Server returns estimated similarity of these HLL objects. Return type is a double.
375 *
376 * @param ops Operations array.
377 * @param name Name of bin.
378 * @param ctx Must set to NULL.
379 * @param list List of HLL as_bytes objects.
380 * @ingroup hll_operations
381 */
382static inline bool
384 as_operations* ops, const char* name, as_cdt_ctx* ctx, as_list* list
385 )
386{
387 return as_operations_hll_read_list(ops, name, ctx, AS_HLL_OP_SIMILARITY, list);
388}
389
390/**
391 * Create HLL describe operation.
392 * Server returns index and minhash bit counts used to create HLL bin in a list of integers.
393 * The list size is 2.
394 *
395 * @param ops Operations array.
396 * @param name Name of bin.
397 * @param ctx Must set to NULL.
398 * @ingroup hll_operations
399 */
400static inline bool
402 as_operations* ops, const char* name, as_cdt_ctx* ctx
403 )
404{
405 return as_operations_hll_read(ops, name, ctx, AS_HLL_OP_DESCRIBE);
406}
407
408#ifdef __cplusplus
409} // end extern "C"
410#endif
@ AS_HLL_OP_GET_UNION
@ AS_HLL_OP_DESCRIBE
@ AS_HLL_OP_FOLD
@ AS_HLL_OP_INTERSECT_COUNT
@ AS_HLL_OP_COUNT
@ AS_HLL_OP_MAY_CONTAIN
@ AS_HLL_OP_SIMILARITY
@ AS_HLL_OP_ADD
@ AS_HLL_OP_UNION_COUNT
@ AS_HLL_OP_UNION
@ AS_HLL_OP_INIT
@ AS_HLL_OP_REFRESH_COUNT
AS_EXTERN bool as_operations_hll_read_list(as_operations *ops, const char *name, as_cdt_ctx *ctx, uint16_t command, as_list *list)
AS_EXTERN bool as_operations_hll_read(as_operations *ops, const char *name, as_cdt_ctx *ctx, uint16_t command)
#define AS_EXTERN
Definition as_std.h:25
static bool as_operations_hll_get_union(as_operations *ops, const char *name, as_cdt_ctx *ctx, as_list *list)
static bool as_operations_hll_init(as_operations *ops, const char *name, as_cdt_ctx *ctx, as_hll_policy *policy, int index_bit_count)
AS_EXTERN bool as_operations_hll_add_mh(as_operations *ops, const char *name, as_cdt_ctx *ctx, as_hll_policy *policy, as_list *list, int index_bit_count, int mh_bit_count)
static bool as_operations_hll_get_intersect_count(as_operations *ops, const char *name, as_cdt_ctx *ctx, as_list *list)
static bool as_operations_hll_add(as_operations *ops, const char *name, as_cdt_ctx *ctx, as_hll_policy *policy, as_list *list, int index_bit_count)
static bool as_operations_hll_describe(as_operations *ops, const char *name, as_cdt_ctx *ctx)
as_hll_write_flags
AS_EXTERN bool as_operations_hll_fold(as_operations *ops, const char *name, as_cdt_ctx *ctx, int index_bit_count)
static void as_hll_policy_init(as_hll_policy *policy)
static void as_hll_policy_set_write_flags(as_hll_policy *policy, as_hll_write_flags flags)
AS_EXTERN bool as_operations_hll_set_union(as_operations *ops, const char *name, as_cdt_ctx *ctx, as_hll_policy *policy, as_list *list)
static bool as_operations_hll_get_union_count(as_operations *ops, const char *name, as_cdt_ctx *ctx, as_list *list)
AS_EXTERN bool as_operations_hll_init_mh(as_operations *ops, const char *name, as_cdt_ctx *ctx, as_hll_policy *policy, int index_bit_count, int mh_bit_count)
AS_EXTERN bool as_operations_hll_refresh_count(as_operations *ops, const char *name, as_cdt_ctx *ctx)
static bool as_operations_hll_update(as_operations *ops, const char *name, as_cdt_ctx *ctx, as_hll_policy *policy, as_list *list)
static bool as_operations_hll_get_count(as_operations *ops, const char *name, as_cdt_ctx *ctx)
static bool as_operations_hll_get_similarity(as_operations *ops, const char *name, as_cdt_ctx *ctx, as_list *list)
@ AS_HLL_WRITE_UPDATE_ONLY
@ AS_HLL_WRITE_ALLOW_FOLD
@ AS_HLL_WRITE_NO_FAIL
@ AS_HLL_WRITE_DEFAULT
@ AS_HLL_WRITE_CREATE_ONLY