susumu.yata
null+****@clear*****
Tue Dec 16 10:55:12 JST 2014
susumu.yata 2014-11-19 12:51:32 +0900 (Wed, 19 Nov 2014) New Revision: 9da74d232b2fa32a9a505db7ddf383f4745c8c5b https://github.com/groonga/grnxx/commit/9da74d232b2fa32a9a505db7ddf383f4745c8c5b Message: Add match/unmatch() to data types. (#115) Modified files: include/grnxx/data_types/scalar/bool.hpp include/grnxx/data_types/scalar/float.hpp include/grnxx/data_types/scalar/geo_point.hpp include/grnxx/data_types/scalar/int.hpp include/grnxx/data_types/scalar/text.hpp include/grnxx/data_types/vector/bool.hpp include/grnxx/data_types/vector/float.hpp include/grnxx/data_types/vector/geo_point.hpp include/grnxx/data_types/vector/int.hpp include/grnxx/data_types/vector/text.hpp Modified: include/grnxx/data_types/scalar/bool.hpp (+7 -0) =================================================================== --- include/grnxx/data_types/scalar/bool.hpp 2014-11-18 19:35:32 +0900 (17f9756) +++ include/grnxx/data_types/scalar/bool.hpp 2014-11-19 12:51:32 +0900 (8967707) @@ -82,6 +82,13 @@ class Bool { Bool(static_cast<uint8_t>(value_ ^ rhs.value_)); } + constexpr bool match(Bool rhs) const { + return value_ == rhs.value_; + } + constexpr bool unmatch(Bool rhs) const { + return value_ != rhs.value_; + } + static constexpr DataType type() { return BOOL_DATA; } Modified: include/grnxx/data_types/scalar/float.hpp (+7 -0) =================================================================== --- include/grnxx/data_types/scalar/float.hpp 2014-11-18 19:35:32 +0900 (afd4a76) +++ include/grnxx/data_types/scalar/float.hpp 2014-11-19 12:51:32 +0900 (e7d7a1f) @@ -116,6 +116,13 @@ class Float { return (is_na() || rhs.is_na()) ? Bool::na() : Bool(value_ >= rhs.value_); } + constexpr bool match(Float rhs) const { + return (is_na() && rhs.is_na()) || (value_ == rhs.value_); + } + constexpr bool unmatch(Float rhs) const { + return !(is_na() && rhs.is_na()) && (value_ != rhs.value_); + } + // Return the next representable toward "to". Float next_toward(Float to) const { return Float(std::nextafter(value_, to.value_)); Modified: include/grnxx/data_types/scalar/geo_point.hpp (+8 -0) =================================================================== --- include/grnxx/data_types/scalar/geo_point.hpp 2014-11-18 19:35:32 +0900 (6d76b0a) +++ include/grnxx/data_types/scalar/geo_point.hpp 2014-11-19 12:51:32 +0900 (17f194a) @@ -105,6 +105,14 @@ class GeoPoint { (longitude_ != rhs.longitude_)); } + // TODO: std::memcmp() might be better. + constexpr bool match(const GeoPoint &rhs) const { + return (latitude_ == rhs.latitude_) && (longitude_ == rhs.longitude_); + } + constexpr bool unmatch(const GeoPoint &rhs) const { + return (latitude_ != rhs.latitude_) || (longitude_ != rhs.longitude_); + } + static constexpr DataType type() { return GEO_POINT_DATA; } Modified: include/grnxx/data_types/scalar/int.hpp (+7 -0) =================================================================== --- include/grnxx/data_types/scalar/int.hpp 2014-11-18 19:35:32 +0900 (8d066fa) +++ include/grnxx/data_types/scalar/int.hpp 2014-11-19 12:51:32 +0900 (6d14b72) @@ -221,6 +221,13 @@ class Int { return (is_na() || rhs.is_na()) ? Bool::na() : Bool(value_ >= rhs.value_); } + constexpr bool match(Int rhs) const { + return value_ == rhs.value_; + } + constexpr bool unmatch(Int rhs) const { + return value_ != rhs.value_; + } + // -- Typecast (grnxx/data_types/typecast.hpp) -- constexpr Float to_float() const; Modified: include/grnxx/data_types/scalar/text.hpp (+19 -0) =================================================================== --- include/grnxx/data_types/scalar/text.hpp 2014-11-18 19:35:32 +0900 (35f818a) +++ include/grnxx/data_types/scalar/text.hpp 2014-11-19 12:51:32 +0900 (152b8d9) @@ -105,6 +105,25 @@ class Text { return has_greater_or_equal_size; } + bool match(const Text &rhs) const { + if (size_.unmatch(rhs.size_)) { + return false; + } + if (is_na()) { + return true; + } + return std::memcmp(data_, rhs.data_, size_.value()) == 0; + } + bool unmatch(const Text &rhs) const { + if (size_.unmatch(rhs.size_)) { + return true; + } + if (is_na()) { + return false; + } + return std::memcmp(data_, rhs.data_, size_.value()) != 0; + } + static constexpr DataType type() { return TEXT_DATA; } Modified: include/grnxx/data_types/vector/bool.hpp (+19 -0) =================================================================== --- include/grnxx/data_types/vector/bool.hpp 2014-11-18 19:35:32 +0900 (674bf8a) +++ include/grnxx/data_types/vector/bool.hpp 2014-11-19 12:51:32 +0900 (2306c29) @@ -63,6 +63,25 @@ class Vector<Bool> { return has_not_equal_size; } + bool match(const Vector &rhs) const { + if (size_.unmatch(rhs.size_)) { + return false; + } + if (is_na()) { + return true; + } + return std::memcmp(data_, rhs.data_, size_.value()) == 0; + } + bool unmatch(const Vector &rhs) const { + if (size_.unmatch(rhs.size_)) { + return true; + } + if (is_na()) { + return false; + } + return std::memcmp(data_, rhs.data_, size_.value()) != 0; + } + static constexpr DataType type() { return BOOL_VECTOR_DATA; } Modified: include/grnxx/data_types/vector/float.hpp (+33 -0) =================================================================== --- include/grnxx/data_types/vector/float.hpp 2014-11-18 19:35:32 +0900 (81341bf) +++ include/grnxx/data_types/vector/float.hpp 2014-11-19 12:51:32 +0900 (ebf29df) @@ -77,6 +77,39 @@ class Vector<Float> { return has_not_equal_size; } + bool match(const Vector &rhs) const { + if (size_.unmatch(rhs.size_)) { + return false; + } + if (is_na()) { + return true; + } + // TODO: This is because raw values are not normalized. + size_t size = size_.value(); + for (size_t i = 0; i < size; ++i) { + if (data_[i].unmatch(rhs.data_[i])) { + return false; + } + } + return true; + } + bool unmatch(const Vector &rhs) const { + if (size_.unmatch(rhs.size_)) { + return true; + } + if (is_na()) { + return false; + } + // TODO: This is because raw values are not normalized. + size_t size = size_.value(); + for (size_t i = 0; i < size; ++i) { + if (data_[i].unmatch(rhs.data_[i])) { + return true; + } + } + return false; + } + static constexpr DataType type() { return FLOAT_VECTOR_DATA; } Modified: include/grnxx/data_types/vector/geo_point.hpp (+21 -0) =================================================================== --- include/grnxx/data_types/vector/geo_point.hpp 2014-11-18 19:35:32 +0900 (3494f23) +++ include/grnxx/data_types/vector/geo_point.hpp 2014-11-19 12:51:32 +0900 (a0e5527) @@ -67,6 +67,27 @@ class Vector<GeoPoint> { return has_not_equal_size; } + bool match(const Vector &rhs) const { + if (size_.unmatch(rhs.size_)) { + return false; + } + if (is_na()) { + return true; + } + return std::memcmp(data_, rhs.data_, + sizeof(GeoPoint) * size_.value()) == 0; + } + bool unmatch(const Vector &rhs) const { + if (size_.unmatch(rhs.size_)) { + return true; + } + if (is_na()) { + return false; + } + return std::memcmp(data_, rhs.data_, + sizeof(GeoPoint) * size_.value()) != 0; + } + static constexpr DataType type() { return GEO_POINT_VECTOR_DATA; } Modified: include/grnxx/data_types/vector/int.hpp (+19 -0) =================================================================== --- include/grnxx/data_types/vector/int.hpp 2014-11-18 19:35:32 +0900 (4344a7f) +++ include/grnxx/data_types/vector/int.hpp 2014-11-19 12:51:32 +0900 (c56a1d8) @@ -65,6 +65,25 @@ class Vector<Int> { return has_not_equal_size; } + bool match(const Vector &rhs) const { + if (size_.unmatch(rhs.size_)) { + return false; + } + if (is_na()) { + return true; + } + return std::memcmp(data_, rhs.data_, sizeof(Int) * size_.value()) == 0; + } + bool unmatch(const Vector &rhs) const { + if (size_.unmatch(rhs.size_)) { + return true; + } + if (is_na()) { + return false; + } + return std::memcmp(data_, rhs.data_, sizeof(Int) * size_.value()) != 0; + } + static constexpr DataType type() { return INT_VECTOR_DATA; } Modified: include/grnxx/data_types/vector/text.hpp (+33 -0) =================================================================== --- include/grnxx/data_types/vector/text.hpp 2014-11-18 19:35:32 +0900 (2971622) +++ include/grnxx/data_types/vector/text.hpp 2014-11-19 12:51:32 +0900 (8ff1aa1) @@ -94,6 +94,39 @@ class Vector<Text> { return has_not_equal_size; } + bool match(const Vector &rhs) const { + if (size_.unmatch(rhs.size_)) { + return false; + } + if (is_na()) { + return true; + } + // TODO: This is because raw values are not normalized. + size_t size = size_.value(); + for (size_t i = 0; i < size; ++i) { + if (data_[i].unmatch(rhs.data_[i])) { + return false; + } + } + return true; + } + bool unmatch(const Vector &rhs) const { + if (size_.unmatch(rhs.size_)) { + return true; + } + if (is_na()) { + return false; + } + // TODO: This is because raw values are not normalized. + size_t size = size_.value(); + for (size_t i = 0; i < size; ++i) { + if (data_[i].unmatch(rhs.data_[i])) { + return true; + } + } + return false; + } + static constexpr DataType type() { return TEXT_VECTOR_DATA; } -------------- next part -------------- HTML����������������������������... Download