Everett
Loading...
Searching...
No Matches
policy.h
Go to the documentation of this file.
1
13#pragma once
14
15#include <everett/registry.h>
16#include <everett/backend.h>
17
18#include <bit>
19#include <cstdint>
20#include <limits>
21#include <optional>
22#include <type_traits>
23
24namespace everett {
25 enum class stream_role : std::uint8_t { native, borrowed };
26
27 enum class bit_backspace_code : std::uint8_t { exponential_golomb = 0, golomb = 1 };
28 template <std::uint64_t Order = 0> struct exponential_golomb {
29 static_assert(Order <= 63, "exponential-Golomb order must be at most 63");
30 };
31 template <std::uint64_t M> struct golomb {
32 static_assert(M != 0, "Golomb modulus must be positive");
33 };
34
35 namespace policy_detail {
36 template <class Code> struct backspace_traits;
37 template <std::uint64_t Order> struct backspace_traits<exponential_golomb<Order>> {
38 static_assert(Order <= 63, "exponential-Golomb order must be at most 63");
40 static constexpr std::uint64_t parameter = Order;
41 };
42 template <std::uint64_t M> struct backspace_traits<golomb<M>> {
43 static_assert(M != 0, "Golomb modulus must be positive");
45 static constexpr std::uint64_t parameter = M;
46 };
47 }
48
49 // The registry chooses units and the common value width, if any. Sort
50 // encoding widths are converted to those units, including byte leaves
51 // below bit discriminators. Associated worlds and streams retain this policy.
52 template <class Registry = unsorted<std::optional<std::string>>, std::uint64_t GroupSize = 15,
53 class BackspaceCode = exponential_golomb<0>, std::uint64_t CodecBlockSize = GroupSize,
54 simd::architecture Arch = simd::scalar>
56 using architecture = Arch;
57 using registry_type = Registry;
59 static constexpr profile_unit unit = registry::unit;
60 static_assert(GroupSize >= 3 && GroupSize != std::numeric_limits<std::uint64_t>::max() &&
61 std::has_single_bit(GroupSize + 1), "group size must be 2^n - 1 and at least three");
62 static_assert(unit == profile_unit::bit || std::is_same_v<BackspaceCode, exponential_golomb<0>>,
63 "byte profiles use varints and require the default backspace policy");
64 static_assert(CodecBlockSize && CodecBlockSize <= std::numeric_limits<std::uint32_t>::max(),
65 "codec block size must fit a positive 32-bit count");
66 using backspace_encoding = BackspaceCode;
69 static constexpr std::uint64_t group_size = GroupSize;
70 static constexpr std::uint64_t codec_block_size = CodecBlockSize;
71 static constexpr unsigned class_bits = static_cast<unsigned>(std::bit_width(GroupSize));
72 static constexpr unsigned unit_shift = unit == profile_unit::byte ? 3 : 0;
73 static constexpr unsigned bits_per_unit = 1u << unit_shift;
74 static constexpr bool fixed_width = registry::fixed_width;
75 static constexpr std::optional<std::uint64_t> value_width = registry::value_width;
76 };
77
78 // The execution target is independent of the registry and serialized policy.
79 // Applications select a native profile at their admitted dispatch boundary.
80 template <simd::architecture Arch, class Registry = unsorted<std::optional<std::string>>,
81 std::uint64_t GroupSize = 15, class BackspaceCode = exponential_golomb<0>,
82 std::uint64_t CodecBlockSize = GroupSize>
84
85 // Explicit bit-addressed string tables leave one subtree for future sorts.
86 // Ordinary string tables use the byte-addressed storage_policy<> default.
89}
Shares explicit SIMD architecture traits with Everett's kernels.
Definition active_engine.h:18
stream_role
Definition policy.h:25
bit_backspace_code
Definition policy.h:27
profile_unit
Definition registry.h:29
Describes sort codes, encoding requirements and typed registry dispatch.
Definition registry.h:78
Definition policy.h:28
Definition policy.h:31
Definition registry.h:217
static constexpr profile_unit unit
Definition registry.h:222
static constexpr bool fixed_width
Definition registry.h:226
static constexpr auto value_width
Definition registry.h:224
Definition registry.h:76
Definition policy.h:55
static constexpr std::uint64_t group_size
Definition policy.h:69
Registry registry_type
Definition policy.h:57
Arch architecture
Definition policy.h:56
static constexpr unsigned unit_shift
Definition policy.h:72
BackspaceCode backspace_encoding
Definition policy.h:66
static constexpr std::uint64_t codec_block_size
Definition policy.h:70
static constexpr profile_unit unit
Definition policy.h:59
static constexpr std::optional< std::uint64_t > value_width
Definition policy.h:75
static constexpr unsigned class_bits
Definition policy.h:71
static constexpr std::uint64_t backspace_parameter
Definition policy.h:68
static constexpr unsigned bits_per_unit
Definition policy.h:73
static constexpr bit_backspace_code backspace_code
Definition policy.h:67
static constexpr bool fixed_width
Definition policy.h:74