susumu.yata
null+****@clear*****
Wed Jul 31 16:57:09 JST 2013
susumu.yata 2013-07-31 16:57:09 +0900 (Wed, 31 Jul 2013) New Revision: 3dc9476c889404c3685eab3dd4829e5ee8a3dd84 https://github.com/groonga/grnxx/commit/3dc9476c889404c3685eab3dd4829e5ee8a3dd84 Message: Change the return type of truncate(), bool -> void. Modified files: lib/grnxx/map.cpp lib/grnxx/map.hpp lib/grnxx/map/array_map.cpp lib/grnxx/map/array_map.hpp lib/grnxx/map/double_array.cpp lib/grnxx/map/double_array.hpp lib/grnxx/map/hash_table.cpp lib/grnxx/map/hash_table.hpp lib/grnxx/map/patricia.cpp lib/grnxx/map/patricia.hpp test/test_map.cpp Modified: lib/grnxx/map.cpp (+1 -1) =================================================================== --- lib/grnxx/map.cpp 2013-07-31 10:37:51 +0900 (b295088) +++ lib/grnxx/map.cpp 2013-07-31 16:57:09 +0900 (9dd4753) @@ -243,7 +243,7 @@ bool Map<Bytes>::find_longest_prefix_match(KeyArg query, int64_t *key_id, } template <typename T> -bool Map<T>::truncate() { +void Map<T>::truncate() { GRNXX_ERROR() << "invalid operation"; throw LogicError(); } Modified: lib/grnxx/map.hpp (+1 -1) =================================================================== --- lib/grnxx/map.hpp 2013-07-31 10:37:51 +0900 (4313dab) +++ lib/grnxx/map.hpp 2013-07-31 16:57:09 +0900 (b85f1f3) @@ -122,7 +122,7 @@ class Map { Key *key = nullptr); // Remove all the keys in "*this" and return true on success. - virtual bool truncate(); + virtual void truncate(); // Return a reference to create a cursor query. MapCursorAllKeys<T> all_keys() const { Modified: lib/grnxx/map/array_map.cpp (+1 -2) =================================================================== --- lib/grnxx/map/array_map.cpp 2013-07-31 10:37:51 +0900 (6ebcb20) +++ lib/grnxx/map/array_map.cpp 2013-07-31 16:57:09 +0900 (21a0c44) @@ -222,9 +222,8 @@ bool ArrayMap<T>::replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id) { } template <typename T> -bool ArrayMap<T>::truncate() { +void ArrayMap<T>::truncate() { pool_->truncate(); - return true; } template <typename T> Modified: lib/grnxx/map/array_map.hpp (+1 -1) =================================================================== --- lib/grnxx/map/array_map.hpp 2013-07-31 10:37:51 +0900 (78c4166) +++ lib/grnxx/map/array_map.hpp 2013-07-31 16:57:09 +0900 (776b941) @@ -66,7 +66,7 @@ class ArrayMap : public Map<T> { bool remove(KeyArg key); bool replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id = nullptr); - bool truncate(); + void truncate(); private: Storage *storage_; Modified: lib/grnxx/map/double_array.cpp (+1 -2) =================================================================== --- lib/grnxx/map/double_array.cpp 2013-07-31 10:37:51 +0900 (ac03640) +++ lib/grnxx/map/double_array.cpp 2013-07-31 16:57:09 +0900 (4fb8049) @@ -286,13 +286,12 @@ bool DoubleArray<Bytes>::replace(KeyArg src_key, KeyArg dest_key, return true; } -bool DoubleArray<Bytes>::truncate() { +void DoubleArray<Bytes>::truncate() { // TODO: How to recycle nodes. Node * const node = &nodes_->get_value(ROOT_NODE_ID); node->set_child(NODE_INVALID_LABEL); node->set_offset(NODE_INVALID_OFFSET); pool_->truncate(); - return true; } bool DoubleArray<Bytes>::find_longest_prefix_match(KeyArg query, Modified: lib/grnxx/map/double_array.hpp (+1 -1) =================================================================== --- lib/grnxx/map/double_array.hpp 2013-07-31 10:37:51 +0900 (65dfec1) +++ lib/grnxx/map/double_array.hpp 2013-07-31 16:57:09 +0900 (959c95d) @@ -90,7 +90,7 @@ class DoubleArray<Bytes> : public Map<Bytes> { bool remove(KeyArg key); bool replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id = nullptr); - bool truncate(); + void truncate(); bool find_longest_prefix_match(KeyArg query, int64_t *key_id = nullptr, Modified: lib/grnxx/map/hash_table.cpp (+2 -3) =================================================================== --- lib/grnxx/map/hash_table.cpp 2013-07-31 10:37:51 +0900 (f05234a) +++ lib/grnxx/map/hash_table.cpp 2013-07-31 16:57:09 +0900 (a68ce84) @@ -276,11 +276,11 @@ bool HashTable<T>::replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id) { } template <typename T> -bool HashTable<T>::truncate() { +void HashTable<T>::truncate() { refresh_table(); if (max_key_id() == MAP_MIN_KEY_ID) { // Nothing to do. - return true; + return; } // Create an empty table. std::unique_ptr<Table> new_table( @@ -303,7 +303,6 @@ bool HashTable<T>::truncate() { table_id_ = header_->table_id; } Table::unlink(storage_, old_table_->storage_node_id()); - return true; } template <typename T> Modified: lib/grnxx/map/hash_table.hpp (+1 -1) =================================================================== --- lib/grnxx/map/hash_table.hpp 2013-07-31 10:37:51 +0900 (79f38ce) +++ lib/grnxx/map/hash_table.hpp 2013-07-31 16:57:09 +0900 (35ff421) @@ -68,7 +68,7 @@ class HashTable : public Map<T> { bool remove(KeyArg key); bool replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id = nullptr); - bool truncate(); + void truncate(); private: Storage *storage_; Modified: lib/grnxx/map/patricia.cpp (+5 -10) =================================================================== --- lib/grnxx/map/patricia.cpp 2013-07-31 10:37:51 +0900 (f455428) +++ lib/grnxx/map/patricia.cpp 2013-07-31 16:57:09 +0900 (1b01606) @@ -469,14 +469,10 @@ bool Patricia<T>::replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id) { } template <typename T> -bool Patricia<T>::truncate() { - Node * const root_node = &nodes_->get_value(ROOT_NODE_ID); - if (!root_node) { - return false; - } +void Patricia<T>::truncate() { + Node &root_node = nodes_->get_value(ROOT_NODE_ID); pool_->truncate(); - *root_node = Node::dead_node(); - return true; + root_node = Node::dead_node(); } template <typename T> @@ -1350,11 +1346,11 @@ bool Patricia<Bytes>::find_longest_prefix_match(KeyArg query, int64_t *key_id, } } -bool Patricia<Bytes>::truncate() { +void Patricia<Bytes>::truncate() { refresh_nodes(); if (max_key_id() == MAP_MIN_KEY_ID) { // Nothing to do. - return true; + return; } std::unique_ptr<NodeArray> new_nodes( NodeArray::create(storage_, storage_node_id_, MIN_NODES_SIZE)); @@ -1387,7 +1383,6 @@ bool Patricia<Bytes>::truncate() { } NodeArray::unlink(storage_, old_nodes_->storage_node_id()); Cache::unlink(storage_, old_cache_->storage_node_id()); - return true; } void Patricia<Bytes>::create_map(Storage *storage, uint32_t storage_node_id, Modified: lib/grnxx/map/patricia.hpp (+2 -2) =================================================================== --- lib/grnxx/map/patricia.hpp 2013-07-31 10:37:51 +0900 (19a8171) +++ lib/grnxx/map/patricia.hpp 2013-07-31 16:57:09 +0900 (11b65aa) @@ -75,7 +75,7 @@ class Patricia : public Map<T> { bool remove(KeyArg key); bool replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id = nullptr); - bool truncate(); + void truncate(); private: Storage *storage_; @@ -129,7 +129,7 @@ class Patricia<Bytes> : public Map<Bytes> { bool find_longest_prefix_match(KeyArg query, int64_t *key_id = nullptr, Key *key = nullptr); - bool truncate(); + void truncate(); private: Storage *storage_; Modified: test/test_map.cpp (+1 -1) =================================================================== --- test/test_map.cpp 2013-07-31 10:37:51 +0900 (c1dd87c) +++ test/test_map.cpp 2013-07-31 16:57:09 +0900 (fd9702b) @@ -566,7 +566,7 @@ void test_map_truncate(grnxx::MapType map_type) { for (std::uint64_t i = 0; i < MAP_NUM_KEYS; ++i) { assert(map->add(keys[i])); } - assert(map->truncate()); + map->truncate(); assert(map->max_key_id() == (grnxx::MAP_MIN_KEY_ID - 1)); assert(map->num_keys() == 0); for (std::uint64_t i = 0; i < MAP_NUM_KEYS; ++i) { -------------- next part -------------- HTML����������������������������...Download