susumu.yata
null+****@clear*****
Tue Aug 19 17:37:17 JST 2014
susumu.yata 2014-08-19 17:37:17 +0900 (Tue, 19 Aug 2014) New Revision: 040b29a1a3db145509787b7b31b2b699ae9c99f4 https://github.com/groonga/grnxx/commit/040b29a1a3db145509787b7b31b2b699ae9c99f4 Message: Use Int instead of size_t. Modified files: include/grnxx/column.hpp include/grnxx/db.hpp include/grnxx/table.hpp include/grnxx/types.hpp lib/grnxx/db.cpp lib/grnxx/table.cpp Modified: include/grnxx/column.hpp (+2 -2) =================================================================== --- include/grnxx/column.hpp 2014-08-19 10:21:06 +0900 (568f747) +++ include/grnxx/column.hpp 2014-08-19 17:37:17 +0900 (ff7624b) @@ -32,7 +32,7 @@ class Column { return has_key_attribute_; } // Return the number of indexes. - size_t num_indexes() const { + Int num_indexes() const { // TODO: Index is not supported yet. return 0; } @@ -88,7 +88,7 @@ class Column { // Returns a pointer to the index on success. // On failure, returns nullptr and stores error information into "*error" if // "error" != nullptr. - Index *get_index(size_t index_id) const { + Index *get_index(Int index_id) const { // TODO: Not supported yet. return nullptr; } Modified: include/grnxx/db.hpp (+3 -3) =================================================================== --- include/grnxx/db.hpp 2014-08-19 10:21:06 +0900 (de7fb4c) +++ include/grnxx/db.hpp 2014-08-19 17:37:17 +0900 (0b34934) @@ -11,7 +11,7 @@ class DB { ~DB(); // Return the number of tables. - size_t num_tables() const { + Int num_tables() const { return tables_.size(); } @@ -63,7 +63,7 @@ class DB { // Returns a pointer to the table on success. // On failure, returns nullptr and stores error information into "*error" if // "error" != nullptr. - Table *get_table(size_t table_id) const { + Table *get_table(Int table_id) const { return tables_[table_id].get(); } @@ -97,7 +97,7 @@ class DB { // "error" != nullptr. Table *find_table_with_id(Error *error, String name, - size_t *table_id) const; + Int *table_id) const; friend unique_ptr<DB> open_db(Error *error, String path, Modified: include/grnxx/table.hpp (+3 -3) =================================================================== --- include/grnxx/table.hpp 2014-08-19 10:21:06 +0900 (803886e) +++ include/grnxx/table.hpp 2014-08-19 17:37:17 +0900 (5874344) @@ -20,7 +20,7 @@ class Table { return name_.ref(); } // Return the number of columns. - size_t num_columns() const { + Int num_columns() const { return columns_.size(); } // Return the key column, or nullptr if the table has no key column. @@ -85,7 +85,7 @@ class Table { // Returns a pointer to the column on success. // On failure, returns nullptr and stores error information into "*error" if // "error" != nullptr. - Column *get_column(size_t column_id) const { + Column *get_column(Int column_id) const { return columns_[column_id].get(); } @@ -247,7 +247,7 @@ class Table { // "error" != nullptr. Column *find_column_with_id(Error *error, String name, - size_t *column_id) const; + Int *column_id) const; friend class DB; friend class TableCursor; Modified: include/grnxx/types.hpp (+62 -62) =================================================================== --- include/grnxx/types.hpp 2014-08-19 10:21:06 +0900 (80fe110) +++ include/grnxx/types.hpp 2014-08-19 17:37:17 +0900 (638f4fd) @@ -36,68 +36,6 @@ using std::unique_ptr; // An object to make a memory allocation (new) returns nullptr on failure. using std::nothrow; -// Reference to a byte string. -class String { - public: - // The default constructor does nothing. - String() = default; - - // Refer to a zero-terminated string. - String(const char *str) : data_(str), size_(str ? std::strlen(str) : 0) {} - - // Refer to an arbitrary byte string. - String(const char *data, size_t size) : data_(data), size_(size) {} - - const char &operator[](size_t i) const { - return data_[i]; - } - - const char *data() const { - return data_; - } - size_t size() const { - return size_; - } - - private: - const char *data_; - size_t size_; -}; - -inline bool operator==(String lhs, String rhs) { - return (lhs.size() == rhs.size()) && - (std::memcmp(lhs.data(), rhs.data(), lhs.size()) == 0); -} - -inline bool operator!=(String lhs, String rhs) { - return (lhs.size() != rhs.size()) || - (std::memcmp(lhs.data(), rhs.data(), lhs.size()) != 0); -} - -inline bool operator<(String lhs, String rhs) { - size_t min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size(); - int result = std::memcmp(lhs.data(), rhs.data(), min_size); - return (result < 0) || ((result == 0) && (lhs.size() < rhs.size())); -} - -inline bool operator>(String lhs, String rhs) { - size_t min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size(); - int result = std::memcmp(lhs.data(), rhs.data(), min_size); - return (result > 0) || ((result == 0) && (lhs.size() > rhs.size())); -} - -inline bool operator<=(String lhs, String rhs) { - size_t min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size(); - int result = std::memcmp(lhs.data(), rhs.data(), min_size); - return (result < 0) || ((result == 0) && (lhs.size() <= rhs.size())); -} - -inline bool operator>=(String lhs, String rhs) { - size_t min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size(); - int result = std::memcmp(lhs.data(), rhs.data(), min_size); - return (result > 0) || ((result == 0) && (lhs.size() >= rhs.size())); -} - // Error information. class Error; @@ -257,6 +195,68 @@ inline bool operator!=(GeoPoint lhs, GeoPoint rhs) { (lhs.longitude() != rhs.longitude()); } +// Reference to a byte string. +class String { + public: + // The default constructor does nothing. + String() = default; + + // Refer to a zero-terminated string. + String(const char *str) : data_(str), size_(str ? std::strlen(str) : 0) {} + + // Refer to an arbitrary byte string. + String(const char *data, Int size) : data_(data), size_(size) {} + + const char &operator[](Int i) const { + return data_[i]; + } + + const char *data() const { + return data_; + } + Int size() const { + return size_; + } + + private: + const char *data_; + Int size_; +}; + +inline bool operator==(String lhs, String rhs) { + return (lhs.size() == rhs.size()) && + (std::memcmp(lhs.data(), rhs.data(), lhs.size()) == 0); +} + +inline bool operator!=(String lhs, String rhs) { + return (lhs.size() != rhs.size()) || + (std::memcmp(lhs.data(), rhs.data(), lhs.size()) != 0); +} + +inline bool operator<(String lhs, String rhs) { + Int min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size(); + int result = std::memcmp(lhs.data(), rhs.data(), min_size); + return (result < 0) || ((result == 0) && (lhs.size() < rhs.size())); +} + +inline bool operator>(String lhs, String rhs) { + Int min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size(); + int result = std::memcmp(lhs.data(), rhs.data(), min_size); + return (result > 0) || ((result == 0) && (lhs.size() > rhs.size())); +} + +inline bool operator<=(String lhs, String rhs) { + Int min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size(); + int result = std::memcmp(lhs.data(), rhs.data(), min_size); + return (result < 0) || ((result == 0) && (lhs.size() <= rhs.size())); +} + +inline bool operator>=(String lhs, String rhs) { + Int min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size(); + int result = std::memcmp(lhs.data(), rhs.data(), min_size); + return (result > 0) || ((result == 0) && (lhs.size() >= rhs.size())); +} + using Text = String; class RowRef { Modified: lib/grnxx/db.cpp (+8 -8) =================================================================== --- lib/grnxx/db.cpp 2014-08-19 10:21:06 +0900 (15884e1) +++ lib/grnxx/db.cpp 2014-08-19 17:37:17 +0900 (4fb44ce) @@ -29,7 +29,7 @@ Table *DB::create_table(Error *error, } bool DB::remove_table(Error *error, String name) { - size_t table_id; + Int table_id; if (!find_table_with_id(error, name, &table_id)) { return false; } @@ -46,7 +46,7 @@ bool DB::remove_table(Error *error, String name) { bool DB::rename_table(Error *error, String name, String new_name) { - size_t table_id; + Int table_id; if (!find_table_with_id(error, name, &table_id)) { return false; } @@ -65,13 +65,13 @@ bool DB::rename_table(Error *error, bool DB::reorder_table(Error *error, String name, String prev_name) { - size_t table_id; + Int table_id; if (!find_table_with_id(error, name, &table_id)) { return false; } - size_t new_table_id = 0; + Int new_table_id = 0; if (prev_name.size() != 0) { - size_t prev_table_id; + Int prev_table_id; if (!find_table_with_id(error, prev_name, &prev_table_id)) { return false; } @@ -91,7 +91,7 @@ bool DB::reorder_table(Error *error, } Table *DB::find_table(Error *error, String name) const { - for (size_t table_id = 0; table_id < num_tables(); ++table_id) { + for (Int table_id = 0; table_id < num_tables(); ++table_id) { if (name == tables_[table_id]->name()) { return tables_[table_id].get(); } @@ -113,8 +113,8 @@ DB::DB() : tables_() {} Table *DB::find_table_with_id(Error *error, String name, - size_t *table_id) const { - for (size_t i = 0; i < num_tables(); ++i) { + Int *table_id) const { + for (Int i = 0; i < num_tables(); ++i) { if (name == tables_[i]->name()) { if (table_id != nullptr) { *table_id = i; Modified: lib/grnxx/table.cpp (+12 -12) =================================================================== --- lib/grnxx/table.cpp 2014-08-19 10:21:06 +0900 (cde7c01) +++ lib/grnxx/table.cpp 2014-08-19 17:37:17 +0900 (e5218fd) @@ -254,7 +254,7 @@ Column *Table::create_column(Error *error, } bool Table::remove_column(Error *error, String name) { - size_t column_id; + Int column_id; if (!find_column_with_id(error, name, &column_id)) { return false; } @@ -271,7 +271,7 @@ bool Table::remove_column(Error *error, String name) { bool Table::rename_column(Error *error, String name, String new_name) { - size_t column_id; + Int column_id; if (!find_column_with_id(error, name, &column_id)) { return false; } @@ -290,13 +290,13 @@ bool Table::rename_column(Error *error, bool Table::reorder_column(Error *error, String name, String prev_name) { - size_t column_id; + Int column_id; if (!find_column_with_id(error, name, &column_id)) { return false; } - size_t new_column_id = 0; + Int new_column_id = 0; if (prev_name.size() != 0) { - size_t prev_column_id; + Int prev_column_id; if (!find_column_with_id(error, prev_name, &prev_column_id)) { return false; } @@ -316,7 +316,7 @@ bool Table::reorder_column(Error *error, } Column *Table::find_column(Error *error, String name) const { - for (size_t column_id = 0; column_id < num_columns(); ++column_id) { + for (Int column_id = 0; column_id < num_columns(); ++column_id) { if (name == columns_[column_id]->name()) { return columns_[column_id].get(); } @@ -392,14 +392,14 @@ bool Table::insert_row(Error *error, if (next_row_id > max_row_id()) { // Fill non-key column values with the default values. - for (size_t column_id = 0; column_id < num_columns(); ++column_id) { + for (Int column_id = 0; column_id < num_columns(); ++column_id) { if (columns_[column_id].get() != key_column()) { if (!columns_[column_id]->set_default_value(error, next_row_id)) { // Rollback the insertion. if (key_column()) { key_column_->unset(next_row_id); } - for (size_t i = 0; i < column_id; ++i) { + for (Int i = 0; i < column_id; ++i) { if (columns_[i].get() != key_column()) { columns_[i]->unset(next_row_id); } @@ -422,7 +422,7 @@ bool Table::remove_row(Error *error, Int row_id) { return false; } // TODO: Check removability and unset column values. - for (size_t column_id = 0; column_id < num_columns(); ++column_id) { + for (Int column_id = 0; column_id < num_columns(); ++column_id) { columns_[column_id]->unset(row_id); } unset_bit(row_id); @@ -530,7 +530,7 @@ Int Table::find_zero_bit() const { return max_row_id() + 1; } Int pos = 0; - for (size_t i = bitmap_indexes_.size(); i > 0; ) { + for (Int i = bitmap_indexes_.size(); i > 0; ) { pos = (pos * 64) + ::__builtin_ctzll(~bitmap_indexes_[--i][pos]); } return (pos * 64) + ::__builtin_ctzll(~bitmap_[pos]); @@ -543,7 +543,7 @@ bool Table::reserve_bit(Error *error, Int i) { return false; } // Resize the bitmap if required. - size_t block_id = i / 64; + Int block_id = i / 64; if (block_id >= bitmap_.size()) { if (!bitmap_.resize(error, block_id + 1, 0)) { return false; @@ -586,7 +586,7 @@ bool Table::is_removable() { Column *Table::find_column_with_id(Error *error, String name, - size_t *column_id) const { + Int *column_id) const { for (Int i = 0; i < num_columns(); ++i) { if (name == columns_[i]->name()) { if (column_id != nullptr) { -------------- next part -------------- HTML����������������������������...Download