[Groonga-commit] groonga/grnxx at 93aa51f [master] Add grnxx::map::HashTable::sweep().

Back to archive index

susumu.yata null+****@clear*****
Wed Aug 21 11:39:09 JST 2013


susumu.yata	2013-08-21 11:39:09 +0900 (Wed, 21 Aug 2013)

  New Revision: 93aa51f985f568917447145356cfdc4e70fa8554
  https://github.com/groonga/grnxx/commit/93aa51f985f568917447145356cfdc4e70fa8554

  Message:
    Add grnxx::map::HashTable::sweep().

  Modified files:
    lib/grnxx/map/hash_table.cpp
    lib/grnxx/map/hash_table.hpp

  Modified: lib/grnxx/map/hash_table.cpp (+11 -0)
===================================================================
--- lib/grnxx/map/hash_table.cpp    2013-08-20 22:44:00 +0900 (889d228)
+++ lib/grnxx/map/hash_table.cpp    2013-08-21 11:39:09 +0900 (9875c78)
@@ -693,6 +693,17 @@ void HashTable<T>::defrag() {
 }
 
 template <typename T>
+void HashTable<T>::sweep(Duration lifetime) {
+  const Time threshold = clock_.now() - lifetime;
+  while (!queue_.empty()) {
+    QueueEntry &queue_entry = queue_.front();
+    if (queue_entry.time <= threshold) {
+      queue_.pop();
+    }
+  }
+}
+
+template <typename T>
 void HashTable<T>::truncate() {
   refresh_if_possible();
   std::unique_ptr<Pool> new_pool(Pool::create(storage_, storage_node_id_));

  Modified: lib/grnxx/map/hash_table.hpp (+2 -0)
===================================================================
--- lib/grnxx/map/hash_table.hpp    2013-08-20 22:44:00 +0900 (445b38e)
+++ lib/grnxx/map/hash_table.hpp    2013-08-21 11:39:09 +0900 (de9c7b7)
@@ -23,6 +23,7 @@
 #include <memory>
 #include <queue>
 
+#include "grnxx/duration.hpp"
 #include "grnxx/map.hpp"
 #include "grnxx/periodic_clock.hpp"
 #include "grnxx/time.hpp"
@@ -82,6 +83,7 @@ class HashTable : public Map<T> {
   bool replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id = nullptr);
 
   void defrag();
+  void sweep(Duration lifetime);
 
   void truncate();
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index