Bitcoin Core  22.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 
14 class Sketch
15 {
16  uint64_t m_canary;
17  const int m_implementation;
18  const int m_bits;
19 
20 public:
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(int 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
Sketch::Decode
virtual int Decode(int max_count, uint64_t *roots) const =0
Sketch::Syndromes
virtual size_t Syndromes() const =0
Sketch::Add
virtual void Add(uint64_t element)=0
Sketch::Implementation
int Implementation() const
Definition: sketch.h:30
Sketch
Abstract class for internal representation of a minisketch object.
Definition: sketch.h:14
Sketch::SetSeed
virtual void SetSeed(uint64_t seed)=0
Sketch::m_canary
uint64_t m_canary
Definition: sketch.h:20
Sketch::Deserialize
virtual void Deserialize(const unsigned char *)=0
Sketch::~Sketch
virtual ~Sketch()
Definition: sketch.h:33
Sketch::Serialize
virtual void Serialize(unsigned char *) const =0
Sketch::Sketch
Sketch(int implementation, int bits)
Definition: sketch.h:25
Sketch::Check
void Check() const
Definition: sketch.h:28
Sketch::m_implementation
const int m_implementation
Definition: sketch.h:21
Sketch::Ready
void Ready()
Definition: sketch.h:27
Sketch::Init
virtual void Init(int syndromes)=0
Sketch::Bits
int Bits() const
Definition: sketch.h:31
Sketch::Merge
virtual size_t Merge(const Sketch *other_sketch)=0
Sketch::m_bits
const int m_bits
Definition: sketch.h:22
Sketch::UnReady
void UnReady()
Definition: sketch.h:29