File: examples_test.go

package info (click to toggle)
golang-github-retailnext-hllpp 1.0.0+git20170901.6e8b6d3-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 196 kB
  • sloc: makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,218 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2015, RetailNext, Inc.
// This material contains trade secrets and confidential information of
// RetailNext, Inc.  Any use, reproduction, disclosure or dissemination
// is strictly prohibited without the explicit written permission
// of RetailNext, Inc.
// All rights reserved.
package hllpp

import "fmt"

func Example() {
	h := New()

	h.Add([]byte("barclay"))
	h.Add([]byte("reginald"))
	h.Add([]byte("barclay"))
	h.Add([]byte("broccoli"))

	fmt.Println(h.Count())
	// Output: 3
}

func ExampleNewWithConfig() {
	h, err := NewWithConfig(Config{
		Precision:       12,
		SparsePrecision: 14,
	})
	if err != nil {
		panic(err)
	}

	h.Add([]byte("qapla'"))
	h.Add([]byte("qapla'"))

	fmt.Println(h.Count())
	// Output: 1
}

func ExampleHLLPP_Marshal() {
	h := New()

	h.Add([]byte("hobbledehoyhood"))

	serialized := h.Marshal()
	h, err := Unmarshal(serialized)
	if err != nil {
		panic(err)
	}

	fmt.Println(h.Count())
	// Output: 1
}

func ExampleHLLPP_Merge() {
	h := New()
	h.Add([]byte("picard"))
	h.Add([]byte("janeway"))

	other := New()
	other.Add([]byte("picard"))
	other.Add([]byte("kirk"))

	err := h.Merge(other)
	if err != nil {
		panic(err)
	}

	fmt.Println(h.Count())
	// Output: 3
}