[Groonga-commit] groonga/grnxx at ec66f6c [master] Update Column::set_key_attribute() to use an index if available. (#125)

Back to archive index

susumu.yata null+****@clear*****
Thu Dec 4 16:54:06 JST 2014


susumu.yata	2014-12-04 16:54:06 +0900 (Thu, 04 Dec 2014)

  New Revision: ec66f6c5d4944d03cb04c2e41eed74437054f1de
  https://github.com/groonga/grnxx/commit/ec66f6c5d4944d03cb04c2e41eed74437054f1de

  Message:
    Update Column::set_key_attribute() to use an index if available. (#125)

  Modified files:
    lib/grnxx/impl/column/scalar/int.cpp
    lib/grnxx/impl/column/scalar/text.cpp

  Modified: lib/grnxx/impl/column/scalar/int.cpp (+15 -9)
===================================================================
--- lib/grnxx/impl/column/scalar/int.cpp    2014-12-04 15:34:15 +0900 (509dcac)
+++ lib/grnxx/impl/column/scalar/int.cpp    2014-12-04 16:54:06 +0900 (1428370)
@@ -135,17 +135,23 @@ void Column<Int>::set_key_attribute() {
     throw "Self reference";  // TODO
   }
 
-  // TODO: An index should be used if available.
-  std::unordered_set<int64_t> set;
-  size_t valid_size = get_valid_size();
-  for (size_t i = 0; i < valid_size; ++i) try {
-    if (!values_[i].is_na()) {
-      if (!set.insert(values_[i].raw()).second) {
-        throw "Key duplicate";  // TODO
+  if (!indexes_.is_empty()) {
+    // TODO: Choose the best index.
+    if (!indexes_[0]->test_uniqueness()) {
+      throw "Key duplicate";  // TODO
+    }
+  } else {
+    std::unordered_set<int64_t> set;
+    size_t valid_size = get_valid_size();
+    for (size_t i = 0; i < valid_size; ++i) try {
+      if (!values_[i].is_na()) {
+        if (!set.insert(values_[i].raw()).second) {
+          throw "Key duplicate";  // TODO
+        }
       }
+    } catch (const std::bad_alloc &) {
+      throw "Memory allocation failed";  // TODO
     }
-  } catch (const std::bad_alloc &) {
-    throw "Memory allocation failed";  // TODO
   }
   is_key_ = true;
 }

  Modified: lib/grnxx/impl/column/scalar/text.cpp (+17 -10)
===================================================================
--- lib/grnxx/impl/column/scalar/text.cpp    2014-12-04 15:34:15 +0900 (281429c)
+++ lib/grnxx/impl/column/scalar/text.cpp    2014-12-04 16:54:06 +0900 (7ea812f)
@@ -194,18 +194,25 @@ void Column<Text>::set_key_attribute() {
   if (is_key_) {
     throw "Key column";  // TODO
   }
-  // TODO: An index should be used if available.
-  std::set<String> set;
-  size_t valid_size = get_valid_size();
-  for (size_t i = 0; i < valid_size; ++i) try {
-    Text value = get(Int(i));
-    if (!value.is_na()) {
-      if (!set.insert(String(value.raw_data(), value.raw_size())).second) {
-        throw "Key duplicate";  // TODO
+
+  if (!indexes_.is_empty()) {
+    // TODO: Choose the best index.
+    if (!indexes_[0]->test_uniqueness()) {
+      throw "Key duplicate";  // TODO
+    }
+  } else {
+    std::set<String> set;
+    size_t valid_size = get_valid_size();
+    for (size_t i = 0; i < valid_size; ++i) try {
+      Text value = get(Int(i));
+      if (!value.is_na()) {
+        if (!set.insert(String(value.raw_data(), value.raw_size())).second) {
+          throw "Key duplicate";  // TODO
+        }
       }
+    } catch (const std::bad_alloc &) {
+      throw "Memory allocation failed";  // TODO
     }
-  } catch (const std::bad_alloc &) {
-    throw "Memory allocation failed";  // TODO
   }
   is_key_ = true;
 }
-------------- next part --------------
HTML����������������������������...
Download 



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