MCPcopy Create free account
hub / github.com/ElementsProject/elements / Minisketch

Class Minisketch

src/minisketch/include/minisketch.h:196–364  ·  view source on GitHub ↗

Simple RAII C++11 wrapper around the minisketch API. */

Source from the content-addressed store, hash-verified

194#if __cplusplus >= 201103L
195/** Simple RAII C++11 wrapper around the minisketch API. */
196class Minisketch
197{
198 struct Deleter
199 {
200 void operator()(minisketch* ptr) const
201 {
202 minisketch_destroy(ptr);
203 }
204 };
205
206 std::unique_ptr<minisketch, Deleter> m_minisketch;
207
208public:
209 /** Check whether the library supports fields of the given size. */
210 static bool BitsSupported(uint32_t bits) noexcept { return minisketch_bits_supported(bits); }
211
212 /** Get the highest supported implementation number. */
213 static uint32_t MaxImplementation() noexcept { return minisketch_implementation_max(); }
214
215 /** Check whether the library supports fields with a given size and implementation number.
216 * If a particular field size `bits` is supported, implementation 0 is always supported for it.
217 * Higher implementation numbers may or may not be available as well, up to MaxImplementation().
218 */
219 static bool ImplementationSupported(uint32_t bits, uint32_t implementation) noexcept { return minisketch_implementation_supported(bits, implementation); }
220
221 /** Given field size and a maximum number of decodable elements n, compute what capacity c to
222 * use so that sketches with more elements than n have a chance no higher than 2^-fpbits of
223 * being decoded incorrectly (and will instead fail when decoding for up to n elements).
224 *
225 * See minisketch_compute_capacity for more details. */
226 static size_t ComputeCapacity(uint32_t bits, size_t max_elements, uint32_t fpbits) noexcept { return minisketch_compute_capacity(bits, max_elements, fpbits); }
227
228 /** Reverse operation of ComputeCapacity. See minisketch_compute_max_elements. */
229 static size_t ComputeMaxElements(uint32_t bits, size_t capacity, uint32_t fpbits) noexcept { return minisketch_compute_max_elements(bits, capacity, fpbits); }
230
231 /** Construct a clone of the specified sketch. */
232 Minisketch(const Minisketch& sketch) noexcept
233 {
234 if (sketch.m_minisketch) {
235 m_minisketch = std::unique_ptr<minisketch, Deleter>(minisketch_clone(sketch.m_minisketch.get()));
236 }
237 }
238
239 /** Make this Minisketch a clone of the specified one. */
240 Minisketch& operator=(const Minisketch& sketch) noexcept
241 {
242 if (sketch.m_minisketch) {
243 m_minisketch = std::unique_ptr<minisketch, Deleter>(minisketch_clone(sketch.m_minisketch.get()));
244 }
245 return *this;
246 }
247
248 /** Check whether this Minisketch object is valid. */
249 explicit operator bool() const noexcept { return bool{m_minisketch}; }
250
251 /** Construct an (invalid) Minisketch object. */
252 Minisketch() noexcept = default;
253

Callers 3

CreateFPMethod · 0.70
CreateSketchesFunction · 0.50
MakeMinisketch32Function · 0.50

Calls 8

minisketch_cloneFunction · 0.85
minisketch_set_seedFunction · 0.85
minisketch_add_uint64Function · 0.85
minisketch_mergeFunction · 0.85
minisketch_deserializeFunction · 0.85
getMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by 1

CreateSketchesFunction · 0.40