[Groonga-commit] groonga/grnxx at c7be65b [master] Add BitwiseNotNode for Int.

Back to archive index

susumu.yata null+****@clear*****
Mon Aug 11 13:11:12 JST 2014


susumu.yata	2014-08-11 13:11:12 +0900 (Mon, 11 Aug 2014)

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

  Message:
    Add BitwiseNotNode for Int.

  Modified files:
    lib/grnxx/expression2.cpp

  Modified: lib/grnxx/expression2.cpp (+35 -7)
===================================================================
--- lib/grnxx/expression2.cpp    2014-08-11 13:09:17 +0900 (0c855cc)
+++ lib/grnxx/expression2.cpp    2014-08-11 13:11:12 +0900 (eaafcf4)
@@ -622,7 +622,10 @@ bool LogicalNotNode::evaluate(Error *error,
 
 // ---- BitwiseNotNode ----
 
-class BitwiseNotNode : public UnaryNode<Bool, Bool> {
+template <typename T> class BitwiseNotNode;
+
+template <>
+class BitwiseNotNode<Bool> : public UnaryNode<Bool, Bool> {
  public:
   using Value = Bool;
 
@@ -637,9 +640,9 @@ class BitwiseNotNode : public UnaryNode<Bool, Bool> {
                 ArrayRef<Bool> results);
 };
 
-bool BitwiseNotNode::filter(Error *error,
-                            ArrayCRef<Record> input_records,
-                            ArrayRef<Record> *output_records) {
+bool BitwiseNotNode<Bool>::filter(Error *error,
+                                  ArrayCRef<Record> input_records,
+                                  ArrayRef<Record> *output_records) {
   if (!fill_arg_values(error, input_records)) {
     return false;
   }
@@ -654,9 +657,9 @@ bool BitwiseNotNode::filter(Error *error,
   return true;
 }
 
-bool BitwiseNotNode::evaluate(Error *error,
-                              ArrayCRef<Record> records,
-                              ArrayRef<Bool> results) {
+bool BitwiseNotNode<Bool>::evaluate(Error *error,
+                                    ArrayCRef<Record> records,
+                                    ArrayRef<Bool> results) {
   if (!arg_->evaluate(error, records, results)) {
     return false;
   }
@@ -668,6 +671,31 @@ bool BitwiseNotNode::evaluate(Error *error,
   return true;
 }
 
+template <>
+class BitwiseNotNode<Int> : public UnaryNode<Int, Int> {
+ public:
+  using Value = Int;
+
+  explicit BitwiseNotNode(unique_ptr<Node> &&arg)
+      : UnaryNode<Int, Int>(std::move(arg)) {}
+
+  bool evaluate(Error *error,
+                ArrayCRef<Record> records,
+                ArrayRef<Int> results);
+};
+
+bool BitwiseNotNode<Int>::evaluate(Error *error,
+                                   ArrayCRef<Record> records,
+                                   ArrayRef<Int> results) {
+  if (!arg_->evaluate(error, records, results)) {
+    return false;
+  }
+  for (Int i = 0; i < records.size(); ++i) {
+    results.set(i, ~results.get(i));
+  }
+  return true;
+}
+
 // ---- PositiveNode ----
 
 // Nothing to do.
-------------- next part --------------
HTML����������������������������...
Télécharger 



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