susumu.yata
null+****@clear*****
Wed May 29 14:34:14 JST 2013
susumu.yata 2013-05-29 14:34:14 +0900 (Wed, 29 May 2013) New Revision: e15438307c5cc9be9c222f939e88b1283ff7bfe2 https://github.com/groonga/grnxx/commit/e15438307c5cc9be9c222f939e88b1283ff7bfe2 Message: Update grnxx::map::ArrayMap to use Array. Remove obsolete modules (Bitmap and KeyArray). Removed files: lib/grnxx/map/bitmap.cpp lib/grnxx/map/bitmap.hpp lib/grnxx/map/key_array.cpp lib/grnxx/map/key_array.hpp Modified files: lib/grnxx/map/Makefile.am lib/grnxx/map/array_map.cpp lib/grnxx/map/array_map.hpp lib/grnxx/map/helper.hpp Modified: lib/grnxx/map/Makefile.am (+0 -4) =================================================================== --- lib/grnxx/map/Makefile.am 2013-05-29 13:16:51 +0900 (bcc0e80) +++ lib/grnxx/map/Makefile.am 2013-05-29 14:34:14 +0900 (76179d5) @@ -4,19 +4,15 @@ libgrnxx_map_la_LDFLAGS = @AM_LTLDFLAGS@ libgrnxx_map_la_SOURCES = \ array_map.cpp \ - bitmap.cpp \ bytes_store.cpp \ - key_array.cpp \ cursor_impl.cpp \ scanner_impl.cpp libgrnxx_map_includedir = ${includedir}/grnxx/map libgrnxx_map_include_HEADERS = \ array_map.hpp \ - bitmap.hpp \ bytes_store.hpp \ cursor_impl.hpp \ header.hpp \ helper.hpp \ - key_array.hpp \ scanner_impl.hpp Modified: lib/grnxx/map/array_map.cpp (+14 -20) =================================================================== --- lib/grnxx/map/array_map.cpp 2013-05-29 13:16:51 +0900 (67c92bd) +++ lib/grnxx/map/array_map.cpp 2013-05-29 14:34:14 +0900 (6fac117) @@ -22,7 +22,6 @@ #include "grnxx/geo_point.hpp" #include "grnxx/logger.hpp" -#include "grnxx/map/helper.hpp" #include "grnxx/storage.hpp" namespace grnxx { @@ -116,7 +115,7 @@ bool ArrayMap<T>::get(int64_t key_id, Key *key) { return false; } bool bit; - if (!bitmap_.get(key_id, &bit)) { + if (!bitmap_->get(key_id, &bit)) { return false; } if (!bit) { @@ -151,7 +150,7 @@ bool ArrayMap<T>::unset(int64_t key_id) { // GRNXX_WARNING() << "not found: key_id = " << key_id; return false; } - if (!bitmap_.set(key_id, false)) { + if (!bitmap_->set(key_id, false)) { return false; } header_->next_key_id = key_id; @@ -180,7 +179,7 @@ bool ArrayMap<T>::find(KeyArg key, int64_t *key_id) { const Key normalized_key = map::Helper<T>::normalize(key); for (int64_t i = MAP_MIN_KEY_ID; i <= header_->max_key_id; ++i) { bool bit; - if (!bitmap_.get(i, &bit)) { + if (!bitmap_->get(i, &bit)) { return false; } if (bit) { @@ -206,7 +205,7 @@ bool ArrayMap<T>::add(KeyArg key, int64_t *key_id) { int64_t next_next_key_id = MAP_INVALID_KEY_ID; for (int64_t i = MAP_MIN_KEY_ID; i <= header_->max_key_id; ++i) { bool bit; - if (!bitmap_.get(i, &bit)) { + if (!bitmap_->get(i, &bit)) { return false; } if (bit) { @@ -227,7 +226,7 @@ bool ArrayMap<T>::add(KeyArg key, int64_t *key_id) { } } if (!keys_->set(next_key_id, normalized_key) || - !bitmap_.set(next_key_id, true)) { + !bitmap_->set(next_key_id, true)) { return false; } if (next_key_id == (header_->max_key_id + 1)) { @@ -252,7 +251,7 @@ bool ArrayMap<T>::remove(KeyArg key) { // GRNXX_WARNING() << "not found: key = " << key; return false; } - if (!bitmap_.set(key_id, false)) { + if (!bitmap_->set(key_id, false)) { return false; } header_->next_key_id = key_id; @@ -267,7 +266,7 @@ bool ArrayMap<T>::replace(KeyArg src_key, KeyArg dest_key, int64_t *key_id) { int64_t src_key_id = MAP_INVALID_KEY_ID; for (int64_t i = MAP_MIN_KEY_ID; i <= header_->max_key_id; ++i) { bool bit; - if (!bitmap_.get(i, &bit)) { + if (!bitmap_->get(i, &bit)) { return false; } if (bit) { @@ -317,16 +316,13 @@ bool ArrayMap<T>::create_map(Storage *storage, uint32_t storage_node_id, storage_node_id_ = storage_node.id(); header_ = static_cast<ArrayMapHeader *>(storage_node.body()); *header_ = ArrayMapHeader(); - if (!bitmap_.create(storage, storage_node_id_, false)) { - storage->unlink_node(storage_node_id_); - return false; - } - header_->bitmap_storage_node_id = bitmap_.storage_node_id(); - keys_.reset(Array<T>::create(storage, storage_node_id_)); - if (!keys_) { + bitmap_.reset(Bitmap::create(storage, storage_node_id_)); + keys_.reset(KeyArray::create(storage, storage_node_id_)); + if (!bitmap_ || !keys_) { storage->unlink_node(storage_node_id_); return false; } + header_->bitmap_storage_node_id = bitmap_->storage_node_id(); header_->keys_storage_node_id = keys_->storage_node_id(); return true; } @@ -345,11 +341,9 @@ bool ArrayMap<T>::open_map(Storage *storage, uint32_t storage_node_id) { } storage_node_id_ = storage_node_id; header_ = static_cast<ArrayMapHeader *>(storage_node.body()); - if (!bitmap_.open(storage, header_->bitmap_storage_node_id)) { - return false; - } - keys_.reset(Array<T>::open(storage, header_->keys_storage_node_id)); - if (!keys_) { + bitmap_.reset(Bitmap::open(storage, header_->bitmap_storage_node_id)); + keys_.reset(KeyArray::open(storage, header_->keys_storage_node_id)); + if (!bitmap_ || !keys_) { return false; } return true; Modified: lib/grnxx/map/array_map.hpp (+6 -3) =================================================================== --- lib/grnxx/map/array_map.hpp 2013-05-29 13:16:51 +0900 (4d87bfa) +++ lib/grnxx/map/array_map.hpp 2013-05-29 14:34:14 +0900 (e98c12b) @@ -22,7 +22,7 @@ #include "grnxx/array.hpp" #include "grnxx/map.hpp" -#include "grnxx/map/bitmap.hpp" +#include "grnxx/map/helper.hpp" #include "grnxx/types.hpp" namespace grnxx { @@ -40,6 +40,9 @@ class ArrayMap : public Map<T> { using KeyArg = typename Map<T>::KeyArg; using Cursor = typename Map<T>::Cursor; + using Bitmap = typename Helper<T>::Bitmap; + using KeyArray = typename Helper<T>::KeyArray; + ArrayMap(); ~ArrayMap(); @@ -71,8 +74,8 @@ class ArrayMap : public Map<T> { Storage *storage_; uint32_t storage_node_id_; ArrayMapHeader *header_; - Bitmap<T> bitmap_; - std::unique_ptr<Array<T>> keys_; + std::unique_ptr<Bitmap> bitmap_; + std::unique_ptr<KeyArray> keys_; bool create_map(Storage *storage, uint32_t storage_node_id, const MapOptions &options); Deleted: lib/grnxx/map/bitmap.cpp (+0 -24) 100644 =================================================================== --- lib/grnxx/map/bitmap.cpp 2013-05-29 13:16:51 +0900 (7cd3b03) +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright (C) 2013 Brazil, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#include "grnxx/map/bitmap.hpp" - -namespace grnxx { -namespace map { - -} // namespace map -} // namespace grnxx Deleted: lib/grnxx/map/bitmap.hpp (+0 -122) 100644 =================================================================== --- lib/grnxx/map/bitmap.hpp 2013-05-29 13:16:51 +0900 (9d3ab6f) +++ /dev/null @@ -1,122 +0,0 @@ -/* - Copyright (C) 2013 Brazil, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#ifndef GRNXX_MAP_BITMAP_HPP -#define GRNXX_MAP_BITMAP_HPP - -#include "grnxx/features.hpp" - -#include "grnxx/bit_array.hpp" -#include "grnxx/types.hpp" - -namespace grnxx { - -class Storage; - -namespace map { - -// Change the settings based on the key type. -template <typename T, size_t T_SIZE = sizeof(T)> -struct BitmapTraits { - // Map<T> has at most 2^40 different keys. - using ArrayType = BitArray<>; -}; -template <typename T> -struct BitmapTraits<T, 1> { - // Map<T> has at most 2^8 different keys. - using ArrayType = BitArray<256, 1, 1>; -}; -template <typename T> -struct BitmapTraits<T, 2> { - // Map<T> has at most 2^16 different keys. - using ArrayType = BitArray<256, 256, 1>; -}; -template <typename T> -struct BitmapTraits<T, 4> { - // Map<T> has at most 2^32 different keys. - using ArrayType = BitArray<65536, 256, 256>; -}; - -// TODO: Unused member functions will be removed in future. -template <typename T> -class Bitmap { - public: - using ArrayImpl = typename BitmapTraits<T>::ArrayType; - using Bit = typename ArrayImpl::Value; - using BitArg = typename ArrayImpl::ValueArg; - using Unit = typename ArrayImpl::Unit; - - // Return true iff the bitmap is valid. - explicit operator bool() const { - return static_cast<bool>(impl_); - } - - // Create a bitmap. - bool create(Storage *storage, uint32_t storage_node_id) { - return impl_.create(storage, storage_node_id); - } - // Create a bitmap with the default bit. - bool create(Storage *storage, uint32_t storage_node_id, - BitArg default_bit) { - return impl_.create(storage, storage_node_id, default_bit); - } - // Open a bitmap. - bool open(Storage *storage, uint32_t storage_node_id) { - return impl_.open(storage, storage_node_id); - } - - // Unlink a bitmap. - static bool unlink(Storage *storage, uint32_t storage_node_id) { - return ArrayImpl::unlink(storage, storage_node_id); - } - - // Return the storage node ID. - uint32_t storage_node_id() const { - return impl_.storage_node_id(); - } - - // Get a bit. - // This function throws an exception on failure. - Bit operator[](uint64_t bit_id) { - return impl_[bit_id]; - } - - // Get a bit and return true on success. - // The bit is assigned to "*bit" iff "bit" != nullptr. - bool get(uint64_t bit_id, Bit *bit) { - return impl_.get(bit_id, bit); - } - // Set a bit and return true on success. - // Note that if bits in the same byte are set at the same time, the result is - // undefined. - bool set(uint64_t bit_id, BitArg bit) { - return impl_.set(bit_id, bit); - } - - // Get a unit and return its address on success. - Unit *get_unit(uint64_t unit_id) { - return impl_.get_unit(unit_id); - } - - private: - ArrayImpl impl_; -}; - -} // namespace map -} // namespace grnxx - -#endif // GRNXX_MAP_BITMAP_HPP Modified: lib/grnxx/map/helper.hpp (+47 -0) =================================================================== --- lib/grnxx/map/helper.hpp 2013-05-29 13:16:51 +0900 (0a7dc37) +++ lib/grnxx/map/helper.hpp 2013-05-29 14:34:14 +0900 (3c36970) @@ -30,6 +30,50 @@ namespace grnxx { namespace map { +// Change the settings based on the key type. +template <typename T, size_t T_SIZE = sizeof(T)> +struct BitmapHelper { + // Map<T> has at most 2^40 different keys. + using Type = Array<bool>; +}; +template <typename T> +struct BitmapHelper<T, 1> { + // Map<T> has at most 2^8 different keys. + using Type = Array<bool, 256, 1, 1>; +}; +template <typename T> +struct BitmapHelper<T, 2> { + // Map<T> has at most 2^16 different keys. + using Type = Array<bool, 256, 256, 1>; +}; +template <typename T> +struct BitmapHelper<T, 4> { + // Map<T> has at most 2^32 different keys. + using Type = Array<bool, 65536, 256, 256>; +}; + +// Change the settings based on the key type. +template <typename T, size_t T_SIZE = sizeof(T)> +struct KeyArrayHelper { + // Map<T> has at most 2^40 different keys. + using Type = Array<T>; +}; +template <typename T> +struct KeyArrayHelper<T, 1> { + // Map<T> has at most 2^8 different keys. + using Type = Array<T, 256, 1, 1>; +}; +template <typename T> +struct KeyArrayHelper<T, 2> { + // Map<T> has at most 2^16 different keys. + using Type = Array<T, 256, 256, 1>; +}; +template <typename T> +struct KeyArrayHelper<T, 4> { + // Map<T> has at most 2^32 different keys. + using Type = Array<T, 65536, 256, 256>; +}; + // Normalize a key. template <typename T, bool IS_FLOATING_POINT = std::is_floating_point<T>::value> @@ -90,6 +134,9 @@ struct Helper { using Key = typename Traits<T>::Type; using KeyArg = typename Traits<T>::ArgumentType; + using Bitmap = typename BitmapHelper<T>::Type; + using KeyArray = typename KeyArrayHelper<T>::Type; + static Key normalize(KeyArg key) { return NormalizeHelper<T>::normalize(key); } Deleted: lib/grnxx/map/key_array.cpp (+0 -24) 100644 =================================================================== --- lib/grnxx/map/key_array.cpp 2013-05-29 13:16:51 +0900 (6efd1ad) +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright (C) 2013 Brazil, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#include "grnxx/map/key_array.hpp" - -namespace grnxx { -namespace map { - -} // namespace map -} // namespace grnxx Deleted: lib/grnxx/map/key_array.hpp (+0 -113) 100644 =================================================================== --- lib/grnxx/map/key_array.hpp 2013-05-29 13:16:51 +0900 (dcc24c0) +++ /dev/null @@ -1,113 +0,0 @@ -/* - Copyright (C) 2013 Brazil, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#ifndef GRNXX_MAP_KEY_ARRAY_HPP -#define GRNXX_MAP_KEY_ARRAY_HPP - -#include "grnxx/features.hpp" - -#include "grnxx/array.hpp" -#include "grnxx/types.hpp" - -namespace grnxx { - -class Storage; - -namespace map { - -// Change the settings based on the key type. -template <typename T, size_t T_SIZE = sizeof(T)> -struct KeyArrayTraits { - // Map<T> has at most 2^40 different keys. - using ArrayType = Array<T>; -}; -template <typename T> -struct KeyArrayTraits<T, 1> { - // Map<T> has at most 2^8 different keys. - using ArrayType = Array<T, 256, 1, 1>; -}; -template <typename T> -struct KeyArrayTraits<T, 2> { - // Map<T> has at most 2^16 different keys. - using ArrayType = Array<T, 256, 256, 1>; -}; -template <typename T> -struct KeyArrayTraits<T, 4> { - // Map<T> has at most 2^32 different keys. - using ArrayType = Array<T, 65536, 256, 256>; -}; - -template <typename T> -class KeyArray { - public: - using ArrayImpl = typename KeyArrayTraits<T>::ArrayType; - using Key = typename ArrayImpl::Value; - using KeyArg = typename ArrayImpl::ValueArg; - - // Return true iff the array is valid. - explicit operator bool() const { - return static_cast<bool>(impl_); - } - - // Create an array. - bool create(Storage *storage, uint32_t storage_node_id) { - return impl_.create(storage, storage_node_id); - } - // Create an array with the default key. - bool create(Storage *storage, uint32_t storage_node_id, - KeyArg default_key) { - return impl_.create(storage, storage_node_id, default_key); - } - // Open an array. - bool open(Storage *storage, uint32_t storage_node_id) { - return impl_.open(storage, storage_node_id); - } - - // Unlink an array. - static bool unlink(Storage *storage, uint32_t storage_node_id) { - return ArrayImpl::unlink(storage, storage_node_id); - } - - // Return the storage node ID. - uint32_t storage_node_id() const { - return impl_.storage_node_id(); - } - - // Get a key. - // This function throws an exception on failure. - Key operator[](uint64_t key_id) { - return impl_[key_id]; - } - - // Get a key and return true on success. - // The key is assigned to "*key" iff "key" != nullptr. - bool get(uint64_t key_id, Key *key) { - return impl_.get(key_id, key); - } - // Set a key and return true on success. - bool set(uint64_t key_id, KeyArg key) { - return impl_.set(key_id, key); - } - - private: - ArrayImpl impl_; -}; - -} // namespace map -} // namespace grnxx - -#endif // GRNXX_MAP_KEY_ARRAY_HPP -------------- next part -------------- HTML����������������������������... ダウンロード