[Groonga-commit] groonga/grnxx at 95c89d2 [master] Fix a bug that Column<Text> cannot find N/A. (#135)

Back to archive index

susumu.yata null+****@clear*****
Fri Dec 26 11:55:16 JST 2014


susumu.yata	2014-12-26 11:55:16 +0900 (Fri, 26 Dec 2014)

  New Revision: 95c89d22934173b0954d93d87d26520d8f4581b8
  https://github.com/groonga/grnxx/commit/95c89d22934173b0954d93d87d26520d8f4581b8

  Message:
    Fix a bug that Column<Text> cannot find N/A. (#135)

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

  Modified: lib/grnxx/impl/column/scalar/text.cpp (+29 -32)
===================================================================
--- lib/grnxx/impl/column/scalar/text.cpp    2014-12-25 16:48:52 +0900 (cc8855e)
+++ lib/grnxx/impl/column/scalar/text.cpp    2014-12-26 11:55:16 +0900 (062b332)
@@ -151,22 +151,7 @@ bool Column<Text>::contains(const Datum &datum) const {
     }
     return indexes_[0]->contains(datum);
   }
-  size_t valid_size = get_valid_size();
-  if (value.is_na()) {
-    for (size_t i = 0; i < valid_size; ++i) {
-      if (headers_[i] == na_header()) {
-        return true;
-      }
-    }
-  } else {
-    for (size_t i = 0; i < valid_size; ++i) {
-      // TODO: Improve this (get() checks the range of its argument).
-      if (get(Int(i)).match(value)) {
-        return true;
-      }
-    }
-  }
-  return false;
+  return !scan(value).is_na();
 }
 
 Int Column<Text>::find_one(const Datum &datum) const {
@@ -175,22 +160,7 @@ Int Column<Text>::find_one(const Datum &datum) const {
   if (!value.is_na() && !indexes_.is_empty()) {
     return indexes_[0]->find_one(datum);
   }
-  size_t valid_size = get_valid_size();
-  if (value.is_na()) {
-    for (size_t i = 0; i < valid_size; ++i) {
-      if (headers_[i] == na_header()) {
-        return Int(i);
-      }
-    }
-  } else {
-    for (size_t i = 0; i < valid_size; ++i) {
-      // TODO: Improve this (get() checks the range of its argument).
-      if (get(Int(i)).match(value)) {
-        return Int(i);
-      }
-    }
-  }
-  return Int::na();
+  return scan(value);
 }
 
 void Column<Text>::set_key_attribute() {
@@ -347,6 +317,33 @@ void Column<Text>::read(ArrayCRef<Record> records,
   }
 }
 
+Int Column<Text>::scan(const Text &value) const {
+  if (table_->max_row_id().is_na()) {
+    return Int::na();
+  }
+  size_t table_size = table_->max_row_id().raw() + 1;
+  size_t valid_size =
+      (headers_.size() < table_size) ? headers_.size() : table_size;
+  if (value.is_na()) {
+    if (headers_.size() < table_size) {
+      return table_->max_row_id();
+    }
+    for (size_t i = 0; i < valid_size; ++i) {
+      if (headers_[i] == na_header() && table_->_test_row(i)) {
+        return Int(i);
+      }
+    }
+  } else {
+    for (size_t i = 0; i < valid_size; ++i) {
+      // TODO: Improve this (get() checks the range of its argument).
+      if (get(Int(i)).match(value)) {
+        return Int(i);
+      }
+    }
+  }
+  return Int::na();
+}
+
 size_t Column<Text>::get_valid_size() const {
   if (table_->max_row_id().is_na()) {
     return 0;

  Modified: lib/grnxx/impl/column/scalar/text.hpp (+6 -0)
===================================================================
--- lib/grnxx/impl/column/scalar/text.hpp    2014-12-25 16:48:52 +0900 (3afd9a1)
+++ lib/grnxx/impl/column/scalar/text.hpp    2014-12-26 11:55:16 +0900 (e75ceb7)
@@ -75,6 +75,12 @@ class Column<Text> : public ColumnBase {
     return std::numeric_limits<uint64_t>::max();
   }
 
+  // Scan the column to find "value".
+  //
+  // If found, returns the row ID.
+  // If not found, returns N/A.
+  Int scan(const Text &value) const;
+
   // Return the active column size.
   size_t get_valid_size() const;
 
-------------- next part --------------
HTML����������������������������...
Descargar 



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