Action Engine
Loading...
Searching...
No Matches
node_map.h
Go to the documentation of this file.
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ACTIONENGINE_NODES_NODE_MAP_H_
16#define ACTIONENGINE_NODES_NODE_MAP_H_
17
18#include <memory>
19#include <string>
20#include <string_view>
21#include <vector>
22
23#include <absl/base/nullability.h>
24#include <absl/base/thread_annotations.h>
25#include <absl/container/flat_hash_map.h>
26
30
41
42namespace act {
43
53class NodeMap {
54 public:
55 explicit NodeMap(ChunkStoreFactory chunk_store_factory = {});
56
57 ~NodeMap();
58
59 // This class cannot be copied as each AsyncNode contains non-trivial state
60 // that cannot be duplicated safely.
61 NodeMap(const NodeMap& other) = delete;
62 NodeMap& operator=(const NodeMap& other) = delete;
63
64 // NodeMap can be safely moved by value.
65 NodeMap(NodeMap&& other) noexcept;
66 NodeMap& operator=(NodeMap&& other) noexcept;
67
68 auto Get(std::string_view id,
69 const ChunkStoreFactory& chunk_store_factory = {})
70 -> AsyncNode* absl_nonnull;
71 auto operator[](std::string_view id) -> AsyncNode* absl_nonnull;
72
73 auto Get(const std::vector<std::string_view>& ids,
74 const ChunkStoreFactory& chunk_store_factory = {})
75 -> std::vector<AsyncNode*>;
76
77 [[nodiscard]] std::unique_ptr<AsyncNode> Extract(std::string_view id);
78
79 auto insert(std::string_view id, AsyncNode&& node) -> AsyncNode&;
80 bool contains(std::string_view id) const;
81
82 private:
83 std::unique_ptr<ChunkStore> MakeChunkStore(
84 const ChunkStoreFactory& factory = {}, std::string_view id = "") const;
85
86 mutable act::Mutex mu_;
87 absl::flat_hash_map<std::string, std::unique_ptr<AsyncNode>> nodes_
88 ABSL_GUARDED_BY(mu_){};
89
90 ChunkStoreFactory chunk_store_factory_;
91};
92} // namespace act
93
94#endif // ACTIONENGINE_NODES_NODE_MAP_H_
Concurrency utilities for ActionEngine.
Provides the AsyncNode class for handling asynchronous data streams.
Definition async_node.h:70
An abstract interface for raw data storage and retrieval for ActionEngine nodes.