susumu.yata
null+****@clear*****
Tue Dec 16 10:43:15 JST 2014
susumu.yata 2014-11-17 15:48:56 +0900 (Mon, 17 Nov 2014) New Revision: 7eaee435f6f10faa5871531c713477f25f2041d9 https://github.com/groonga/grnxx/commit/7eaee435f6f10faa5871531c713477f25f2041d9 Message: Add Vector<Bool>. (#109) Modified files: include/grnxx/data_types/vector/bool.hpp Modified: include/grnxx/data_types/vector/bool.hpp (+54 -1) =================================================================== --- include/grnxx/data_types/vector/bool.hpp 2014-11-17 11:23:26 +0900 (e863e0e) +++ include/grnxx/data_types/vector/bool.hpp 2014-11-17 15:48:56 +0900 (7907d42) @@ -12,10 +12,63 @@ template <typename T> class Vector; template <> class Vector<Bool> { public: - // TODO + Vector() = default; + ~Vector() = default; + + constexpr Vector(const Vector &) = default; + Vector &operator=(const Vector &) = default; + + constexpr Vector(const Bool *data, size_t size) : data_(data), size_(size) {} + explicit constexpr Vector(NA) : data_(nullptr), size_(NA()) {} + + const Bool &operator[](size_t i) const { + return data_[i]; + } + constexpr const Bool *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_, 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_, size_.value()) != 0); + } + return has_not_equal_size; + } + static constexpr DataType type() { return BOOL_VECTOR_DATA; } + + static constexpr Vector empty() { + return Vector(nullptr, 0); + } + static constexpr Vector na() { + return Vector(NA()); + } + + private: + const Bool *data_; + Int size_; }; using BoolVector = Vector<Bool>; -------------- next part -------------- HTML����������������������������... 下载