[Groonga-commit] groonga/grnxx at 725e78a [master] Add ArrayCRef.

Back to archive index

susumu.yata null+****@clear*****
Mon Aug 11 11:22:49 JST 2014


susumu.yata	2014-08-11 11:22:49 +0900 (Mon, 11 Aug 2014)

  New Revision: 725e78a35eba85422da3c316a5df69e712d29971
  https://github.com/groonga/grnxx/commit/725e78a35eba85422da3c316a5df69e712d29971

  Message:
    Add ArrayCRef.

  Modified files:
    include/grnxx/array.hpp
    lib/grnxx/expression2.cpp

  Modified: include/grnxx/array.hpp (+374 -59)
===================================================================
--- include/grnxx/array.hpp    2014-08-08 17:42:47 +0900 (664e6fa)
+++ include/grnxx/array.hpp    2014-08-11 11:22:49 +0900 (8b01db8)
@@ -12,33 +12,109 @@ class ArrayErrorReporter {
   static void report_memory_error(Error *error);
 };
 
+template <typename T> class ArrayCRef;
+template <typename T> class ArrayRef;
+template <typename T> class Array;
+
+template <typename T>
+class ArrayCRef {
+ public:
+  using Value = T;
+
+  ArrayCRef() = default;
+  ArrayCRef(const ArrayCRef &) = default;
+
+  ArrayCRef &operator=(const ArrayCRef &) = default;
+
+  bool operator==(ArrayCRef<Value> rhs) const {
+    return (values_ == rhs.values_) && (size_ == rhs.size_);
+  }
+  bool operator!=(ArrayCRef<Value> rhs) const {
+    return (values_ != rhs.values_) || (size_ != rhs.size_);
+  }
+
+  ArrayCRef ref(Int offset = 0) const {
+    return ArrayCRef(values_ + offset, size_ - offset);
+  }
+  ArrayCRef ref(Int offset, Int size) const {
+    return ArrayCRef(values_ + offset, size);
+  }
+
+  Value get(Int i) const {
+    return values_[i];
+  }
+
+  const Value &operator[](Int i) const {
+    return values_[i];
+  }
+
+  Int size() const {
+    return size_;
+  }
+
+ private:
+  const Value *values_;
+  Int size_;
+
+  ArrayCRef(const Value *values, Int size) : values_(values), size_(size) {}
+
+  friend class ArrayRef<Value>;
+  friend class Array<Value>;
+};
+
 template <typename T>
 class ArrayRef {
  public:
+  using Value = T;
+
   ArrayRef() = default;
-  ArrayRef(T *values, Int size) : values_(values), size_(size) {}
   ArrayRef(const ArrayRef &) = default;
 
   ArrayRef &operator=(const ArrayRef &) = default;
 
-  ArrayRef ref(Int offset = 0) const {
+  operator ArrayCRef<Value>() const {
+    return ref();
+  }
+
+  bool operator==(ArrayCRef<Value> rhs) const {
+    return (values_ == rhs.values_) && (size_ == rhs.size_);
+  }
+  bool operator==(ArrayRef<Value> rhs) const {
+    return (values_ == rhs.values_) && (size_ == rhs.size_);
+  }
+
+  bool operator!=(ArrayCRef<Value> rhs) const {
+    return (values_ != rhs.values_) || (size_ != rhs.size_);
+  }
+  bool operator!=(ArrayRef<Value> rhs) const {
+    return (values_ != rhs.values_) || (size_ != rhs.size_);
+  }
+
+  ArrayCRef<Value> ref(Int offset = 0) const {
+    return ArrayCRef<Value>(values_ + offset, size_ - offset);
+  }
+  ArrayCRef<Value> ref(Int offset, Int size) const {
+    return ArrayCRef<Value>(values_ + offset, size);
+  }
+
+  ArrayRef ref(Int offset = 0) {
     return ArrayRef(values_ + offset, size_ - offset);
   }
-  ArrayRef ref(Int offset, Int size) const {
+  ArrayRef ref(Int offset, Int size) {
     return ArrayRef(values_ + offset, size);
   }
 
-  T get(Int i) const {
+  Value get(Int i) const {
     return values_[i];
   }
-  void set(Int i, T value) {
+  void set(Int i, Value value) {
     values_[i] = value;
   }
 
-  T &operator[](Int i) {
+  Value &operator[](Int i) {
     return values_[i];
   }
-  const T &operator[](Int i) const {
+  const Value &operator[](Int i) const {
     return values_[i];
   }
 
@@ -47,13 +123,28 @@ class ArrayRef {
   }
 
  private:
-  T *values_;
+  Value *values_;
   Int size_;
+
+  ArrayRef(Value *values, Int size) : values_(values), size_(size) {}
+
+  friend class Array<Value>;
 };
 
 template <typename T>
+inline bool operator==(ArrayCRef<T> lhs, ArrayRef<T> rhs) {
+  return rhs == lhs;
+}
+template <typename T>
+inline bool operator!=(ArrayCRef<T> lhs, ArrayRef<T> rhs) {
+  return rhs != lhs;
+}
+
+template <typename T>
 class Array {
  public:
+  using Value = T;
+
   Array() : values_() {}
   ~Array() {}
 
@@ -64,49 +155,59 @@ class Array {
     return *this;
   }
 
-  operator ArrayRef<T>() const {
+  operator ArrayCRef<Value>() const {
     return ref();
   }
+  operator ArrayRef<Value>() {
+    return ref();
+  }
+
+  ArrayCRef<Value> ref(Int offset = 0) const {
+    return ArrayCRef<Value>(values_.data() + offset, size() - offset);
+  }
+  ArrayCRef<Value> ref(Int offset, Int size) const {
+    return ArrayCRef<Value>(values_.data() + offset, size);
+  }
 
-  ArrayRef<T> ref(Int offset = 0) const {
-    return ArrayRef<T>(const_cast<T *>(data()) + offset, size() - offset);
+  ArrayRef<Value> ref(Int offset = 0) {
+    return ArrayRef<Value>(values_.data() + offset, size() - offset);
   }
-  ArrayRef<T> ref(Int offset, Int size) const {
-    return ArrayRef<T>(const_cast<T *>(data()) + offset, size);
+  ArrayRef<Value> ref(Int offset, Int size) {
+    return ArrayRef<Value>(values_.data() + offset, size);
   }
 
-  T get(Int i) const {
+  Value get(Int i) const {
     return values_[i];
   }
-  void set(Int i, T value) {
+  void set(Int i, Value value) {
     values_[i] = value;
   }
 
-  T &operator[](Int i) {
+  Value &operator[](Int i) {
     return values_[static_cast<size_t>(i)];
   }
-  const T &operator[](Int i) const {
+  const Value &operator[](Int i) const {
     return values_[static_cast<size_t>(i)];
   }
 
-  T &front() {
+  Value &front() {
     return values_.front();
   }
-  const T &front() const {
+  const Value &front() const {
     return values_.front();
   }
 
-  T &back() {
+  Value &back() {
     return values_.back();
   }
-  const T &back() const {
+  const Value &back() const {
     return values_.back();
   }
 
-  T *data() {
+  Value *data() {
     return values_.data();
   }
-  const T *data() const {
+  const Value *data() const {
     return values_.data();
   }
 
@@ -132,7 +233,7 @@ class Array {
     ArrayErrorReporter::report_memory_error(error);
     return false;
   }
-  bool resize(Error *error, Int new_size, const T &value) try {
+  bool resize(Error *error, Int new_size, const Value &value) try {
     values_.resize(new_size, value);
     return true;
   } catch (...) {
@@ -156,14 +257,14 @@ class Array {
     values_.erase(values_.begin() + i);
   }
 
-  bool push_back(Error *error, const T &value) try {
+  bool push_back(Error *error, const Value &value) try {
     values_.push_back(value);
     return true;
   } catch (...) {
     ArrayErrorReporter::report_memory_error(error);
     return false;
   }
-  bool push_back(Error *error, T &&value) try {
+  bool push_back(Error *error, Value &&value) try {
     values_.push_back(std::move(value));
     return true;
   } catch (...) {
@@ -175,7 +276,7 @@ class Array {
   }
 
  private:
-  std::vector<T> values_;
+  std::vector<Value> values_;
 };
 
 //class BoolReference {
@@ -218,34 +319,138 @@ class Array {
 //  return static_cast<Bool>(lhs) != rhs;
 //}
 
-// ArrayRef<Bool> is specialized because a bit does not have its own unique
+// ArrayCRef<Bool> is specialized because a bit does not have its own unique
 // address and thus a pointer type for Bool is not available.
 template <>
-class ArrayRef<Bool> {
+class ArrayCRef<Bool> {
  public:
-  ArrayRef() = default;
-  ArrayRef(uint64_t *blocks, Int offset, Int size)
+  using Value = Bool;
+
+  ArrayCRef() = default;
+  ArrayCRef(const ArrayCRef &) = default;
+
+  ArrayCRef &operator=(const ArrayCRef &) = default;
+
+  bool operator==(ArrayCRef<Value> rhs) const {
+    return (blocks_ == rhs.blocks_) &&
+           (offset_ == rhs.offset_) &&
+           (size_ == rhs.size_);
+  }
+  bool operator!=(ArrayCRef<Value> rhs) const {
+    return (blocks_ != rhs.blocks_) ||
+           (offset_ != rhs.offset_) ||
+           (size_ != rhs.size_);
+  }
+
+  ArrayCRef ref(Int offset = 0) const {
+    offset += static_cast<Int>(offset_);
+    return ArrayCRef(blocks_, offset, size() - offset);
+  }
+  ArrayCRef ref(Int offset, Int size) const {
+    offset += static_cast<Int>(offset_);
+    return ArrayCRef(blocks_, offset, size);
+  }
+
+  Value get(Int i) const {
+    i += static_cast<Int>(offset_);
+    return (blocks_[i / 64] & (uint64_t(1) << (i % 64))) != 0;
+  }
+
+  Value operator[](Int i) const {
+    i += static_cast<Int>(offset_);
+    return (blocks_[i / 64] & (uint64_t(1) << (i % 64))) != 0;
+  }
+
+  // TODO: For optimization.
+//  const uint64_t *blocks() const {
+//    return blocks_;
+//  }
+//  Int offset() const {
+//    return static_cast<Int>(offset_);
+//  }
+
+  Int size() const {
+    return static_cast<Int>(size_);
+  }
+
+ private:
+  const uint64_t *blocks_;
+  struct {
+    uint64_t offset_:16;
+    uint64_t size_:48;
+  };
+
+  ArrayCRef(const uint64_t *blocks, Int offset, Int size)
       : blocks_(blocks + (offset / 64)),
         offset_(static_cast<uint64_t>(offset % 64)),
         size_(static_cast<uint64_t>(size)) {}
+
+  friend class ArrayRef<Value>;
+  friend class Array<Value>;
+};
+
+// ArrayRef<Bool> is specialized because a bit does not have its own unique
+// address and thus a pointer type for Bool is not available.
+template <>
+class ArrayRef<Bool> {
+ public:
+  using Value = Bool;
+
+  ArrayRef() = default;
   ArrayRef(const ArrayRef &) = default;
 
   ArrayRef &operator=(const ArrayRef &) = default;
 
-  ArrayRef ref(Int offset = 0) const {
+
+  bool operator==(ArrayCRef<Value> rhs) const {
+    return (blocks_ == rhs.blocks_) &&
+           (offset_ == rhs.offset_) &&
+           (size_ == rhs.size_);
+  }
+  bool operator==(ArrayRef<Value> rhs) const {
+    return (blocks_ == rhs.blocks_) &&
+           (offset_ == rhs.offset_) &&
+           (size_ == rhs.size_);
+  }
+
+  bool operator!=(ArrayCRef<Value> rhs) const {
+    return (blocks_ != rhs.blocks_) ||
+           (offset_ != rhs.offset_) ||
+           (size_ != rhs.size_);
+  }
+  bool operator!=(ArrayRef<Value> rhs) const {
+    return (blocks_ == rhs.blocks_) ||
+           (offset_ == rhs.offset_) ||
+           (size_ == rhs.size_);
+  }
+
+  operator ArrayCRef<Value>() const {
+    return ref();
+  }
+
+  ArrayCRef<Value> ref(Int offset = 0) const {
+    offset += static_cast<Int>(offset_);
+    return ArrayCRef<Value>(blocks_, offset, size() - offset);
+  }
+  ArrayCRef<Value> ref(Int offset, Int size) const {
+    offset += static_cast<Int>(offset_);
+    return ArrayCRef<Value>(blocks_, offset, size);
+  }
+
+  ArrayRef ref(Int offset = 0) {
     offset += static_cast<Int>(offset_);
     return ArrayRef(blocks_, offset, size() - offset);
   }
-  ArrayRef ref(Int offset, Int size) const {
+  ArrayRef ref(Int offset, Int size) {
     offset += static_cast<Int>(offset_);
     return ArrayRef(blocks_, offset, size);
   }
 
-  Bool get(Int i) const {
+  Value get(Int i) const {
     i += static_cast<Int>(offset_);
     return (blocks_[i / 64] & (uint64_t(1) << (i % 64))) != 0;
   }
-  void set(Int i, Bool value) {
+  void set(Int i, Value value) {
     i += static_cast<Int>(offset_);
     if (value) {
       blocks_[i / 64] |= uint64_t(1) << (i % 64);
@@ -258,7 +463,7 @@ class ArrayRef<Bool> {
 //    i += static_cast<Int>(offset_);
 //    return BoolReference(&blocks_[i / 64], uint64_t(1) << (i % 64));
 //  }
-  Bool operator[](Int i) const {
+  Value operator[](Int i) const {
     i += static_cast<Int>(offset_);
     return (blocks_[i / 64] & (uint64_t(1) << (i % 64))) != 0;
   }
@@ -281,6 +486,13 @@ class ArrayRef<Bool> {
     uint64_t offset_:16;
     uint64_t size_:48;
   };
+
+  ArrayRef(uint64_t *blocks, Int offset, Int size)
+      : blocks_(blocks + (offset / 64)),
+        offset_(static_cast<uint64_t>(offset % 64)),
+        size_(static_cast<uint64_t>(size)) {}
+
+  friend class Array<Value>;
 };
 
 // Array<Bool> is specialized because a bit does not have its own unique
@@ -288,6 +500,8 @@ class ArrayRef<Bool> {
 template <>
 class Array<Bool> {
  public:
+  using Value = Bool;
+
   Array() : blocks_(), size_(0) {}
   ~Array() {}
 
@@ -298,22 +512,31 @@ class Array<Bool> {
     return *this;
   }
 
-  operator ArrayRef<Bool>() const {
+  operator ArrayCRef<Value>() const {
+    return ref();
+  }
+  operator ArrayRef<Value>() {
     return ref();
   }
 
-  ArrayRef<Bool> ref(Int offset = 0) const {
-    return ArrayRef<Bool>(const_cast<uint64_t *>(blocks()),
-                          offset, size() - offset);
+  ArrayCRef<Value> ref(Int offset = 0) const {
+    return ArrayCRef<Value>(blocks_.data(), offset, size() - offset);
+  }
+  ArrayCRef<Value> ref(Int offset, Int size) const {
+    return ArrayCRef<Value>(blocks_.data(), offset, size);
+  }
+
+  ArrayRef<Value> ref(Int offset = 0) {
+    return ArrayRef<Value>(blocks_.data(), offset, size() - offset);
   }
-  ArrayRef<Bool> ref(Int offset, Int size) const {
-    return ArrayRef<Bool>(const_cast<uint64_t *>(blocks()), offset, size);
+  ArrayRef<Value> ref(Int offset, Int size) {
+    return ArrayRef<Value>(blocks_.data(), offset, size);
   }
 
-  Bool get(Int i) const {
+  Value get(Int i) const {
     return (blocks_[i / 64] & (uint64_t(1) << (i % 64))) != 0;
   }
-  void set(Int i, Bool value) {
+  void set(Int i, Value value) {
     if (value) {
       blocks_[i / 64] |= uint64_t(1) << (i % 64);
     } else {
@@ -324,21 +547,21 @@ class Array<Bool> {
 //  BoolReference operator[](Int i) {
 //    return BoolReference(&blocks_[i / 64], uint64_t(1) << (i % 64));
 //  }
-  Bool operator[](Int i) const {
+  Value operator[](Int i) const {
     return (blocks_[i / 64] & (uint64_t(1) << (i % 64))) != 0;
   }
 
 //  BoolReference front() {
 //    return BoolReference(&blocks_[0], 1);
 //  }
-  Bool front() const {
+  Value front() const {
     return (blocks_[0] & 1) != 0;
   }
 
 //  BoolReference back() {
 //    return operator[](size_ - 1);
 //  }
-  Bool back() const {
+  Value back() const {
     return operator[](size_ - 1);
   }
 
@@ -368,7 +591,7 @@ class Array<Bool> {
     size_ = new_size;
     return true;
   }
-  bool resize(Error *error, Int new_size, Bool value) {
+  bool resize(Error *error, Int new_size, Value value) {
     if (!blocks_.resize(error, (new_size + 63) / 64,
                         value ? ~uint64_t(0) : uint64_t(0))) {
       return false;
@@ -390,7 +613,7 @@ class Array<Bool> {
 //    values_.erase(values_.begin() + i);
 //  }
 
-  bool push_back(Error *error, Bool value) {
+  bool push_back(Error *error, Value value) {
     if ((size_ % 64) == 0) {
       if (!blocks_.push_back(error, 0)) {
         return false;
@@ -417,18 +640,98 @@ class Array<Bool> {
 };
 
 template <>
+class ArrayCRef<Record> {
+ public:
+  using Value = Record;
+
+  ArrayCRef() = default;
+  ArrayCRef(const ArrayCRef &) = default;
+
+  ArrayCRef &operator=(const ArrayCRef &) = default;
+
+  bool operator==(ArrayCRef<Record> rhs) const {
+    return (records_ == rhs.records_) && (size_ == rhs.size_);
+  }
+  bool operator!=(ArrayCRef<Record> rhs) const {
+    return (records_ != rhs.records_) || (size_ != rhs.size_);
+  }
+
+  ArrayCRef ref(Int offset = 0) const {
+    return ArrayCRef(records_ + offset, size_ - offset);
+  }
+  ArrayCRef ref(Int offset, Int size) const {
+    return ArrayCRef(records_ + offset, size);
+  }
+
+  Record get(Int i) const {
+    return records_[i];
+  }
+  Int get_row_id(Int i) const {
+    return records_[i].row_id;
+  }
+  Float get_score(Int i) const {
+    return records_[i].score;
+  }
+
+  Record operator[](Int i) const {
+    return records_[i];
+  }
+
+  Int size() const {
+    return size_;
+  }
+
+ private:
+  const Record *records_;
+  Int size_;
+
+  ArrayCRef(const Record *records, Int size)
+      : records_(records),
+        size_(size) {}
+
+  friend class ArrayRef<Value>;
+  friend class Array<Value>;
+};
+
+template <>
 class ArrayRef<Record> {
  public:
+  using Value = Record;
+
   ArrayRef() = default;
-  ArrayRef(Record *records, Int size) : records_(records), size_(size) {}
   ArrayRef(const ArrayRef &) = default;
 
   ArrayRef &operator=(const ArrayRef &) = default;
 
-  ArrayRef ref(Int offset = 0) const {
+  bool operator==(ArrayCRef<Record> rhs) const {
+    return (records_ == rhs.records_) && (size_ == rhs.size_);
+  }
+  bool operator==(ArrayRef<Record> rhs) const {
+    return (records_ == rhs.records_) && (size_ == rhs.size_);
+  }
+
+  bool operator!=(ArrayCRef<Record> rhs) const {
+    return (records_ != rhs.records_) || (size_ != rhs.size_);
+  }
+  bool operator!=(ArrayRef<Record> rhs) const {
+    return (records_ != rhs.records_) || (size_ != rhs.size_);
+  }
+
+  operator ArrayCRef<Record>() const {
+    return ref();
+  }
+
+  ArrayCRef<Record> ref(Int offset = 0) const {
+    return ArrayCRef<Record>(records_ + offset, size_ - offset);
+  }
+  ArrayCRef<Record> ref(Int offset, Int size) const {
+    return ArrayCRef<Record>(records_ + offset, size);
+  }
+
+  ArrayRef ref(Int offset = 0) {
     return ArrayRef(records_ + offset, size_ - offset);
   }
-  ArrayRef ref(Int offset, Int size) const {
+  ArrayRef ref(Int offset, Int size) {
     return ArrayRef(records_ + offset, size);
   }
 
@@ -466,6 +769,10 @@ class ArrayRef<Record> {
  private:
   Record *records_;
   Int size_;
+
+  ArrayRef(Record *records, Int size) : records_(records), size_(size) {}
+
+  friend class Array<Value>;
 };
 
 template <>
@@ -481,17 +788,25 @@ class Array<Record> {
     return *this;
   }
 
-  operator ArrayRef<Record>() const {
+  operator ArrayCRef<Record>() const {
     return ref();
   }
+  operator ArrayRef<Record>() {
+    return ref();
+  }
+
+  ArrayCRef<Record> ref(Int offset = 0) const {
+    return ArrayCRef<Record>(records_.data() + offset, size() - offset);
+  }
+  ArrayCRef<Record> ref(Int offset, Int size) const {
+    return ArrayCRef<Record>(records_.data() + offset, size);
+  }
 
-  ArrayRef<Record> ref(Int offset = 0) const {
-    return ArrayRef<Record>(
-        const_cast<Record *>(records_.data()) + offset, size() - offset);
+  ArrayRef<Record> ref(Int offset = 0) {
+    return ArrayRef<Record>(records_.data() + offset, size() - offset);
   }
-  ArrayRef<Record> ref(Int offset, Int size) const {
-    return ArrayRef<Record>(
-        const_cast<Record *>(records_.data()) + offset, size);
+  ArrayRef<Record> ref(Int offset, Int size) {
+    return ArrayRef<Record>(records_.data() + offset, size);
   }
 
   Record get(Int i) const {

  Modified: lib/grnxx/expression2.cpp (+45 -45)
===================================================================
--- lib/grnxx/expression2.cpp    2014-08-08 17:42:47 +0900 (6ae7db1)
+++ lib/grnxx/expression2.cpp    2014-08-11 11:22:49 +0900 (be6f627)
@@ -41,11 +41,11 @@ class Node {
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
   virtual bool filter(Error *error,
-                      const ArrayRef<Record> &input_records,
+                      ArrayCRef<Record> input_records,
                       ArrayRef<Record> *output_records) = 0;
   // TODO
 //  virtual bool filter(Error *error,
-//                      const ArrayRef<Record> &input_records,
+//                      ArrayCRef<Record> input_records,
 //                      Array<Record> *output_records) = 0;
 
   // Adjust scores of records.
@@ -74,7 +74,7 @@ class TypedNode : public Node {
   }
 
   virtual bool filter(Error *error,
-                      const ArrayRef<Record> &input_records,
+                      ArrayCRef<Record> input_records,
                       ArrayRef<Record> *output_records);
   virtual bool adjust(Error *error, ArrayRef<Record> *records);
 
@@ -86,13 +86,13 @@ class TypedNode : public Node {
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
   virtual bool evaluate(Error *error,
-                        const ArrayRef<Record> &records,
+                        ArrayCRef<Record> records,
                         ArrayRef<Value> *results) = 0;
 };
 
 template <typename T>
 bool TypedNode<T>::filter(Error *error,
-                          const ArrayRef<Record> &input_records,
+                          ArrayCRef<Record> input_records,
                           ArrayRef<Record> *output_records) {
   // Only TypedNode<Bool> supports filter().
   GRNXX_ERROR_SET(error, INVALID_OPERATION, "Invalid operation");
@@ -101,7 +101,7 @@ bool TypedNode<T>::filter(Error *error,
 
 template <>
 bool TypedNode<Bool>::filter(Error *error,
-                             const ArrayRef<Record> &input_records,
+                             ArrayCRef<Record> input_records,
                              ArrayRef<Record> *output_records) {
   // TODO: This implementation should be overridden by derived classes.
   Array<Bool> results;
@@ -164,7 +164,7 @@ class DatumNode : public TypedNode<T> {
   }
 
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Value> *results);
 
  private:
@@ -173,7 +173,7 @@ class DatumNode : public TypedNode<T> {
 
 template <typename T>
 bool DatumNode<T>::evaluate(Error *error,
-                            const ArrayRef<Record> &records,
+                            ArrayCRef<Record> records,
                             ArrayRef<Value> *results) {
   for (Int i = 0; i < records.size(); ++i) {
     (*results)[i] = datum_;
@@ -195,10 +195,10 @@ class DatumNode<Bool> : public TypedNode<Bool> {
   }
 
   bool filter(Error *error,
-              const ArrayRef<Record> &input_records,
+              ArrayCRef<Record> input_records,
               ArrayRef<Record> *output_records);
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Bool> *results);
 
  private:
@@ -206,10 +206,10 @@ class DatumNode<Bool> : public TypedNode<Bool> {
 };
 
 bool DatumNode<Bool>::filter(Error *error,
-                             const ArrayRef<Record> &input_records,
+                             ArrayCRef<Record> input_records,
                              ArrayRef<Record> *output_records) {
   if (datum_) {
-    if (&input_records != output_records) {
+    if (input_records != *output_records) {
       for (Int i = 0; i < input_records.size(); ++i) {
         output_records->set(i, input_records.get(i));
       }
@@ -221,7 +221,7 @@ bool DatumNode<Bool>::filter(Error *error,
 }
 
 bool DatumNode<Bool>::evaluate(Error *error,
-                               const ArrayRef<Record> &records,
+                               ArrayCRef<Record> records,
                                ArrayRef<Bool> *results) {
   // TODO: Fill results per 64 bits.
   for (Int i = 0; i < records.size(); ++i) {
@@ -245,7 +245,7 @@ class DatumNode<Float> : public TypedNode<Float> {
 
   bool adjust(Error *error, ArrayRef<Record> *records);
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Float> *results);
 
  private:
@@ -260,7 +260,7 @@ bool DatumNode<Float>::adjust(Error *error, ArrayRef<Record> *records) {
 }
 
 bool DatumNode<Float>::evaluate(Error *error,
-                                const ArrayRef<Record> &records,
+                                ArrayCRef<Record> records,
                                 ArrayRef<Float> *results) {
   for (Int i = 0; i < records.size(); ++i) {
     (*results)[i] = datum_;
@@ -283,7 +283,7 @@ class DatumNode<Text> : public TypedNode<Text> {
   }
 
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Text> *results);
 
  private:
@@ -291,7 +291,7 @@ class DatumNode<Text> : public TypedNode<Text> {
 };
 
 bool DatumNode<Text>::evaluate(Error *error,
-                               const ArrayRef<Record> &records,
+                               ArrayCRef<Record> records,
                                ArrayRef<Text> *results) {
   Text datum = Text(datum_.data(), datum_.size());
   for (Int i = 0; i < records.size(); ++i) {
@@ -314,12 +314,12 @@ class RowIDNode : public TypedNode<Int> {
   }
 
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Int> *results);
 };
 
 bool RowIDNode::evaluate(Error *error,
-                         const ArrayRef<Record> &records,
+                         ArrayCRef<Record> records,
                          ArrayRef<Int> *results) {
   for (Int i = 0; i < records.size(); ++i) {
     (*results)[i] = records.get_row_id(i);
@@ -341,7 +341,7 @@ class ScoreNode : public TypedNode<Float> {
 
   bool adjust(Error *error, ArrayRef<Record> *records);
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Float> *results);
 };
 
@@ -351,7 +351,7 @@ bool ScoreNode::adjust(Error *error, ArrayRef<Record> *records) {
 }
 
 bool ScoreNode::evaluate(Error *error,
-                         const ArrayRef<Record> &records,
+                         ArrayCRef<Record> records,
                          ArrayRef<Float> *results) {
   for (Int i = 0; i < records.size(); ++i) {
     (*results)[i] = records.get_score(i);
@@ -375,7 +375,7 @@ class ColumnNode : public TypedNode<T> {
   }
 
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Value> *results);
 
  private:
@@ -384,7 +384,7 @@ class ColumnNode : public TypedNode<T> {
 
 template <typename T>
 bool ColumnNode<T>::evaluate(Error *error,
-                             const ArrayRef<Record> &records,
+                             ArrayCRef<Record> records,
                              ArrayRef<Value> *results) {
   for (Int i = 0; i < records.size(); ++i) {
     (*results)[i] = column_->get(records.get_row_id(i));
@@ -406,10 +406,10 @@ class ColumnNode<Bool> : public TypedNode<Bool> {
   }
 
   bool filter(Error *error,
-              const ArrayRef<Record> &input_records,
+              ArrayCRef<Record> input_records,
               ArrayRef<Record> *output_records);
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Bool> *results);
 
  private:
@@ -417,7 +417,7 @@ class ColumnNode<Bool> : public TypedNode<Bool> {
 };
 
 bool ColumnNode<Bool>::filter(Error *error,
-                              const ArrayRef<Record> &input_records,
+                              ArrayCRef<Record> input_records,
                               ArrayRef<Record> *output_records) {
   Int dest = 0;
   for (Int i = 0; i < input_records.size(); ++i) {
@@ -431,7 +431,7 @@ bool ColumnNode<Bool>::filter(Error *error,
 }
 
 bool ColumnNode<Bool>::evaluate(Error *error,
-                                const ArrayRef<Record> &records,
+                                ArrayCRef<Record> records,
                                 ArrayRef<Bool> *results) {
   for (Int i = 0; i < records.size(); ++i) {
     results->set(i, column_->get(records.get_row_id(i)));
@@ -454,7 +454,7 @@ class ColumnNode<Float> : public TypedNode<Float> {
 
   bool adjust(Error *error, ArrayRef<Record> *records);
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Float> *results);
 
  private:
@@ -469,7 +469,7 @@ bool ColumnNode<Float>::adjust(Error *error, ArrayRef<Record> *records) {
 }
 
 bool ColumnNode<Float>::evaluate(Error *error,
-                                 const ArrayRef<Record> &records,
+                                 ArrayCRef<Record> records,
                                  ArrayRef<Float> *results) {
   for (Int i = 0; i < records.size(); ++i) {
     (*results)[i] = column_->get(records.get_row_id(i));
@@ -500,7 +500,7 @@ class OperatorNode : public TypedNode<T> {
 // On failure, returns false and stores error information into "*error" if
 // "error" != nullptr.
 template <typename T>
-bool fill_node_arg_values(Error *error, const ArrayRef<Record> &records,
+bool fill_node_arg_values(Error *error, ArrayCRef<Record> records,
                           TypedNode<T> *arg, Array<T> *arg_values) {
   Int old_size = arg_values->size();
   if (old_size < records.size()) {
@@ -546,7 +546,7 @@ class UnaryNode : public OperatorNode<T> {
   unique_ptr<TypedNode<Arg>> arg_;
   Array<Arg> arg_values_;
 
-  bool fill_arg_values(Error *error, const ArrayRef<Record> &records) {
+  bool fill_arg_values(Error *error, ArrayCRef<Record> records) {
     return fill_node_arg_values(error, records, arg_.get(), &arg_values_);
   }
 };
@@ -562,10 +562,10 @@ class LogicalNotNode : public UnaryNode<Bool, Bool> {
         temp_records_() {}
 
   bool filter(Error *error,
-              const ArrayRef<Record> &input_records,
+              ArrayCRef<Record> input_records,
               ArrayRef<Record> *output_records);
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Bool> *results);
 
  private:
@@ -573,7 +573,7 @@ class LogicalNotNode : public UnaryNode<Bool, Bool> {
 };
 
 bool LogicalNotNode::filter(Error *error,
-                            const ArrayRef<Record> &input_records,
+                            ArrayCRef<Record> input_records,
                             ArrayRef<Record> *output_records) {
   // Create a copy of "input_records" and then apply a filter to it.
   // Then, appends a sentinel to the end of the result.
@@ -604,7 +604,7 @@ bool LogicalNotNode::filter(Error *error,
 }
 
 bool LogicalNotNode::evaluate(Error *error,
-                              const ArrayRef<Record> &records,
+                              ArrayCRef<Record> records,
                               ArrayRef<Bool> *results) {
   if (!arg_->evaluate(error, records, results)) {
     return false;
@@ -627,15 +627,15 @@ class BitwiseNotNode : public UnaryNode<Bool, Bool> {
       : UnaryNode<Bool, Bool>(std::move(arg)) {}
 
   bool filter(Error *error,
-              const ArrayRef<Record> &input_records,
+              ArrayCRef<Record> input_records,
               ArrayRef<Record> *output_records);
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Bool> *results);
 };
 
 bool BitwiseNotNode::filter(Error *error,
-                            const ArrayRef<Record> &input_records,
+                            ArrayCRef<Record> input_records,
                             ArrayRef<Record> *output_records) {
   if (!fill_arg_values(error, input_records)) {
     return false;
@@ -652,7 +652,7 @@ bool BitwiseNotNode::filter(Error *error,
 }
 
 bool BitwiseNotNode::evaluate(Error *error,
-                              const ArrayRef<Record> &records,
+                              ArrayCRef<Record> records,
                               ArrayRef<Bool> *results) {
   if (!arg_->evaluate(error, records, results)) {
     return false;
@@ -695,10 +695,10 @@ class BinaryNode : public OperatorNode<T> {
   Array<Arg1> arg1_values_;
   Array<Arg2> arg2_values_;
 
-  bool fill_arg1_values(Error *error, const ArrayRef<Record> &records) {
+  bool fill_arg1_values(Error *error, ArrayCRef<Record> records) {
     return fill_node_arg_values(error, records, arg1_.get(), &arg1_values_);
   }
-  bool fill_arg2_values(Error *error, const ArrayRef<Record> &records) {
+  bool fill_arg2_values(Error *error, ArrayCRef<Record> records) {
     return fill_node_arg_values(error, records, arg2_.get(), &arg2_values_);
   }
 };
@@ -716,10 +716,10 @@ class LogicalAndNode : public BinaryNode<Bool, Bool, Bool> {
         temp_records_() {}
 
   bool filter(Error *error,
-              const ArrayRef<Record> &input_records,
+              ArrayCRef<Record> input_records,
               ArrayRef<Record> *output_records);
   bool evaluate(Error *error,
-                const ArrayRef<Record> &records,
+                ArrayCRef<Record> records,
                 ArrayRef<Bool> *results);
 
  private:
@@ -727,14 +727,14 @@ class LogicalAndNode : public BinaryNode<Bool, Bool, Bool> {
 };
 
 bool LogicalAndNode::filter(Error *error,
-                            const ArrayRef<Record> &input_records,
+                            ArrayCRef<Record> input_records,
                             ArrayRef<Record> *output_records) {
   return arg1_->filter(error, input_records, output_records) &&
          arg2_->filter(error, *output_records, output_records);
 }
 
 bool LogicalAndNode::evaluate(Error *error,
-                              const ArrayRef<Record> &records,
+                              ArrayCRef<Record> records,
                               ArrayRef<Bool> *results) {
   // TODO
   return false;
-------------- next part --------------
HTML����������������������������...
Download 



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