[Groonga-commit] groonga/grnxx at 404ee72 [master] Add Index::test_uniqueness(). (#125)

Back to archive index

susumu.yata null+****@clear*****
Thu Dec 4 15:33:57 JST 2014


susumu.yata	2014-12-04 15:33:57 +0900 (Thu, 04 Dec 2014)

  New Revision: 404ee724b2dbd369e94e187b8c10cf34b22b1533
  https://github.com/groonga/grnxx/commit/404ee724b2dbd369e94e187b8c10cf34b22b1533

  Message:
    Add Index::test_uniqueness(). (#125)

  Modified files:
    include/grnxx/index.hpp
    lib/grnxx/impl/index.cpp
    lib/grnxx/impl/index.hpp

  Modified: include/grnxx/index.hpp (+6 -0)
===================================================================
--- include/grnxx/index.hpp    2014-12-04 12:52:42 +0900 (b86348e)
+++ include/grnxx/index.hpp    2014-12-04 15:33:57 +0900 (1a7ec9f)
@@ -80,6 +80,12 @@ class Index {
   // Return the index type.
   virtual IndexType type() const = 0;
 
+  // Test the uniqueness of the owner column.
+  //
+  // If the onwer column has no duplicate values, except N/A, returns true.
+  // Otherwise, returns false.
+  virtual bool test_uniqueness() const = 0;
+
   // Insert a new entry.
   //
   // On failure, throws an exception.

  Modified: lib/grnxx/impl/index.cpp (+33 -0)
===================================================================
--- lib/grnxx/impl/index.cpp    2014-12-04 12:52:42 +0900 (5ac090f)
+++ lib/grnxx/impl/index.cpp    2014-12-04 15:33:57 +0900 (f57a730)
@@ -316,6 +316,8 @@ class TreeIndex<Int> : public Index {
     return TREE_INDEX;
   }
 
+  bool test_uniqueness() const;
+
   void insert(Int row_id, const Datum &value);
   void remove(Int row_id, const Datum &value);
 
@@ -351,6 +353,15 @@ TreeIndex<Int>::TreeIndex(ColumnBase *column,
   }
 }
 
+bool TreeIndex<Int>::test_uniqueness() const {
+  for (const auto &it : map_) {
+    if (it.second.size() > 1) {
+      return false;
+    }
+  }
+  return true;
+}
+
 void TreeIndex<Int>::insert(Int row_id, const Datum &value) {
   auto result = map_[value.as_int()].insert(row_id);
   if (!result.second) {
@@ -476,6 +487,8 @@ class TreeIndex<Float> : public Index {
     return TREE_INDEX;
   }
 
+  bool test_uniqueness() const;
+
   void insert(Int row_id, const Datum &value);
   void remove(Int row_id, const Datum &value);
 
@@ -511,6 +524,15 @@ TreeIndex<Float>::TreeIndex(ColumnBase *column,
   }
 }
 
+bool TreeIndex<Float>::test_uniqueness() const {
+  for (const auto &it : map_) {
+    if (it.second.size() > 1) {
+      return false;
+    }
+  }
+  return true;
+}
+
 void TreeIndex<Float>::insert(Int row_id, const Datum &value) {
   auto result = map_[value.as_float()].insert(row_id);
   if (!result.second) {
@@ -637,6 +659,8 @@ class TreeIndex<Text> : public Index {
     return TREE_INDEX;
   }
 
+  bool test_uniqueness() const;
+
   void insert(Int row_id, const Datum &value);
   void remove(Int row_id, const Datum &value);
 
@@ -676,6 +700,15 @@ TreeIndex<Text>::TreeIndex(ColumnBase *column,
   }
 }
 
+bool TreeIndex<Text>::test_uniqueness() const {
+  for (const auto &it : map_) {
+    if (it.second.size() > 1) {
+      return false;
+    }
+  }
+  return true;
+}
+
 void TreeIndex<Text>::insert(Int row_id, const Datum &value) {
   Text text = value.as_text();
   String string;

  Modified: lib/grnxx/impl/index.hpp (+2 -0)
===================================================================
--- lib/grnxx/impl/index.hpp    2014-12-04 12:52:42 +0900 (b448f28)
+++ lib/grnxx/impl/index.hpp    2014-12-04 15:33:57 +0900 (caf8932)
@@ -26,6 +26,8 @@ class Index : public IndexInterface {
     return name_;
   }
 
+  virtual bool test_uniqueness() const = 0;
+
   virtual void insert(Int row_id, const Datum &value) = 0;
   virtual void remove(Int row_id, const Datum &value) = 0;
 
-------------- next part --------------
HTML����������������������������...
Download 



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