/ src / minisketch / src / sketch.h
sketch.h
 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  
13  /** Abstract class for internal representation of a minisketch object. */
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(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