aboutsummaryrefslogtreecommitdiff
path: root/cc/primitive_set.h
diff options
context:
space:
mode:
authortholenst <tholenst@google.com>2019-11-13 02:31:39 -0800
committerCopybara-Service <copybara-worker@google.com>2019-11-13 02:32:09 -0800
commit4e237db7b48d0e1875cfe161ef8b0c21d42b0415 (patch)
treece72944e08a196875058489c52586be328fb2a71 /cc/primitive_set.h
parent14523c6b15eb1eba860760f7ab6f81df7ef6ee85 (diff)
downloadtink-4e237db7b48d0e1875cfe161ef8b0c21d42b0415.tar.gz
Add a method get_all to the C++ primitive_set class.
This is analogous to the java method getAll [1]. However, the return type is different since there's nothing as "Collection<List<Entry<P>>>" available anyhow. We could use a vector<vector<Entry<P>*>>, but I don't think that's an improvement. I suggest simply to return a vector of entries in C++ instead. PiperOrigin-RevId: 280157944
Diffstat (limited to 'cc/primitive_set.h')
-rw-r--r--cc/primitive_set.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/cc/primitive_set.h b/cc/primitive_set.h
index b9ccfe201..b1e720d1c 100644
--- a/cc/primitive_set.h
+++ b/cc/primitive_set.h
@@ -149,11 +149,23 @@ class PrimitiveSet {
// Returns the entry with the primary primitive.
const Entry<P>* get_primary() const { return primary_; }
+ // Returns all entries currently in this primitive set.
+ const std::vector<Entry<P>*> get_all() const {
+ absl::MutexLock lock(&primitives_mutex_);
+ std::vector<Entry<P>*> result;
+ for (const auto& prefix_and_vector : primitives_) {
+ for (const auto& primitive : prefix_and_vector.second) {
+ result.push_back(primitive.get());
+ }
+ }
+ return result;
+ }
+
private:
typedef std::unordered_map<std::string, Primitives>
CiphertextPrefixToPrimitivesMap;
Entry<P>* primary_; // the Entry<P> object is owned by primitives_
- absl::Mutex primitives_mutex_;
+ mutable absl::Mutex primitives_mutex_;
CiphertextPrefixToPrimitivesMap primitives_
ABSL_GUARDED_BY(primitives_mutex_);
};