MCPcopy Create free account
hub / github.com/ElementsProject/elements / main

Function main

src/minisketch/doc/example.c:11–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include "../include/minisketch.h"
10
11int main(void) {
12
13 minisketch *sketch_a = minisketch_create(12, 0, 4);
14
15 for (int i = 3000; i < 3010; ++i) {
16 minisketch_add_uint64(sketch_a, i);
17 }
18
19 size_t sersize = minisketch_serialized_size(sketch_a);
20 assert(sersize == 12 * 4 / 8); // 4 12-bit values is 6 bytes.
21 unsigned char *buffer_a = malloc(sersize);
22 minisketch_serialize(sketch_a, buffer_a);
23 minisketch_destroy(sketch_a);
24
25 minisketch *sketch_b = minisketch_create(12, 0, 4); // Bob's own sketch
26 for (int i = 3002; i < 3012; ++i) {
27 minisketch_add_uint64(sketch_b, i);
28 }
29
30 sketch_a = minisketch_create(12, 0, 4); // Alice's sketch
31 minisketch_deserialize(sketch_a, buffer_a); // Load Alice's sketch
32 free(buffer_a);
33
34 // Merge the elements from sketch_a into sketch_b. The result is a sketch_b
35 // which contains all elements that occurred in Alice's or Bob's sets, but not
36 // in both.
37 minisketch_merge(sketch_b, sketch_a);
38
39 uint64_t differences[4];
40 ssize_t num_differences = minisketch_decode(sketch_b, 4, differences);
41 minisketch_destroy(sketch_a);
42 minisketch_destroy(sketch_b);
43 if (num_differences < 0) {
44 printf("More than 4 differences!\n");
45 } else {
46 ssize_t i;
47 for (i = 0; i < num_differences; ++i) {
48 printf("%u is in only one of the two sets\n", (unsigned)differences[i]);
49 }
50 }
51}

Callers

nothing calls this directly

Calls 9

minisketch_createFunction · 0.85
minisketch_add_uint64Function · 0.85
minisketch_serializeFunction · 0.85
minisketch_destroyFunction · 0.85
minisketch_deserializeFunction · 0.85
minisketch_mergeFunction · 0.85
minisketch_decodeFunction · 0.85
printfFunction · 0.85

Tested by

no test coverage detected