susumu.yata
null+****@clear*****
Wed Jul 24 15:39:25 JST 2013
susumu.yata 2013-07-24 15:39:25 +0900 (Wed, 24 Jul 2013) New Revision: 07a284ffd9076bd359d52fae4d4859f6bac42369 https://github.com/groonga/grnxx/commit/07a284ffd9076bd359d52fae4d4859f6bac42369 Message: Use a return value instead of an argument. Modified files: lib/grnxx/map/hash_table.cpp lib/grnxx/map/hash_table.hpp Modified: lib/grnxx/map/hash_table.cpp (+9 -9) =================================================================== --- lib/grnxx/map/hash_table.cpp 2013-07-24 15:31:59 +0900 (995cff2) +++ lib/grnxx/map/hash_table.cpp 2013-07-24 15:39:25 +0900 (119c0c1) @@ -139,8 +139,8 @@ bool HashTable<T>::get(int64_t key_id, Key *key) { template <typename T> bool HashTable<T>::unset(int64_t key_id) { refresh_key_ids(); - int64_t *stored_key_id; - if (!find_key_id(key_id, &stored_key_id)) { + int64_t * const stored_key_id = find_key_id(key_id); + if (!stored_key_id) { // Not found. return false; } @@ -157,8 +157,8 @@ bool HashTable<T>::reset(int64_t key_id, KeyArg dest_key) { // Not found. return false; } - int64_t *src_key_id; - if (!find_key_id(key_id, &src_key_id)) { + int64_t * const src_key_id = find_key_id(key_id); + if (!src_key_id) { // Not found. return false; } @@ -334,19 +334,19 @@ void HashTable<T>::open_map(Storage *storage, uint32_t storage_node_id) { } template <typename T> -bool HashTable<T>::find_key_id(int64_t key_id, int64_t **stored_key_id) { +int64_t *HashTable<T>::find_key_id(int64_t key_id) { KeyIDArray * const key_ids = key_ids_.get(); Key stored_key; if (!get(key_id, &stored_key)) { // Not found. - return false; + return nullptr; } const uint64_t first_hash = Hash<T>()(stored_key); for (uint64_t hash = first_hash; ; ) { - *stored_key_id = &key_ids->get_value(hash & (key_ids->size() - 1)); - if (**stored_key_id == key_id) { + int64_t &stored_key_id = key_ids->get_value(hash & (key_ids->size() - 1)); + if (stored_key_id == key_id) { // Found. - return true; + return &stored_key_id; } hash = rehash(hash); if (hash == first_hash) { Modified: lib/grnxx/map/hash_table.hpp (+4 -4) =================================================================== --- lib/grnxx/map/hash_table.hpp 2013-07-24 15:31:59 +0900 (adb545c) +++ lib/grnxx/map/hash_table.hpp 2013-07-24 15:39:25 +0900 (52678cf) @@ -82,10 +82,10 @@ class HashTable : public Map<T> { const MapOptions &options); void open_map(Storage *storage, uint32_t storage_node_id); - // Find a key ID in the hash table. - // Return true on success and assign the address to "*stored_key_id". - // Return false on failure and don't modify "*stored_key_id". - bool find_key_id(int64_t key_id, int64_t **stored_key_id); + // Search a hash table for a key ID. + // Return a pointer to the stored key ID on success. + // Return nullptr on failure. + int64_t *find_key_id(int64_t key_id); // Find a key in the hash table. // Return true on success and assign the address to "*stored_key_id". // Return false on failure and assign the address of first unused entry. -------------- next part -------------- HTML����������������������������...Download