[Groonga-commit] groonga/grnxx at 6feb4f7 [master] Add defrag() to grnxx::Map.

Back to archive index

susumu.yata null+****@clear*****
Tue Aug 6 11:52:56 JST 2013


susumu.yata	2013-08-06 11:52:56 +0900 (Tue, 06 Aug 2013)

  New Revision: 6feb4f721cdcce3bd0c01e5cf76bf46fb5c9206e
  https://github.com/groonga/grnxx/commit/6feb4f721cdcce3bd0c01e5cf76bf46fb5c9206e

  Message:
    Add defrag() to grnxx::Map.

  Modified files:
    lib/grnxx/map.cpp
    lib/grnxx/map.hpp
    lib/grnxx/map/array_map.cpp
    lib/grnxx/map/array_map.hpp
    lib/grnxx/map/double_array.cpp
    lib/grnxx/map/double_array.hpp
    lib/grnxx/map/hash_table.cpp
    lib/grnxx/map/hash_table.hpp
    lib/grnxx/map/patricia.cpp
    lib/grnxx/map/patricia.hpp

  Modified: lib/grnxx/map.cpp (+6 -0)
===================================================================
--- lib/grnxx/map.cpp    2013-08-05 17:20:14 +0900 (9dd4753)
+++ lib/grnxx/map.cpp    2013-08-06 11:52:56 +0900 (c62e512)
@@ -243,6 +243,12 @@ bool Map<Bytes>::find_longest_prefix_match(KeyArg query, int64_t *key_id,
 }
 
 template <typename T>
+void Map<T>::defrag(double) {
+  GRNXX_ERROR() << "invalid operation";
+  throw LogicError();
+}
+
+template <typename T>
 void Map<T>::truncate() {
   GRNXX_ERROR() << "invalid operation";
   throw LogicError();

  Modified: lib/grnxx/map.hpp (+3 -0)
===================================================================
--- lib/grnxx/map.hpp    2013-08-05 17:20:14 +0900 (b85f1f3)
+++ lib/grnxx/map.hpp    2013-08-06 11:52:56 +0900 (b96baeb)
@@ -121,6 +121,9 @@ class Map {
                                          int64_t *key_id = nullptr,
                                          Key *key = nullptr);
 
+  // Defrag components.
+  virtual void defrag(double usage_rate_threshold);
+
   // Remove all the keys in "*this" and return true on success.
   virtual void truncate();
 

  Modified: lib/grnxx/map/array_map.cpp (+5 -0)
===================================================================
--- lib/grnxx/map/array_map.cpp    2013-08-05 17:20:14 +0900 (21a0c44)
+++ lib/grnxx/map/array_map.cpp    2013-08-06 11:52:56 +0900 (dad9f7e)
@@ -222,6 +222,11 @@ bool ArrayMap<T>::replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id) {
 }
 
 template <typename T>
+void ArrayMap<T>::defrag(double usage_rate_threshold) {
+  pool_->defrag(usage_rate_threshold);
+}
+
+template <typename T>
 void ArrayMap<T>::truncate() {
   pool_->truncate();
 }

  Modified: lib/grnxx/map/array_map.hpp (+2 -0)
===================================================================
--- lib/grnxx/map/array_map.hpp    2013-08-05 17:20:14 +0900 (776b941)
+++ lib/grnxx/map/array_map.hpp    2013-08-06 11:52:56 +0900 (5c6ef4a)
@@ -66,6 +66,8 @@ class ArrayMap : public Map<T> {
   bool remove(KeyArg key);
   bool replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id = nullptr);
 
+  void defrag(double usage_rate_threshold);
+
   void truncate();
 
  private:

  Modified: lib/grnxx/map/double_array.cpp (+5 -0)
===================================================================
--- lib/grnxx/map/double_array.cpp    2013-08-05 17:20:14 +0900 (ef0f338)
+++ lib/grnxx/map/double_array.cpp    2013-08-06 11:52:56 +0900 (9ab632c)
@@ -537,6 +537,11 @@ bool DoubleArray<Bytes>::replace(KeyArg src_key, KeyArg dest_key,
   return true;
 }
 
+void DoubleArray<Bytes>::defrag(double usage_rate_threshold) {
+  // TODO
+  pool_->defrag(usage_rate_threshold);
+}
+
 void DoubleArray<Bytes>::truncate() {
   // TODO: How to recycle nodes.
   Node * const node = &nodes_->get_value(ROOT_NODE_ID);

  Modified: lib/grnxx/map/double_array.hpp (+2 -0)
===================================================================
--- lib/grnxx/map/double_array.hpp    2013-08-05 17:20:14 +0900 (0ce1c00)
+++ lib/grnxx/map/double_array.hpp    2013-08-06 11:52:56 +0900 (545efda)
@@ -90,6 +90,8 @@ class DoubleArray<Bytes> : public Map<Bytes> {
   bool remove(KeyArg key);
   bool replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id = nullptr);
 
+  void defrag(double usage_rate_threshold);
+
   void truncate();
 
   bool find_longest_prefix_match(KeyArg query,

  Modified: lib/grnxx/map/hash_table.cpp (+6 -0)
===================================================================
--- lib/grnxx/map/hash_table.cpp    2013-08-05 17:20:14 +0900 (7bd0dbe)
+++ lib/grnxx/map/hash_table.cpp    2013-08-06 11:52:56 +0900 (fbe6513)
@@ -335,6 +335,12 @@ bool HashTable<T>::replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id) {
 }
 
 template <typename T>
+void HashTable<T>::defrag(double usage_rate_threshold) {
+  rebuild();
+  pool_->defrag(usage_rate_threshold);
+}
+
+template <typename T>
 void HashTable<T>::truncate() {
   refresh_table();
   if (max_key_id() == MAP_MIN_KEY_ID) {

  Modified: lib/grnxx/map/hash_table.hpp (+2 -0)
===================================================================
--- lib/grnxx/map/hash_table.hpp    2013-08-05 17:20:14 +0900 (9c19106)
+++ lib/grnxx/map/hash_table.hpp    2013-08-06 11:52:56 +0900 (2565423)
@@ -70,6 +70,8 @@ class HashTable : public Map<T> {
   bool remove(KeyArg key);
   bool replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id = nullptr);
 
+  void defrag(double usage_rate_threshold);
+
   void truncate();
 
  private:

  Modified: lib/grnxx/map/patricia.cpp (+11 -0)
===================================================================
--- lib/grnxx/map/patricia.cpp    2013-08-05 17:20:14 +0900 (cda6a46)
+++ lib/grnxx/map/patricia.cpp    2013-08-06 11:52:56 +0900 (f69cbbe)
@@ -587,6 +587,12 @@ bool Patricia<T>::replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id) {
 }
 
 template <typename T>
+void Patricia<T>::defrag(double usage_rate_threshold) {
+  // TODO
+  pool_->defrag(usage_rate_threshold);
+}
+
+template <typename T>
 void Patricia<T>::truncate() {
   Node &root_node = nodes_->get_value(ROOT_NODE_ID);
   pool_->truncate();
@@ -1468,6 +1474,11 @@ bool Patricia<Bytes>::find_longest_prefix_match(KeyArg query, int64_t *key_id,
   }
 }
 
+void Patricia<Bytes>::defrag(double usage_rate_threshold) {
+  defrag_nodes();
+  pool_->defrag(usage_rate_threshold);
+}
+
 void Patricia<Bytes>::truncate() {
   refresh_nodes();
   if (max_key_id() == MAP_MIN_KEY_ID) {

  Modified: lib/grnxx/map/patricia.hpp (+4 -0)
===================================================================
--- lib/grnxx/map/patricia.hpp    2013-08-05 17:20:14 +0900 (8d07738)
+++ lib/grnxx/map/patricia.hpp    2013-08-06 11:52:56 +0900 (a9b3e8a)
@@ -72,6 +72,8 @@ class Patricia : public Map<T> {
   bool remove(KeyArg key);
   bool replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id = nullptr);
 
+  void defrag(double usage_rate_threshold);
+
   void truncate();
 
  private:
@@ -127,6 +129,8 @@ class Patricia<Bytes> : public Map<Bytes> {
   bool find_longest_prefix_match(KeyArg query, int64_t *key_id = nullptr,
                                  Key *key = nullptr);
 
+  void defrag(double usage_rate_threshold);
+
   void truncate();
 
  private:
-------------- next part --------------
HTML����������������������������...
Download 



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