Bitcoin Core 28.99.0
P2P Digital Currency
sketch.h
Go to the documentation of this file.
1/**********************************************************************
2 * Copyright (c) 2018 Pieter Wuille, Greg Maxwell, Gleb Naumenko *
3 * Distributed under the MIT software license, see the accompanying *
4 * file LICENSE or http://www.opensource.org/licenses/mit-license.php.*
5 **********************************************************************/
6
7#ifndef _MINISKETCH_STATE_H_
8#define _MINISKETCH_STATE_H_
9
10#include <stdint.h>
11#include <stdlib.h>
12
14class Sketch
15{
16 uint64_t m_canary;
18 const int m_bits;
19
20public:
21 Sketch(int implementation, int bits) : m_implementation(implementation), m_bits(bits) {}
22
23 void Ready() { m_canary = 0x6d496e536b65LU; }
24 void Check() const { if (m_canary != 0x6d496e536b65LU) abort(); }
25 void UnReady() { m_canary = 1; }
26 int Implementation() const { return m_implementation; }
27 int Bits() const { return m_bits; }
28
29 virtual ~Sketch() {}
30 virtual size_t Syndromes() const = 0;
31
32 virtual void Init(size_t syndromes) = 0;
33 virtual void Add(uint64_t element) = 0;
34 virtual void Serialize(unsigned char*) const = 0;
35 virtual void Deserialize(const unsigned char*) = 0;
36 virtual size_t Merge(const Sketch* other_sketch) = 0;
37 virtual void SetSeed(uint64_t seed) = 0;
38
39 virtual int Decode(int max_count, uint64_t* roots) const = 0;
40};
41
42#endif
Abstract class for internal representation of a minisketch object.
Definition: sketch.h:15
uint64_t m_canary
Definition: sketch.h:16
const int m_bits
Definition: sketch.h:18
virtual ~Sketch()
Definition: sketch.h:29
virtual void Serialize(unsigned char *) const =0
int Implementation() const
Definition: sketch.h:26
int Bits() const
Definition: sketch.h:27
virtual size_t Merge(const Sketch *other_sketch)=0
void Ready()
Definition: sketch.h:23
virtual void SetSeed(uint64_t seed)=0
void Check() const
Definition: sketch.h:24
virtual size_t Syndromes() const =0
void UnReady()
Definition: sketch.h:25
virtual void Add(uint64_t element)=0
virtual void Deserialize(const unsigned char *)=0
virtual int Decode(int max_count, uint64_t *roots) const =0
virtual void Init(size_t syndromes)=0
Sketch(int implementation, int bits)
Definition: sketch.h:21
const int m_implementation
Definition: sketch.h:17