susumu.yata
null+****@clear*****
Fri Dec 26 12:08:11 JST 2014
susumu.yata 2014-12-26 12:08:11 +0900 (Fri, 26 Dec 2014) New Revision: f6bb500131e2d55a25a8e97069e5304a39318e64 https://github.com/groonga/grnxx/commit/f6bb500131e2d55a25a8e97069e5304a39318e64 Message: Fix a bug that Column<Vector<T>> cannot find N/A. (#135) Modified files: lib/grnxx/impl/column/vector/bool.cpp lib/grnxx/impl/column/vector/bool.hpp lib/grnxx/impl/column/vector/float.cpp lib/grnxx/impl/column/vector/float.hpp lib/grnxx/impl/column/vector/geo_point.cpp lib/grnxx/impl/column/vector/geo_point.hpp lib/grnxx/impl/column/vector/int.cpp lib/grnxx/impl/column/vector/int.hpp lib/grnxx/impl/column/vector/text.cpp lib/grnxx/impl/column/vector/text.hpp Modified: lib/grnxx/impl/column/vector/bool.cpp (+27 -32) =================================================================== --- lib/grnxx/impl/column/vector/bool.cpp 2014-12-26 11:55:16 +0900 (578bedc) +++ lib/grnxx/impl/column/vector/bool.cpp 2014-12-26 12:08:11 +0900 (75ba880) @@ -84,38 +84,44 @@ void Column<Vector<Bool>>::get(Int row_id, Datum *datum) const { bool Column<Vector<Bool>>::contains(const Datum &datum) const { // TODO: Use an index if exists. - Vector<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 (headers_[i] == na_header()) { - return true; - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - // TODO: Improve this. - if (get(Int(i)).match(value)) { - return true; - } - } - } - return false; + return !scan(parse_datum(datum)).is_na(); } Int Column<Vector<Bool>>::find_one(const Datum &datum) const { // TODO: Use an index if exists. - Vector<Bool> value = parse_datum(datum); - size_t valid_size = get_valid_size(); + return scan(parse_datum(datum)); +} + +void Column<Vector<Bool>>::unset(Int row_id) { + Vector<Bool> value = get(row_id); + if (!value.is_na()) { + // TODO: Update indexes if exist. +// for (size_t i = 0; i < num_indexes(); ++i) { +// indexes_[i]->remove(row_id, value); +// } + headers_[row_id.raw()] = na_header(); + } +} + +Int Column<Vector<Bool>>::scan(const Vector<Bool> &value) const { + if (table_->max_row_id().is_na()) { + return Int::na(); + } + size_t table_size = table_->max_row_id().raw() + 1; + size_t valid_size = + (headers_.size() < table_size) ? headers_.size() : table_size; if (value.is_na()) { + if (headers_.size() < table_size) { + return table_->max_row_id(); + } for (size_t i = 0; i < valid_size; ++i) { - if (headers_[i] == na_header()) { + if (headers_[i] == na_header() && table_->_test_row(i)) { return Int(i); } } } else { for (size_t i = 0; i < valid_size; ++i) { - // TODO: Improve this. + // TODO: Improve this (get() checks the range of its argument). if (get(Int(i)).match(value)) { return Int(i); } @@ -124,17 +130,6 @@ Int Column<Vector<Bool>>::find_one(const Datum &datum) const { return Int::na(); } -void Column<Vector<Bool>>::unset(Int row_id) { - Vector<Bool> value = get(row_id); - if (!value.is_na()) { - // TODO: Update indexes if exist. -// for (size_t i = 0; i < num_indexes(); ++i) { -// indexes_[i]->remove(row_id, value); -// } - headers_[row_id.raw()] = na_header(); - } -} - size_t Column<Vector<Bool>>::get_valid_size() const { if (table_->max_row_id().is_na()) { return 0; Modified: lib/grnxx/impl/column/vector/bool.hpp (+6 -0) =================================================================== --- lib/grnxx/impl/column/vector/bool.hpp 2014-12-26 11:55:16 +0900 (ab58e7c) +++ lib/grnxx/impl/column/vector/bool.hpp 2014-12-26 12:08:11 +0900 (3e8067c) @@ -71,6 +71,12 @@ class Column<Vector<Bool>> : public ColumnBase { return std::numeric_limits<uint64_t>::max(); } + // Scan the column to find "value". + // + // If found, returns the row ID. + // If not found, returns N/A. + Int scan(const Vector<Bool> &value) const; + // Return the active column size. size_t get_valid_size() const; Modified: lib/grnxx/impl/column/vector/float.cpp (+29 -34) =================================================================== --- lib/grnxx/impl/column/vector/float.cpp 2014-12-26 11:55:16 +0900 (3f4eeee) +++ lib/grnxx/impl/column/vector/float.cpp 2014-12-26 12:08:11 +0900 (8f2488b) @@ -84,44 +84,12 @@ void Column<Vector<Float>>::get(Int row_id, Datum *datum) const { bool Column<Vector<Float>>::contains(const Datum &datum) const { // TODO: Use an index if exists. - Vector<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 (headers_[i] == na_header()) { - return true; - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - // TODO: Improve this. - if (get(Int(i)).match(value)) { - return true; - } - } - } - return false; + return !scan(parse_datum(datum)).is_na(); } Int Column<Vector<Float>>::find_one(const Datum &datum) const { // TODO: Use an index if exists. - Vector<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 (headers_[i] == na_header()) { - return Int(i); - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - // TODO: Improve this. - if (get(Int(i)).match(value)) { - return Int(i); - } - } - } - return Int::na(); + return scan(parse_datum(datum)); } void Column<Vector<Float>>::unset(Int row_id) { @@ -145,6 +113,33 @@ void Column<Vector<Float>>::read(ArrayCRef<Record> records, } } +Int Column<Vector<Float>>::scan(const Vector<Float> &value) const { + if (table_->max_row_id().is_na()) { + return Int::na(); + } + size_t table_size = table_->max_row_id().raw() + 1; + size_t valid_size = + (headers_.size() < table_size) ? headers_.size() : table_size; + if (value.is_na()) { + if (headers_.size() < table_size) { + return table_->max_row_id(); + } + for (size_t i = 0; i < valid_size; ++i) { + if (headers_[i] == na_header() && table_->_test_row(i)) { + return Int(i); + } + } + } else { + for (size_t i = 0; i < valid_size; ++i) { + // TODO: Improve this (get() checks the range of its argument). + if (get(Int(i)).match(value)) { + return Int(i); + } + } + } + return Int::na(); +} + size_t Column<Vector<Float>>::get_valid_size() const { if (table_->max_row_id().is_na()) { return 0; Modified: lib/grnxx/impl/column/vector/float.hpp (+6 -0) =================================================================== --- lib/grnxx/impl/column/vector/float.hpp 2014-12-26 11:55:16 +0900 (473f319) +++ lib/grnxx/impl/column/vector/float.hpp 2014-12-26 12:08:11 +0900 (55f66fe) @@ -71,6 +71,12 @@ class Column<Vector<Float>> : public ColumnBase { return std::numeric_limits<uint64_t>::max(); } + // Scan the column to find "value". + // + // If found, returns the row ID. + // If not found, returns N/A. + Int scan(const Vector<Float> &value) const; + // Return the active column size. size_t get_valid_size() const; Modified: lib/grnxx/impl/column/vector/geo_point.cpp (+29 -34) =================================================================== --- lib/grnxx/impl/column/vector/geo_point.cpp 2014-12-26 11:55:16 +0900 (e57bd27) +++ lib/grnxx/impl/column/vector/geo_point.cpp 2014-12-26 12:08:11 +0900 (c8190fd) @@ -85,44 +85,12 @@ void Column<Vector<GeoPoint>>::get(Int row_id, Datum *datum) const { bool Column<Vector<GeoPoint>>::contains(const Datum &datum) const { // TODO: Use an index if exists. - Vector<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 (headers_[i] == na_header()) { - return true; - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - // TODO: Improve this. - if (get(Int(i)).match(value)) { - return true; - } - } - } - return false; + return !scan(parse_datum(datum)).is_na(); } Int Column<Vector<GeoPoint>>::find_one(const Datum &datum) const { // TODO: Use an index if exists. - Vector<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 (headers_[i] == na_header()) { - return Int(i); - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - // TODO: Improve this. - if (get(Int(i)).match(value)) { - return Int(i); - } - } - } - return Int::na(); + return scan(parse_datum(datum)); } void Column<Vector<GeoPoint>>::unset(Int row_id) { @@ -146,6 +114,33 @@ void Column<Vector<GeoPoint>>::read(ArrayCRef<Record> records, } } +Int Column<Vector<GeoPoint>>::scan(const Vector<GeoPoint> &value) const { + if (table_->max_row_id().is_na()) { + return Int::na(); + } + size_t table_size = table_->max_row_id().raw() + 1; + size_t valid_size = + (headers_.size() < table_size) ? headers_.size() : table_size; + if (value.is_na()) { + if (headers_.size() < table_size) { + return table_->max_row_id(); + } + for (size_t i = 0; i < valid_size; ++i) { + if (headers_[i] == na_header() && table_->_test_row(i)) { + return Int(i); + } + } + } else { + for (size_t i = 0; i < valid_size; ++i) { + // TODO: Improve this (get() checks the range of its argument). + if (get(Int(i)).match(value)) { + return Int(i); + } + } + } + return Int::na(); +} + size_t Column<Vector<GeoPoint>>::get_valid_size() const { if (table_->max_row_id().is_na()) { return 0; Modified: lib/grnxx/impl/column/vector/geo_point.hpp (+6 -0) =================================================================== --- lib/grnxx/impl/column/vector/geo_point.hpp 2014-12-26 11:55:16 +0900 (f1fb553) +++ lib/grnxx/impl/column/vector/geo_point.hpp 2014-12-26 12:08:11 +0900 (46dc6e8) @@ -72,6 +72,12 @@ class Column<Vector<GeoPoint>> : public ColumnBase { return std::numeric_limits<uint64_t>::max(); } + // Scan the column to find "value". + // + // If found, returns the row ID. + // If not found, returns N/A. + Int scan(const Vector<GeoPoint> &value) const; + // Return the active column size. size_t get_valid_size() const; Modified: lib/grnxx/impl/column/vector/int.cpp (+29 -34) =================================================================== --- lib/grnxx/impl/column/vector/int.cpp 2014-12-26 11:55:16 +0900 (047672f) +++ lib/grnxx/impl/column/vector/int.cpp 2014-12-26 12:08:11 +0900 (a529efa) @@ -99,44 +99,12 @@ void Column<Vector<Int>>::get(Int row_id, Datum *datum) const { bool Column<Vector<Int>>::contains(const Datum &datum) const { // TODO: Use an index if exists. - Vector<Int> 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 (headers_[i] == na_header()) { - return true; - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - // TODO: Improve this. - if (get(Int(i)).match(value)) { - return true; - } - } - } - return false; + return !scan(parse_datum(datum)).is_na(); } Int Column<Vector<Int>>::find_one(const Datum &datum) const { // TODO: Use an index if exists. - Vector<Int> 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 (headers_[i] == na_header()) { - return Int(i); - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - // TODO: Improve this. - if (get(Int(i)).match(value)) { - return Int(i); - } - } - } - return Int::na(); + return scan(parse_datum(datum)); } void Column<Vector<Int>>::unset(Int row_id) { @@ -160,6 +128,33 @@ void Column<Vector<Int>>::read(ArrayCRef<Record> records, } } +Int Column<Vector<Int>>::scan(const Vector<Int> &value) const { + if (table_->max_row_id().is_na()) { + return Int::na(); + } + size_t table_size = table_->max_row_id().raw() + 1; + size_t valid_size = + (headers_.size() < table_size) ? headers_.size() : table_size; + if (value.is_na()) { + if (headers_.size() < table_size) { + return table_->max_row_id(); + } + for (size_t i = 0; i < valid_size; ++i) { + if (headers_[i] == na_header() && table_->_test_row(i)) { + return Int(i); + } + } + } else { + for (size_t i = 0; i < valid_size; ++i) { + // TODO: Improve this (get() checks the range of its argument). + if (get(Int(i)).match(value)) { + return Int(i); + } + } + } + return Int::na(); +} + size_t Column<Vector<Int>>::get_valid_size() const { if (table_->max_row_id().is_na()) { return 0; Modified: lib/grnxx/impl/column/vector/int.hpp (+6 -0) =================================================================== --- lib/grnxx/impl/column/vector/int.hpp 2014-12-26 11:55:16 +0900 (0e8e352) +++ lib/grnxx/impl/column/vector/int.hpp 2014-12-26 12:08:11 +0900 (27fb975) @@ -71,6 +71,12 @@ class Column<Vector<Int>> : public ColumnBase { return std::numeric_limits<uint64_t>::max(); } + // Scan the column to find "value". + // + // If found, returns the row ID. + // If not found, returns N/A. + Int scan(const Vector<Int> &value) const; + // Return the active column size. size_t get_valid_size() const; Modified: lib/grnxx/impl/column/vector/text.cpp (+29 -34) =================================================================== --- lib/grnxx/impl/column/vector/text.cpp 2014-12-26 11:55:16 +0900 (89a89ad) +++ lib/grnxx/impl/column/vector/text.cpp 2014-12-26 12:08:11 +0900 (facc8c7) @@ -86,44 +86,12 @@ void Column<Vector<Text>>::get(Int row_id, Datum *datum) const { bool Column<Vector<Text>>::contains(const Datum &datum) const { // TODO: Use an index if exists. - Vector<Text> 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 (headers_[i].size.is_na()) { - return true; - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - // TODO: Improve this. - if (get(Int(i)).match(value)) { - return true; - } - } - } - return false; + return !scan(parse_datum(datum)).is_na(); } Int Column<Vector<Text>>::find_one(const Datum &datum) const { // TODO: Use an index if exists. - Vector<Text> 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 (headers_[i].size.is_na()) { - return Int(i); - } - } - } else { - for (size_t i = 0; i < valid_size; ++i) { - // TODO: Improve this. - if (get(Int(i)).match(value)) { - return Int(i); - } - } - } - return Int::na(); + return scan(parse_datum(datum)); } void Column<Vector<Text>>::unset(Int row_id) { @@ -147,6 +115,33 @@ void Column<Vector<Text>>::read(ArrayCRef<Record> records, } } +Int Column<Vector<Text>>::scan(const Vector<Text> &value) const { + if (table_->max_row_id().is_na()) { + return Int::na(); + } + size_t table_size = table_->max_row_id().raw() + 1; + size_t valid_size = + (headers_.size() < table_size) ? headers_.size() : table_size; + if (value.is_na()) { + if (headers_.size() < table_size) { + return table_->max_row_id(); + } + for (size_t i = 0; i < valid_size; ++i) { + if (headers_[i].size.is_na() && table_->_test_row(i)) { + return Int(i); + } + } + } else { + for (size_t i = 0; i < valid_size; ++i) { + // TODO: Improve this (get() checks the range of its argument). + if (get(Int(i)).match(value)) { + return Int(i); + } + } + } + return Int::na(); +} + size_t Column<Vector<Text>>::get_valid_size() const { if (table_->max_row_id().is_na()) { return 0; Modified: lib/grnxx/impl/column/vector/text.hpp (+6 -0) =================================================================== --- lib/grnxx/impl/column/vector/text.hpp 2014-12-26 11:55:16 +0900 (2e0e75b) +++ lib/grnxx/impl/column/vector/text.hpp 2014-12-26 12:08:11 +0900 (b791839) @@ -63,6 +63,12 @@ class Column<Vector<Text>> : public ColumnBase { return Header{ 0, Int::na() }; } + // Scan the column to find "value". + // + // If found, returns the row ID. + // If not found, returns N/A. + Int scan(const Vector<Text> &value) const; + // Return the active column size. size_t get_valid_size() const; -------------- next part -------------- HTML����������������������������...다운로드