[Groonga-commit] groonga/grnxx at 34306de [new_data_types] Specialize ConstantNode<Vector<Text>>.

Back to archive index

susumu.yata null+****@clear*****
Thu Nov 27 16:14:13 JST 2014


susumu.yata	2014-11-27 16:14:13 +0900 (Thu, 27 Nov 2014)

  New Revision: 34306dec6d6c4412dbaf1946ba8ee5b100f5ec1b
  https://github.com/groonga/grnxx/commit/34306dec6d6c4412dbaf1946ba8ee5b100f5ec1b

  Message:
    Specialize ConstantNode<Vector<Text>>.

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

  Modified: lib/grnxx/impl/expression.cpp (+35 -2)
===================================================================
--- lib/grnxx/impl/expression.cpp    2014-11-27 15:01:54 +0900 (4c465df)
+++ lib/grnxx/impl/expression.cpp    2014-11-27 16:14:13 +0900 (69561f8)
@@ -288,11 +288,44 @@ class ConstantNode<Vector<T>> : public TypedNode<Vector<T>> {
   }
 
  private:
-  // TODO: ConstantNode should be specialized for Vector<Text> because
-  //       Array<T> stores only references.
   Array<T> value_;
 };
 
+// TODO: Vector will have ownership in future.
+template <>
+class ConstantNode<Vector<Text>> : public TypedNode<Vector<Text>> {
+ public:
+  using Value = Vector<Text>;
+
+  explicit ConstantNode(const Value &value)
+      : TypedNode<Value>(),
+        value_(),
+        bodies_() {
+    size_t value_size = value.raw_size();
+    value_.resize(value_size);
+    bodies_.resize(value_size);
+    for (size_t i = 0; i < value_size; ++i) {
+      bodies_[i].assign(value[i].raw_data(), value[i].raw_size());
+      value_[i] = Text(bodies_[i].data(), bodies_[i].size());
+    }
+  }
+  ~ConstantNode() = default;
+
+  NodeType node_type() const {
+    return CONSTANT_NODE;
+  }
+
+  void evaluate(ArrayCRef<Record> records, ArrayRef<Value> results) {
+    for (size_t i = 0; i < records.size(); ++i) {
+      results[i] = Value(value_.data(), value_.size());
+    }
+  }
+
+ private:
+  Array<Text> value_;
+  Array<String> bodies_;
+};
+
 // -- RowIDNode --
 
 class RowIDNode : public TypedNode<Int> {
-------------- next part --------------
HTML����������������������������...
下載 



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