Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
Loading...
Searching...
No Matches
binpack_encoder_cache.h
1#ifndef SOURCEMETA_BLAZE_BINPACK_ENCODER_CACHE_H_
2#define SOURCEMETA_BLAZE_BINPACK_ENCODER_CACHE_H_
3#ifndef DOXYGEN
4
5#ifndef SOURCEMETA_BLAZE_BINPACK_EXPORT
6#include <sourcemeta/blaze/binpack_export.h>
7#endif
8
9#include <sourcemeta/core/json.h>
10
11#include <functional> // std::reference_wrapper
12#include <map> // std::map
13#include <optional> // std::optional
14#include <utility> // std::pair
15
16namespace sourcemeta::blaze {
17
18class SOURCEMETA_BLAZE_BINPACK_EXPORT BinPackCache {
19public:
20 enum class Type : std::uint8_t { Standalone, PrefixLengthVarintPlusOne };
21 auto record(const sourcemeta::core::JSON::String &value,
22 const std::uint64_t offset, const Type type) -> void;
23 [[nodiscard]] auto find(const sourcemeta::core::JSON::String &value,
24 const Type type) const
25 -> std::optional<std::uint64_t>;
26
27#ifndef DOXYGEN
28 // This method is considered private. We only expose it for testing purposes
29 auto remove_oldest() -> void;
30#endif
31
32private:
33// Exporting symbols that depends on the standard C++ library is considered
34// safe.
35// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
36#if defined(_MSC_VER)
37#pragma warning(disable : 4251 4275)
38#endif
39 std::uint64_t byte_size_{0};
40 using Entry = std::pair<sourcemeta::core::JSON::String, Type>;
41 std::map<Entry, std::uint64_t> data_;
42 std::map<std::uint64_t, std::reference_wrapper<const Entry>> order_;
43#if defined(_MSC_VER)
44#pragma warning(default : 4251 4275)
45#endif
46};
47
48} // namespace sourcemeta::blaze
49
50#endif
51#endif