CCF
Loading...
Searching...
No Matches
set_handle.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ccf/kv/unit.h"
7
8namespace ccf::kv
9{
12 template <typename K, typename KSerialiser>
14 {
15 protected:
17
18 public:
19 using KeyType = K;
20
22
32 bool contains(const K& key)
33 {
34 return read_handle.has(KSerialiser::to_serialised(key));
35 }
36
46 bool contains_globally_committed(const K& key)
47 {
49 KSerialiser::to_serialised(key));
50 }
51
63 std::optional<Version> get_version_of_previous_write(const K& key)
64 {
66 KSerialiser::to_serialised(key));
67 }
68
78 template <class F>
79 void foreach(F&& f)
80 {
81 auto g = [&](
84 return f(KSerialiser::from_serialised(k_rep));
85 };
87 }
88
97 size_t size()
98 {
99 return read_handle.size();
100 }
101 };
102
105 template <typename K, typename KSerialiser, typename Unit>
107 {
108 protected:
110
111 public:
113
122 void insert(const K& key)
123 {
124 write_handle.put(KSerialiser::to_serialised(key), Unit::get());
125 }
126
133 void remove(const K& key)
134 {
135 write_handle.remove(KSerialiser::to_serialised(key));
136 }
137
140 void clear()
141 {
143 }
144 };
145
152 template <typename K, typename KSerialiser, typename Unit>
154 public ReadableSetHandle<K, KSerialiser>,
155 public WriteableSetHandle<K, KSerialiser, Unit>
156 {
157 protected:
159
162
163 public:
165 ccf::kv::untyped::ChangeSet& changes, const std::string& map_name) :
168 untyped_handle(changes, map_name)
169 {}
170 };
171}
Definition abstract_handle.h:8
Definition set_handle.h:14
bool contains_globally_committed(const K &key)
Definition set_handle.h:46
size_t size()
Definition set_handle.h:97
K KeyType
Definition set_handle.h:19
ReadableSetHandle(ccf::kv::untyped::MapHandle &uh)
Definition set_handle.h:21
std::optional< Version > get_version_of_previous_write(const K &key)
Definition set_handle.h:63
ccf::kv::untyped::MapHandle & read_handle
Definition set_handle.h:16
bool contains(const K &key)
Definition set_handle.h:32
Definition set_handle.h:156
ccf::kv::untyped::MapHandle untyped_handle
Definition set_handle.h:158
SetHandle(ccf::kv::untyped::ChangeSet &changes, const std::string &map_name)
Definition set_handle.h:164
Definition set_handle.h:107
void remove(const K &key)
Definition set_handle.h:133
WriteableSetHandle(ccf::kv::untyped::MapHandle &uh)
Definition set_handle.h:112
void clear()
Definition set_handle.h:140
ccf::kv::untyped::MapHandle & write_handle
Definition set_handle.h:109
void insert(const K &key)
Definition set_handle.h:122
Definition untyped_map_handle.h:18
void clear()
Definition untyped_map_handle.cpp:175
bool has(const KeyType &key)
Definition untyped_map_handle.cpp:145
bool has_globally_committed(const KeyType &key)
Definition untyped_map_handle.cpp:154
void put(const KeyType &key, const ValueType &value)
Definition untyped_map_handle.cpp:160
std::optional< Version > get_version_of_previous_write(const KeyType &key)
Definition untyped_map_handle.cpp:111
size_t size()
Definition untyped_map_handle.cpp:188
void remove(const KeyType &key)
Definition untyped_map_handle.cpp:168
void foreach(const ElementVisitorWithEarlyOut &fn)
Definition untyped_map_handle.cpp:183
ccf::ByteVector SerialisedEntry
Definition serialised_entry.h:8
Definition app_interface.h:19
Definition untyped_change_set.h:43