[Groonga-commit] groonga/grnxx at 5fe9d66 [master] Add Expression::evaluate() which accepts offset and limit.

Back to archive index

susumu.yata null+****@clear*****
Tue Mar 17 15:32:42 JST 2015


susumu.yata	2015-03-17 15:32:42 +0900 (Tue, 17 Mar 2015)

  New Revision: 5fe9d663895d9befc357236a682a78901f31d7f5
  https://github.com/groonga/grnxx/commit/5fe9d663895d9befc357236a682a78901f31d7f5

  Message:
    Add Expression::evaluate() which accepts offset and limit.

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

  Modified: include/grnxx/expression.hpp (+17 -0)
===================================================================
--- include/grnxx/expression.hpp    2015-03-17 15:31:59 +0900 (1bad27a)
+++ include/grnxx/expression.hpp    2015-03-17 15:32:42 +0900 (300a296)
@@ -64,6 +64,23 @@ class Expression {
   virtual void filter(ArrayCRef<Record> input_records,
                       ArrayRef<Record> *output_records) = 0;
 
+  // Extract true records.
+  //
+  // Evaluates the expression for "input_records" and stores true records
+  // into "*output_records".
+  // "*output_records" is truncated to fit the number of extracted records.
+	//
+  // The first "offset" true records are removed.
+  // The number of output records is at most "limit".
+  //
+  // Fails if "output_records->size()" is less than "input_records.size()".
+  //
+  // On failure, throws an exception.
+  virtual void filter(ArrayCRef<Record> input_records,
+                      ArrayRef<Record> *output_records,
+                      size_t offset,
+                      size_t limit) = 0;
+
   // Adjust scores of records.
   //
   // Evaluates the expression for "*records" and replaces the scores with

  Modified: lib/grnxx/impl/expression.cpp (+38 -0)
===================================================================
--- lib/grnxx/impl/expression.cpp    2015-03-17 15:31:59 +0900 (5f11995)
+++ lib/grnxx/impl/expression.cpp    2015-03-17 15:32:42 +0900 (e966a1e)
@@ -1610,6 +1610,44 @@ void Expression::filter(ArrayCRef<Record> input_records,
   *output_records = output_records->ref(0, count);
 }
 
+void Expression::filter(ArrayCRef<Record> input_records,
+                        ArrayRef<Record> *output_records,
+                        size_t offset,
+                        size_t limit) {
+  ArrayCRef<Record> input = input_records;
+  ArrayRef<Record> output = *output_records;
+  size_t count = 0;
+  while ((input.size() > 0) && (limit > 0)) {
+    size_t next_size = (input.size() < block_size_) ?
+                       input.size() : block_size_;
+    ArrayCRef<Record> next_input = input.cref(0, next_size);
+    ArrayRef<Record> next_output = output.ref(0, next_size);
+    root_->filter(next_input, &next_output);
+    input = input.cref(next_size);
+
+    if (offset > 0) {
+      if (offset >= next_output.size()) {
+        offset -= next_output.size();
+        next_output = next_output.ref(0, 0);
+      } else {
+        for (size_t i = offset; i < next_output.size(); ++i) {
+          next_output.set(i - offset, next_output[i]);
+        }
+        next_output = next_output.ref(0, next_output.size() - offset);
+        offset = 0;
+      }
+    }
+    if (next_output.size() > limit) {
+      next_output = next_output.ref(0, limit);
+    }
+    limit -= next_output.size();
+
+    output = output.ref(next_output.size());
+    count += next_output.size();
+  }
+  *output_records = output_records->ref(0, count);
+}
+
 void Expression::adjust(Array<Record> *records, size_t offset) {
   adjust(records->ref(offset));
 }

  Modified: lib/grnxx/impl/expression.hpp (+4 -0)
===================================================================
--- lib/grnxx/impl/expression.hpp    2015-03-17 15:31:59 +0900 (2b67cac)
+++ lib/grnxx/impl/expression.hpp    2015-03-17 15:32:42 +0900 (9e10588)
@@ -44,6 +44,10 @@ class Expression : public ExpressionInterface {
               size_t output_limit);
   void filter(ArrayCRef<Record> input_records,
               ArrayRef<Record> *output_records);
+  void filter(ArrayCRef<Record> input_records,
+              ArrayRef<Record> *output_records,
+              size_t offset,
+              size_t limit);
 
   void adjust(Array<Record> *records, size_t offset);
   void adjust(ArrayRef<Record> records);
-------------- next part --------------
HTML����������������������������...
Download 



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