Files
bitcoin/src/sketch.h
fanquake cb59af38e7 Squashed 'src/minisketch/' changes from 3472e2f5ec..eb37a9b8e7
eb37a9b8e7 Merge sipa/minisketch#87: Avoid copy in self-assign
fe6557642e Merge sipa/minisketch#88: build: Add `-Wundef`
8ea298bfa7 Avoid copy in self-assign
978a3d8869 build: Add `-Wundef`
3387044179 Merge sipa/minisketch#86: doc: fix typo in sketch_impl.h
15c2d13b60 doc: fix typo in sketch_impl.h
7be08b8a46 Merge sipa/minisketch#85: Fixes for integer precision loss
00fb4a4d83 Avoid or make integer precision conversion explicit
9d62a4d27c Avoid the need to cast/convert to size_t for vector operations
19e06cc7af Prevent overflows from large capacity/max_elements

git-subtree-dir: src/minisketch
git-subtree-split: eb37a9b8e79f9e49d73b96a49bf97a96d9eb676c
2024-06-12 14:38:39 +01:00

43 lines
1.4 KiB
C++

/**********************************************************************
* Copyright (c) 2018 Pieter Wuille, Greg Maxwell, Gleb Naumenko *
* Distributed under the MIT software license, see the accompanying *
* file LICENSE or http://www.opensource.org/licenses/mit-license.php.*
**********************************************************************/
#ifndef _MINISKETCH_STATE_H_
#define _MINISKETCH_STATE_H_
#include <stdint.h>
#include <stdlib.h>
/** Abstract class for internal representation of a minisketch object. */
class Sketch
{
uint64_t m_canary;
const int m_implementation;
const int m_bits;
public:
Sketch(int implementation, int bits) : m_implementation(implementation), m_bits(bits) {}
void Ready() { m_canary = 0x6d496e536b65LU; }
void Check() const { if (m_canary != 0x6d496e536b65LU) abort(); }
void UnReady() { m_canary = 1; }
int Implementation() const { return m_implementation; }
int Bits() const { return m_bits; }
virtual ~Sketch() {}
virtual size_t Syndromes() const = 0;
virtual void Init(size_t syndromes) = 0;
virtual void Add(uint64_t element) = 0;
virtual void Serialize(unsigned char*) const = 0;
virtual void Deserialize(const unsigned char*) = 0;
virtual size_t Merge(const Sketch* other_sketch) = 0;
virtual void SetSeed(uint64_t seed) = 0;
virtual int Decode(int max_count, uint64_t* roots) const = 0;
};
#endif