susumu.yata
null+****@clear*****
Wed Dec 24 18:22:23 JST 2014
susumu.yata 2014-12-24 18:22:23 +0900 (Wed, 24 Dec 2014) New Revision: 27a2ee035960d4ae27718cfa5fc4325be70177e8 https://github.com/groonga/grnxx/commit/27a2ee035960d4ae27718cfa5fc4325be70177e8 Message: Fix bugs that Column<Bool/Float/GeoPoint> cannot find N/A. (#135) Modified files: lib/grnxx/impl/column/scalar/bool.cpp lib/grnxx/impl/column/scalar/bool.hpp lib/grnxx/impl/column/scalar/float.cpp lib/grnxx/impl/column/scalar/float.hpp lib/grnxx/impl/column/scalar/geo_point.cpp lib/grnxx/impl/column/scalar/geo_point.hpp Modified: lib/grnxx/impl/column/scalar/bool.cpp (+22 -37) =================================================================== --- lib/grnxx/impl/column/scalar/bool.cpp 2014-12-24 12:39:08 +0900 (bba6118) +++ lib/grnxx/impl/column/scalar/bool.cpp 2014-12-24 18:22:23 +0900 (06caf10) @@ -59,42 +59,12 @@ void Column<Bool>::get(Int row_id, Datum *datum) const { bool Column<Bool>::contains(const Datum &datum) const { // TODO: Use an index if exists. - Bool value = parse_datum(datum); - size_t valid_size = get_valid_size(); - if (value.is_na()) { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].is_na() && table_->_test_row(i)) { - return true; - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].match(value)) { - return true; - } - } - } - return false; + return !scan(parse_datum(datum)).is_na(); } Int Column<Bool>::find_one(const Datum &datum) const { // TODO: Use an index if exists. - Bool value = parse_datum(datum); - size_t valid_size = get_valid_size(); - if (value.is_na()) { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].is_na() && table_->_test_row(i)) { - return Int(i); - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].match(value)) { - return Int(i); - } - } - } - return Int::na(); + return scan(parse_datum(datum)); } void Column<Bool>::unset(Int row_id) { @@ -115,15 +85,30 @@ void Column<Bool>::read(ArrayCRef<Record> records, } } -size_t Column<Bool>::get_valid_size() const { +Int Column<Bool>::scan(Bool value) const { if (table_->max_row_id().is_na()) { - return 0; + return Int::na(); } size_t table_size = table_->max_row_id().raw() + 1; - if (table_size < values_.size()) { - return table_size; + size_t valid_size = + (values_.size() < table_size) ? values_.size() : table_size; + if (value.is_na()) { + if (values_.size() < table_size) { + return table_->max_row_id(); + } + for (size_t i = 0; i < valid_size; ++i) { + if (values_[i].is_na() && table_->_test_row(i)) { + return Int(i); + } + } + } else { + for (size_t i = 0; i < valid_size; ++i) { + if (values_[i].match(value)) { + return Int(i); + } + } } - return values_.size(); + return Int::na(); } Bool Column<Bool>::parse_datum(const Datum &datum) { Modified: lib/grnxx/impl/column/scalar/bool.hpp (+5 -2) =================================================================== --- lib/grnxx/impl/column/scalar/bool.hpp 2014-12-24 12:39:08 +0900 (95a0f7c) +++ lib/grnxx/impl/column/scalar/bool.hpp 2014-12-24 18:22:23 +0900 (b3fe943) @@ -48,8 +48,11 @@ class Column<Bool> : public ColumnBase { private: Array<Bool> values_; - // Return the active column size. - size_t get_valid_size() const; + // Scan the column to find "value". + // + // If found, returns the row ID. + // If not found, returns N/A. + Int scan(Bool value) const; // Parse "datum" as Bool. // Modified: lib/grnxx/impl/column/scalar/float.cpp (+22 -37) =================================================================== --- lib/grnxx/impl/column/scalar/float.cpp 2014-12-24 12:39:08 +0900 (ff62a2a) +++ lib/grnxx/impl/column/scalar/float.cpp 2014-12-24 18:22:23 +0900 (a149281) @@ -63,22 +63,7 @@ bool Column<Float>::contains(const Datum &datum) const { if (!indexes_.is_empty()) { return indexes_[0]->contains(datum); } - Float value = parse_datum(datum); - size_t valid_size = get_valid_size(); - if (value.is_na()) { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].is_na() && table_->_test_row(i)) { - return true; - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].match(value)) { - return true; - } - } - } - return false; + return !scan(parse_datum(datum)).is_na(); } Int Column<Float>::find_one(const Datum &datum) const { @@ -86,22 +71,7 @@ Int Column<Float>::find_one(const Datum &datum) const { if (!indexes_.is_empty()) { return indexes_[0]->find_one(datum); } - Float value = parse_datum(datum); - size_t valid_size = get_valid_size(); - if (value.is_na()) { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].is_na() && table_->_test_row(i)) { - return Int(i); - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].match(value)) { - return Int(i); - } - } - } - return Int::na(); + return scan(parse_datum(datum)); } void Column<Float>::unset(Int row_id) { @@ -125,15 +95,30 @@ void Column<Float>::read(ArrayCRef<Record> records, } } -size_t Column<Float>::get_valid_size() const { +Int Column<Float>::scan(Float value) const { if (table_->max_row_id().is_na()) { - return 0; + return Int::na(); } size_t table_size = table_->max_row_id().raw() + 1; - if (table_size < values_.size()) { - return table_size; + size_t valid_size = + (values_.size() < table_size) ? values_.size() : table_size; + if (value.is_na()) { + if (values_.size() < table_size) { + return table_->max_row_id(); + } + for (size_t i = 0; i < valid_size; ++i) { + if (values_[i].is_na() && table_->_test_row(i)) { + return Int(i); + } + } + } else { + for (size_t i = 0; i < valid_size; ++i) { + if (values_[i].match(value)) { + return Int(i); + } + } } - return values_.size(); + return Int::na(); } Float Column<Float>::parse_datum(const Datum &datum) { Modified: lib/grnxx/impl/column/scalar/float.hpp (+5 -2) =================================================================== --- lib/grnxx/impl/column/scalar/float.hpp 2014-12-24 12:39:08 +0900 (d48864c) +++ lib/grnxx/impl/column/scalar/float.hpp 2014-12-24 18:22:23 +0900 (ba79a3d) @@ -48,8 +48,11 @@ class Column<Float> : public ColumnBase { private: Array<Float> values_; - // Return the active column size. - size_t get_valid_size() const; + // Scan the column to find "value". + // + // If found, returns the row ID. + // If not found, returns N/A. + Int scan(Float value) const; // Parse "datum" as Float. // Modified: lib/grnxx/impl/column/scalar/geo_point.cpp (+22 -37) =================================================================== --- lib/grnxx/impl/column/scalar/geo_point.cpp 2014-12-24 12:39:08 +0900 (4ad2c29) +++ lib/grnxx/impl/column/scalar/geo_point.cpp 2014-12-24 18:22:23 +0900 (498b138) @@ -60,42 +60,12 @@ void Column<GeoPoint>::get(Int row_id, Datum *datum) const { bool Column<GeoPoint>::contains(const Datum &datum) const { // TODO: Use an index if exists. - GeoPoint value = parse_datum(datum); - size_t valid_size = get_valid_size(); - if (value.is_na()) { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].is_na() && table_->_test_row(i)) { - return true; - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].match(value)) { - return true; - } - } - } - return false; + return !scan(parse_datum(datum)).is_na(); } Int Column<GeoPoint>::find_one(const Datum &datum) const { // TODO: Use an index if exists. - GeoPoint value = parse_datum(datum); - size_t valid_size = get_valid_size(); - if (value.is_na()) { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].is_na() && table_->_test_row(i)) { - return Int(i); - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - if (values_[i].match(value)) { - return Int(i); - } - } - } - return Int::na(); + return scan(parse_datum(datum)); } void Column<GeoPoint>::unset(Int row_id) { @@ -119,15 +89,30 @@ void Column<GeoPoint>::read(ArrayCRef<Record> records, } } -size_t Column<GeoPoint>::get_valid_size() const { +Int Column<GeoPoint>::scan(GeoPoint value) const { if (table_->max_row_id().is_na()) { - return 0; + return Int::na(); } size_t table_size = table_->max_row_id().raw() + 1; - if (table_size < values_.size()) { - return table_size; + size_t valid_size = + (values_.size() < table_size) ? values_.size() : table_size; + if (value.is_na()) { + if (values_.size() < table_size) { + return table_->max_row_id(); + } + for (size_t i = 0; i < valid_size; ++i) { + if (values_[i].is_na() && table_->_test_row(i)) { + return Int(i); + } + } + } else { + for (size_t i = 0; i < valid_size; ++i) { + if (values_[i].match(value)) { + return Int(i); + } + } } - return values_.size(); + return Int::na(); } GeoPoint Column<GeoPoint>::parse_datum(const Datum &datum) { Modified: lib/grnxx/impl/column/scalar/geo_point.hpp (+5 -2) =================================================================== --- lib/grnxx/impl/column/scalar/geo_point.hpp 2014-12-24 12:39:08 +0900 (1659e88) +++ lib/grnxx/impl/column/scalar/geo_point.hpp 2014-12-24 18:22:23 +0900 (9cc603f) @@ -48,8 +48,11 @@ class Column<GeoPoint> : public ColumnBase { private: Array<GeoPoint> values_; - // Return the active column size. - size_t get_valid_size() const; + // Scan the column to find "value". + // + // If found, returns the row ID. + // If not found, returns N/A. + Int scan(GeoPoint value) const; // Parse "datum" as GeoPoint. // -------------- next part -------------- HTML����������������������������... Download