susumu.yata
null+****@clear*****
Wed Jul 24 17:05:52 JST 2013
susumu.yata 2013-07-24 17:05:52 +0900 (Wed, 24 Jul 2013) New Revision: 7893bdec64df3de6ed4265b0d3e57bf93adaa356 https://github.com/groonga/grnxx/commit/7893bdec64df3de6ed4265b0d3e57bf93adaa356 Message: Remove grnxx::map::BytesArray. Removed files: lib/grnxx/map/bytes_array.cpp lib/grnxx/map/bytes_array.hpp Modified files: lib/grnxx/map/Makefile.am lib/grnxx/map/helper.hpp test/test_map.cpp Modified: lib/grnxx/map/Makefile.am (+0 -2) =================================================================== --- lib/grnxx/map/Makefile.am 2013-07-24 16:55:44 +0900 (3fe4507) +++ lib/grnxx/map/Makefile.am 2013-07-24 17:05:52 +0900 (6f9f4d6) @@ -12,7 +12,6 @@ libgrnxx_map_la_LDFLAGS = @AM_LTLDFLAGS@ libgrnxx_map_la_SOURCES = \ array_map.cpp \ - bytes_array.cpp \ bytes_pool.cpp \ common_header.cpp \ cursor_impl.cpp \ @@ -25,7 +24,6 @@ libgrnxx_map_la_SOURCES = \ libgrnxx_map_includedir = ${includedir}/grnxx/map libgrnxx_map_include_HEADERS = \ array_map.hpp \ - bytes_array.hpp \ bytes_pool.hpp \ common_header.hpp \ cursor_impl.hpp \ Deleted: lib/grnxx/map/bytes_array.cpp (+0 -145) 100644 =================================================================== --- lib/grnxx/map/bytes_array.cpp 2013-07-24 16:55:44 +0900 (01163b9) +++ /dev/null @@ -1,145 +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/bytes_array.hpp" - -#include <cstring> -#include <new> - -#include "grnxx/exception.hpp" -#include "grnxx/logger.hpp" -#include "grnxx/storage.hpp" - -namespace grnxx { -namespace map { - -struct BytesArrayHeader { - uint64_t default_value_size; - uint32_t ids_storage_node_id; - uint32_t pool_storage_node_id; - - BytesArrayHeader(); -}; - -BytesArrayHeader::BytesArrayHeader() - : default_value_size(0), - ids_storage_node_id(STORAGE_INVALID_NODE_ID), - pool_storage_node_id(STORAGE_INVALID_NODE_ID) {} - -BytesArray::~BytesArray() {} - -BytesArray *BytesArray::create(Storage *storage, uint32_t storage_node_id, - uint64_t size) { - return create(storage, storage_node_id, size, ""); -} - -BytesArray *BytesArray::create(Storage *storage, uint32_t storage_node_id, - uint64_t size, ValueArg default_value) { - if (!storage) { - GRNXX_ERROR() << "invalid argument: storage = nullptr"; - throw LogicError(); - } - std::unique_ptr<BytesArray> array(new (std::nothrow) BytesArray); - if (!array) { - GRNXX_ERROR() << "new grnxx::map::BytesArray failed"; - throw MemoryError(); - } - array->create_array(storage, storage_node_id, size, default_value); - return array.release(); -} - -BytesArray *BytesArray::open(Storage *storage, uint32_t storage_node_id) { - if (!storage) { - GRNXX_ERROR() << "invalid argument: storage = nullptr"; - throw LogicError(); - } - std::unique_ptr<BytesArray> array(new (std::nothrow) BytesArray); - if (!array) { - GRNXX_ERROR() << "new grnxx::map::BytesArray failed"; - throw MemoryError(); - } - array->open_array(storage, storage_node_id); - return array.release(); -} - -void BytesArray::unlink(Storage *storage, uint32_t storage_node_id) { - std::unique_ptr<BytesArray> array(open(storage, storage_node_id)); - storage->unlink_node(storage_node_id); -} - -void BytesArray::set(uint64_t value_id, ValueArg value) { - uint64_t * const src_bytes_id = &ids_->get_value(value_id); - const uint64_t dest_bytes_id = pool_->add(value); - if (*src_bytes_id != INVALID_BYTES_ID) { - try { - pool_->unset(*src_bytes_id); - } catch (...) { - pool_->unset(dest_bytes_id); - throw; - } - } - *src_bytes_id = dest_bytes_id; -} - -void BytesArray::sweep(Duration lifetime) { - pool_->sweep(lifetime); -} - -BytesArray::BytesArray() - : storage_(nullptr), - storage_node_id_(STORAGE_INVALID_NODE_ID), - header_(nullptr), - default_value_(), - ids_(), - pool_() {} - -void BytesArray::create_array(Storage *storage, uint32_t storage_node_id, - uint64_t size, ValueArg default_value) { - storage_ = storage; - uint64_t storage_node_size = sizeof(BytesArrayHeader) + default_value.size(); - StorageNode storage_node = - storage->create_node(storage_node_id, storage_node_size); - storage_node_id_ = storage_node.id(); - try { - header_ = static_cast<BytesArrayHeader *>(storage_node.body()); - *header_ = BytesArrayHeader(); - header_->default_value_size = default_value.size(); - std::memcpy(header_ + 1, default_value.data(), default_value.size()); - default_value_ = Value(header_ + 1, default_value.size()); - ids_.reset(IDArray::create(storage, storage_node_id_, size, - INVALID_BYTES_ID)); - pool_.reset(BytesPool::create(storage, storage_node_id_)); - header_->ids_storage_node_id = ids_->storage_node_id(); - header_->pool_storage_node_id = pool_->storage_node_id(); - } catch (...) { - storage->unlink_node(storage_node_id_); - throw; - } -} - -void BytesArray::open_array(Storage *storage, uint32_t storage_node_id) { - storage_ = storage; - StorageNode storage_node = storage->open_node(storage_node_id); - storage_node_id_ = storage_node.id(); - header_ = static_cast<BytesArrayHeader *>(storage_node.body()); - default_value_ = Value(header_ + 1, header_->default_value_size); - ids_.reset(IDArray::open(storage, header_->ids_storage_node_id)); - pool_.reset(BytesPool::open(storage, header_->pool_storage_node_id)); -} - -} // namespace map -} // namespace grnxx Deleted: lib/grnxx/map/bytes_array.hpp (+0 -110) 100644 =================================================================== --- lib/grnxx/map/bytes_array.hpp 2013-07-24 16:55:44 +0900 (95324e2) +++ /dev/null @@ -1,110 +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_BYTES_ARRAY_HPP -#define GRNXX_MAP_BYTES_ARRAY_HPP - -#include "grnxx/features.hpp" - -#include <memory> - -#include "grnxx/array.hpp" -#include "grnxx/bytes.hpp" -#include "grnxx/duration.hpp" -#include "grnxx/map/bytes_pool.hpp" -#include "grnxx/traits.hpp" -#include "grnxx/types.hpp" - -namespace grnxx { - -class Storage; - -namespace map { - -class BytesPool; - -struct BytesArrayHeader; - -class BytesArray { - static constexpr uint64_t INVALID_BYTES_ID = ~0ULL; - - public: - using Value = typename Traits<Bytes>::Type; - using ValueArg = typename Traits<Bytes>::ArgumentType; - - using IDArray = Array<uint64_t, 65536, 4096>; - - ~BytesArray(); - - // Create an array. - static BytesArray *create(Storage *storage, uint32_t storage_node_id, - uint64_t size); - // Create an array with default value. - static BytesArray *create(Storage *storage, uint32_t storage_node_id, - uint64_t size, ValueArg default_value); - // Open an array. - static BytesArray *open(Storage *storage, uint32_t storage_node_id); - - // Unlink an array. - static void unlink(Storage *storage, uint32_t storage_node_id); - - // Return the number of values in Array. - uint64_t size() const { - return ids_->size(); - } - - // Return the storage node ID. - uint32_t storage_node_id() const { - return storage_node_id_; - } - - // Get a value. - Value get(uint64_t value_id) { - const uint64_t bytes_id = ids_->get(value_id); - if (bytes_id == INVALID_BYTES_ID) { - return default_value_; - } else { - return pool_->get(bytes_id); - } - } - // Set a value. - void set(uint64_t value_id, ValueArg value); - - // Sweep empty pages whose modified time < (now - lifetime). - void sweep(Duration lifetime); - - private: - Storage *storage_; - uint32_t storage_node_id_; - BytesArrayHeader *header_; - Value default_value_; - std::unique_ptr<IDArray> ids_; - std::unique_ptr<BytesPool> pool_; - - BytesArray(); - - // Create an array with the default value. - void create_array(Storage *storage, uint32_t storage_node_id, - uint64_t size, ValueArg default_value); - // Open an array. - void open_array(Storage *storage, uint32_t storage_node_id); -}; - -} // namespace map -} // namespace grnxx - -#endif // GRNXX_MAP_BYTES_ARRAY_HPP Modified: lib/grnxx/map/helper.hpp (+0 -1) =================================================================== --- lib/grnxx/map/helper.hpp 2013-07-24 16:55:44 +0900 (5914f21) +++ lib/grnxx/map/helper.hpp 2013-07-24 17:05:52 +0900 (8144d4c) @@ -27,7 +27,6 @@ #include "grnxx/array.hpp" #include "grnxx/bytes.hpp" -#include "grnxx/map/bytes_array.hpp" #include "grnxx/traits.hpp" namespace grnxx { Modified: test/test_map.cpp (+0 -92) =================================================================== --- test/test_map.cpp 2013-07-24 16:55:44 +0900 (db144b0) +++ test/test_map.cpp 2013-07-24 17:05:52 +0900 (c1dd87c) @@ -28,7 +28,6 @@ #include "grnxx/geo_point.hpp" #include "grnxx/logger.hpp" #include "grnxx/map.hpp" -#include "grnxx/map/bytes_array.hpp" #include "grnxx/map/bytes_pool.hpp" #include "grnxx/map/hash.hpp" #include "grnxx/map/helper.hpp" @@ -258,86 +257,6 @@ void test_bytes_pool_sweep() { pool->sweep(grnxx::Duration(0)); } -void test_bytes_array_create() { - std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr)); - std::unique_ptr<grnxx::map::BytesArray> array( - grnxx::map::BytesArray::create(storage.get(), - grnxx::STORAGE_ROOT_NODE_ID, - 1ULL << 40)); -} - -void test_bytes_array_create_with_default_value() { - std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr)); - std::unique_ptr<grnxx::map::BytesArray> array( - grnxx::map::BytesArray::create(storage.get(), - grnxx::STORAGE_ROOT_NODE_ID, - 1ULL << 40, - "Default")); -} - -void test_bytes_array_open() { - std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr)); - std::unique_ptr<grnxx::map::BytesArray> array( - grnxx::map::BytesArray::create(storage.get(), - grnxx::STORAGE_ROOT_NODE_ID, - 1ULL << 40)); - const std::uint32_t storage_node_id = array->storage_node_id(); - array.reset(grnxx::map::BytesArray::open(storage.get(), storage_node_id)); -} - -void test_bytes_array_unlink() { - std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr)); - std::unique_ptr<grnxx::map::BytesArray> array( - grnxx::map::BytesArray::create(storage.get(), - grnxx::STORAGE_ROOT_NODE_ID, - 1ULL << 40)); - grnxx::StorageNode storage_node = - storage->open_node(array->storage_node_id()); - grnxx::map::BytesArray::unlink(storage.get(), storage_node.id()); - assert(storage_node.status() == grnxx::STORAGE_NODE_UNLINKED); -} - -void test_bytes_array_storage_node_id() { - std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr)); - std::unique_ptr<grnxx::map::BytesArray> array( - grnxx::map::BytesArray::create(storage.get(), - grnxx::STORAGE_ROOT_NODE_ID, - 1ULL << 40)); - grnxx::StorageNode storage_node = - storage->open_node(array->storage_node_id()); - assert(storage_node.status() == grnxx::STORAGE_NODE_ACTIVE); -} - -void test_bytes_array_get() { - std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr)); - std::unique_ptr<grnxx::map::BytesArray> array( - grnxx::map::BytesArray::create(storage.get(), - grnxx::STORAGE_ROOT_NODE_ID, - 1ULL << 40)); - std::vector<grnxx::Bytes> keys; - generate_random_keys(MAP_NUM_KEYS, &keys); - for (std::uint64_t i = 0; i < MAP_NUM_KEYS; ++i) { - array->set(i, keys[i]); - } - for (std::uint64_t i = 0; i < MAP_NUM_KEYS; ++i) { - grnxx::Bytes stored_key = array->get(i); - assert(stored_key == keys[i]); - } -} - -void test_bytes_array_set() { - std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr)); - std::unique_ptr<grnxx::map::BytesArray> array( - grnxx::map::BytesArray::create(storage.get(), - grnxx::STORAGE_ROOT_NODE_ID, - 1ULL << 40)); - std::vector<grnxx::Bytes> keys; - generate_random_keys(MAP_NUM_KEYS, &keys); - for (std::uint64_t i = 0; i < MAP_NUM_KEYS; ++i) { - array->set(i, keys[i]); - } -} - template <typename T> void test_map_create(grnxx::MapType map_type) { std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr)); @@ -889,16 +808,6 @@ void test_bytes_pool() { test_bytes_pool_sweep(); } -void test_bytes_array() { - test_bytes_array_create(); - test_bytes_array_create_with_default_value(); - test_bytes_array_open(); - test_bytes_array_unlink(); - test_bytes_array_storage_node_id(); - test_bytes_array_get(); - test_bytes_array_set(); -} - void test_map() { test_map<std::int8_t>(); test_map<std::uint8_t>(); @@ -927,7 +836,6 @@ int main() { GRNXX_NOTICE() << "mersenne_twister_seed = " << mersenne_twister_seed; test_bytes_pool(); - test_bytes_array(); test_map(); return 0; -------------- next part -------------- HTML����������������������������...Download