[Groonga-commit] groonga/grnxx at d831bc5 [master] Add Vector<Int>. (#109)

Back to archive index

susumu.yata null+****@clear*****
Tue Dec 16 10:54:27 JST 2014


susumu.yata	2014-11-17 15:58:58 +0900 (Mon, 17 Nov 2014)

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

  Message:
    Add Vector<Int>. (#109)

  Modified files:
    include/grnxx/data_types/vector/int.hpp

  Modified: include/grnxx/data_types/vector/int.hpp (+56 -1)
===================================================================
--- include/grnxx/data_types/vector/int.hpp    2014-11-17 15:53:26 +0900 (57d61f6)
+++ include/grnxx/data_types/vector/int.hpp    2014-11-17 15:58:58 +0900 (d583381)
@@ -12,10 +12,65 @@ template <typename T> class Vector;
 template <>
 class Vector<Int> {
  public:
-  // TODO
+  Vector() = default;
+  ~Vector() = default;
+
+  constexpr Vector(const Vector &) = default;
+  Vector &operator=(const Vector &) = default;
+
+  constexpr Vector(const Int *data, size_t size) : data_(data), size_(size) {}
+  explicit constexpr Vector(NA) : data_(nullptr), size_(NA()) {}
+
+  const Int &operator[](size_t i) const {
+    return data_[i];
+  }
+  constexpr const Int *data() const {
+    return data_;
+  }
+  constexpr Int size() const {
+    return size_;
+  }
+
+  constexpr bool is_empty() const {
+    return size_.value() == 0;
+  }
+  constexpr bool is_na() const {
+    return size_.is_na();
+  }
+
+  // TODO: The behavior of N/A in vector is not fixed yet (#107).
+  Bool operator==(const Vector &rhs) const {
+    Bool has_equal_size = (size_ == rhs.size_);
+    if (has_equal_size.is_true()) {
+      return Bool(std::memcmp(data_, rhs.data_,
+                              sizeof(Int) * size_.value()) == 0);
+    }
+    return has_equal_size;
+  }
+  // TODO: The behavior of N/A in vector is not fixed yet (#107).
+  Bool operator!=(const Vector &rhs) const {
+    Bool has_not_equal_size = (size_ != rhs.size_);
+    if (has_not_equal_size.is_false()) {
+      return Bool(std::memcmp(data_, rhs.data_,
+                              sizeof(Int) * size_.value()) != 0);
+    }
+    return has_not_equal_size;
+  }
+
   static constexpr DataType type() {
     return INT_VECTOR_DATA;
   }
+
+  static constexpr Vector empty() {
+    return Vector(nullptr, 0);
+  }
+  static constexpr Vector na() {
+    return Vector(NA());
+  }
+
+ private:
+  const Int *data_;
+  Int size_;
 };
 
 using IntVector = Vector<Int>;
-------------- next part --------------
HTML����������������������������...
Download 



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