[Groonga-commit] groonga/grnxx at 237ced6 [master] Add Vector<Float/Int>.

Back to archive index

susumu.yata null+****@clear*****
Thu Aug 28 12:59:43 JST 2014


susumu.yata	2014-08-28 12:59:43 +0900 (Thu, 28 Aug 2014)

  New Revision: 237ced69e3d52544ada8822f40a50e095e2afac7
  https://github.com/groonga/grnxx/commit/237ced69e3d52544ada8822f40a50e095e2afac7

  Message:
    Add Vector<Float/Int>.

  Modified files:
    include/grnxx/types.hpp

  Modified: include/grnxx/types.hpp (+67 -1)
===================================================================
--- include/grnxx/types.hpp    2014-08-27 17:30:07 +0900 (c9669cf)
+++ include/grnxx/types.hpp    2014-08-28 12:59:43 +0900 (e2157c2)
@@ -289,7 +289,73 @@ inline Bool operator!=(Vector<Bool> lhs, Vector<Bool> rhs) {
          ((lhs.bits() ^ rhs.bits()) != 0);
 }
 
-using BoolVector = Vector<Bool>;
+template <>
+class Vector<Int> {
+ public:
+  Vector() = default;
+  Vector(const Int *data, Int size) : data_(data), size_(size) {}
+  Vector(const Vector &) = default;
+
+  Vector &operator=(const Vector &) = default;
+
+  // Return the number of Int values.
+  Int size() const {
+    return size_;
+  }
+  // Return the "i"-th Int value.
+  //
+  // If "i" is invalid, the result is undefined.
+  Int get(Int i) const {
+    return data_[i];
+  }
+
+  // Return the "i"-th Int value.
+  //
+  // If "i" is invalid, the result is undefined.
+  Int operator[](Int i) const {
+    return get(i);
+  }
+
+ private:
+  const Int *data_;
+  Int size_;
+};
+
+template <>
+class Vector<Float> {
+ public:
+  Vector() = default;
+  Vector(const Float *data, Int size) : data_(data), size_(size) {}
+  Vector(const Vector &) = default;
+
+  Vector &operator=(const Vector &) = default;
+
+  // Return the number of Float values.
+  Int size() const {
+    return size_;
+  }
+  // Return the "i"-th Float value.
+  //
+  // If "i" is invalid, the result is undefined.
+  Float get(Int i) const {
+    return data_[i];
+  }
+
+  // Return the "i"-th Float value.
+  //
+  // If "i" is invalid, the result is undefined.
+  Float operator[](Int i) const {
+    return get(i);
+  }
+
+ private:
+  const Float *data_;
+  Int size_;
+};
+
+using BoolVector  = Vector<Bool>;
+using IntVector   = Vector<Int>;
+using FloatVector = Vector<Float>;
 
 // Type information.
 template <typename T> struct TypeTraits;
-------------- next part --------------
HTML����������������������������...
Download 



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