OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogutil commits / 987cd0d

Rename peek() to snapshot(), implement new peek()
987cd0d1c3f30fc409091886c90e1b02f1fd4ce7
by Linas Vepštas <linasvepstas@gmail.com> · 2025-12-19T06:18:35.000Z

Changed files (2) +15 -2

opencog/util/concurrent_queue.h +2 -1
……@@ -174,7 +174,8 @@ public:
174174 return the_queue.size();
175175 }
176176
177 std::queue<Element> peek() const
177 /// Return a copy of the entire queue, as it is at this moment.
178 std::queue<Element> snapshot() const
178179 {
179180 std::lock_guard<std::mutex> lock(the_mutex);
180181 std::queue<Element> copy(the_queue);
opencog/util/concurrent_set.h +13 -1
……@@ -211,13 +211,25 @@ public:
211211 return the_set.size();
212212 }
213213
214 std::set<Element, Compare> peek() const
214 /// Return entire contents of the container, as they are at just
215 /// this particular moment in time.
216 std::set<Element, Compare> snapshot() const
215217 {
216218 std::lock_guard<std::mutex> lock(the_mutex);
217219 std::set<Element, Compare> copy(the_set);
218220 return copy;
219221 }
220222
223 /// Return one element, any element from the container, as it is
224 /// right now, at just this moment.
225 std::optional<Element> peek() const
226 {
227 std::lock_guard<std::mutex> lock(the_mutex);
228 if (the_set.empty())
229 return std::nullopt;
230 return *the_set.begin();
231 }
232
221233 /// Erase all elements from the container.
222234 void clear()
223235 {