susumu.yata
null+****@clear*****
Fri Feb 22 13:46:29 JST 2013
susumu.yata 2013-02-22 13:46:29 +0900 (Fri, 22 Feb 2013) New Revision: 1966cff8c5e883d0fd4529933be5527192af4d3a https://github.com/groonga/grnxx/commit/1966cff8c5e883d0fd4529933be5527192af4d3a Log: Remove grnxx::db::Array. Removed files: lib/db/array.cpp lib/db/array.hpp test/test_db_array.cpp Modified files: .gitignore lib/db/Makefile.am test/Makefile.am Modified: .gitignore (+0 -1) =================================================================== --- .gitignore 2013-02-22 13:22:09 +0900 (edbe982) +++ .gitignore 2013-02-22 13:46:29 +0900 (44f2c36) @@ -29,7 +29,6 @@ stamp-h1 temp/ test/test_alpha_double_array test/test_backtrace -test/test_db_array test/test_db_blob_vector test/test_db_vector test/test_duration Modified: lib/db/Makefile.am (+0 -2) =================================================================== --- lib/db/Makefile.am 2013-02-22 13:22:09 +0900 (795faf4) +++ lib/db/Makefile.am 2013-02-22 13:46:29 +0900 (822d206) @@ -3,12 +3,10 @@ noinst_LTLIBRARIES = libgrnxx_db.la libgrnxx_db_la_LDFLAGS = @AM_LTLDFLAGS@ libgrnxx_db_la_SOURCES = \ - array.cpp \ blob_vector.cpp \ vector.cpp libgrnxx_db_includedir = ${includedir}/grnxx/db libgrnxx_db_include_HEADERS = \ - array.hpp \ blob_vector.hpp \ vector.hpp Deleted: lib/db/array.cpp (+0 -156) 100644 =================================================================== --- lib/db/array.cpp 2013-02-22 13:22:09 +0900 (00c8839) +++ /dev/null @@ -1,156 +0,0 @@ -/* - Copyright (C) 2012 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 "array.hpp" - -namespace grnxx { -namespace db { - -void ArrayHeader::initialize(uint64_t value_size, uint64_t array_size) { - std::memset(this, 0, sizeof(ArrayHeader)); - value_size_ = value_size; - array_size_ = array_size; -} - -ArrayImpl::ArrayImpl() - : pool_(), block_id_(io::BLOCK_INVALID_ID), - header_(nullptr), address_(nullptr) {} - -ArrayImpl::ArrayImpl(io::Pool *pool, uint64_t value_size, uint64_t array_size) - : pool_(), block_id_(io::BLOCK_INVALID_ID), - header_(nullptr), address_(nullptr) { - if (!pool) { - GRNXX_ERROR() << "invalid argument: pool = " << pool; - GRNXX_THROW(); - } - if (value_size == 0) { - GRNXX_ERROR() << "invalid argument: value_size = " << value_size; - GRNXX_THROW(); - } - - pool_ = *pool; - - const io::BlockInfo *block_info = - pool->create_block(ARRAY_HEADER_SIZE + (value_size * array_size)); - - header_ = static_cast<ArrayHeader *>(pool->get_block_address(*block_info)); - header_->initialize(value_size, array_size); - - block_id_ = block_info->id(); - address_ = header_ + 1; -} - -ArrayImpl::ArrayImpl(io::Pool *pool, uint32_t block_id) - : pool_(), block_id_(io::BLOCK_INVALID_ID), - header_(nullptr), address_(nullptr) { - if (!pool) { - GRNXX_ERROR() << "invalid argument: pool = " << pool; - GRNXX_THROW(); - } - - pool_ = *pool; - - const io::BlockInfo *block_info = pool->get_block_info(block_id); - if (block_info->size() < ARRAY_HEADER_SIZE) { - GRNXX_ERROR() << "too small block: block_size = " << block_info->size(); - GRNXX_THROW(); - } - - block_id_ = block_info->id(); - header_ = static_cast<ArrayHeader *>(pool->get_block_address(*block_info)); - address_ = header_ + 1; - - if (value_size() == 0) { - GRNXX_ERROR() << "invalid parameter: value_size = " << value_size(); - GRNXX_THROW(); - } - - const uint64_t required_block_size = - ARRAY_HEADER_SIZE + (value_size() * array_size()); - if (block_info->size() < required_block_size) { - GRNXX_ERROR() << "block size conflict: block_size = " << block_info->size() - << ", required_block_size = " << required_block_size; - GRNXX_THROW(); - } -} - -ArrayImpl::~ArrayImpl() {} - -ArrayImpl::ArrayImpl(ArrayImpl &&array) - : pool_(std::move(array.pool_)), block_id_(std::move(array.block_id_)), - header_(std::move(array.header_)), address_(std::move(array.address_)) {} - -ArrayImpl &ArrayImpl::operator=(ArrayImpl &&array) { - pool_ = std::move(array.pool_); - block_id_ = std::move(array.block_id_); - header_ = std::move(array.header_); - address_ = std::move(array.address_); - return *this; -} - -void ArrayImpl::create(io::Pool *pool, uint64_t value_size, - uint64_t array_size) { - ArrayImpl(pool, value_size, array_size).swap(*this); -} - -void ArrayImpl::open(io::Pool *pool, uint32_t block_id) { - ArrayImpl(pool, block_id).swap(*this); -} - -void ArrayImpl::swap(ArrayImpl &array) { - using std::swap; - swap(pool_, array.pool_); - swap(block_id_, array.block_id_); - swap(header_, array.header_); - swap(address_, array.address_); -} - -void ArrayImpl::unlink(io::Pool *pool, uint32_t block_id) { - pool->free_block(block_id); -} - -StringBuilder &ArrayHeader::write_to(StringBuilder &builder) const { - if (!builder) { - return builder; - } - - return builder << "{ value_size = " << value_size_ - << ", array_size = " << array_size_ << " }"; -} - -StringBuilder &ArrayImpl::write_to(StringBuilder &builder) const { - if (!builder) { - return builder; - } - - if (!pool_) { - return builder << "n/a"; - } - - builder << "{ pool = " << pool_.path() - << ", block_id = " << block_id_ - << ", header = "; - if (header_) { - builder << *header_; - } else { - builder << "n/a"; - } - return builder << ", address = " << address_ << " }"; -} - -} // namespace db -} // namespace grnxx Deleted: lib/db/array.hpp (+0 -187) 100644 =================================================================== --- lib/db/array.hpp 2013-02-22 13:22:09 +0900 (49b513b) +++ /dev/null @@ -1,187 +0,0 @@ -/* - Copyright (C) 2012 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_DB_ARRAY_HPP -#define GRNXX_DB_ARRAY_HPP - -#include "../exception.hpp" -#include "../logger.hpp" -#include "../io/pool.hpp" - -namespace grnxx { -namespace db { - -const uint64_t ARRAY_HEADER_SIZE = 64; - -class ArrayHeader { - public: - void initialize(uint64_t value_size, uint64_t array_size); - - uint64_t value_size() const { - return value_size_; - } - uint64_t array_size() const { - return array_size_; - } - - StringBuilder &write_to(StringBuilder &builder) const; - - private: - uint64_t value_size_; - uint64_t array_size_; - uint8_t reserved_[ARRAY_HEADER_SIZE - 16]; -}; - -static_assert(sizeof(ArrayHeader) == ARRAY_HEADER_SIZE, - "sizeof(ArrayHeader) is wrong"); - -class ArrayImpl { - public: - ArrayImpl(); - ArrayImpl(io::Pool *pool, uint64_t value_size, uint64_t array_size); - ArrayImpl(io::Pool *pool, uint32_t block_id); - ~ArrayImpl(); - - ArrayImpl(ArrayImpl &&array); - ArrayImpl &operator=(ArrayImpl &&array); - - void create(io::Pool *pool, uint64_t value_size, uint64_t array_size); - void open(io::Pool *pool, uint32_t block_id); - - uint32_t block_id() const { - return block_id_; - } - uint64_t value_size() const { - return header_->value_size(); - } - uint64_t array_size() const { - return header_->array_size(); - } - void *address() const { - return address_; - } - - void swap(ArrayImpl &array); - - StringBuilder &write_to(StringBuilder &builder) const; - - static void unlink(io::Pool *pool, uint32_t block_id); - - private: - io::Pool pool_; - uint32_t block_id_; - ArrayHeader *header_; - void *address_; - - ArrayImpl(const ArrayImpl &); - ArrayImpl &operator=(const ArrayImpl &); -}; - -inline void swap(ArrayImpl &lhs, ArrayImpl &rhs) { - lhs.swap(rhs); -} - -template <typename T> -class Array { - public: - typedef T Value; - - Array() : impl_() {} - ~Array() {} - - Array(Array &&array) : impl_(std::move(array.impl_)) {} - Array &operator=(Array &&array) { - impl_ = std::move(array.impl_); - return *this; - } - - void create(io::Pool *pool, uint64_t size) { - impl_.create(pool, sizeof(Value), size); - } - void open(io::Pool *pool, uint32_t block_id) { - ArrayImpl new_impl; - new_impl.open(pool, block_id); - if (new_impl.value_size() != sizeof(Value)) { - GRNXX_ERROR() << "invalid value size: expected = " << sizeof(Value) - << ", actual = " << new_impl.value_size(); - GRNXX_THROW(); - } - impl_ = std::move(new_impl); - } - void close() { - ArrayImpl().swap(impl_); - } - - Value &operator[](uint64_t id) const { - return address()[id]; - } - - uint32_t block_id() const { - return impl_.block_id(); - } - uint64_t size() const { - return impl_.array_size(); - } - Value *address() const { - return static_cast<Value *>(impl_.address()); - } - - void swap(Array &array) { - impl_.swap(array.impl_); - } - - StringBuilder &write_to(StringBuilder &builder) const { - return impl_.write_to(builder); - } - - static void unlink(io::Pool *pool, uint32_t block_id) { - Array array; - array.open(pool, block_id); - array.close(); - ArrayImpl::unlink(pool, block_id); - } - - private: - ArrayImpl impl_; - - Array(const Array &); - Array &operator=(const Array &); -}; - -template <typename T> -inline void swap(Array<T> &lhs, Array<T> &rhs) { - lhs.swap(rhs); -} - -inline StringBuilder &operator<<(StringBuilder &builder, - const ArrayHeader &header) { - return header.write_to(builder); -} -inline StringBuilder &operator<<(StringBuilder &builder, - const ArrayImpl &array) { - return array.write_to(builder); -} -template <typename T> -inline StringBuilder &operator<<(StringBuilder &builder, - const Array<T> &array) { - return array.write_to(builder); -} - -} // namespace db -} // namespace grnxx - -#endif // GRNXX_DB_ARRAY_HPP Modified: test/Makefile.am (+0 -4) =================================================================== --- test/Makefile.am 2013-02-22 13:22:09 +0900 (8997a62) +++ test/Makefile.am 2013-02-22 13:46:29 +0900 (3e3e1b9) @@ -3,7 +3,6 @@ AM_CXXFLAGS = @AM_CXXFLAGS@ -I$(top_srcdir)/lib TESTS = \ test_alpha_double_array \ test_backtrace \ - test_db_array \ test_db_blob_vector \ test_db_vector \ test_duration \ @@ -40,9 +39,6 @@ test_alpha_double_array_LDADD = ../lib/libgrnxx.la test_backtrace_SOURCES = test_backtrace.cpp test_backtrace_LDADD = ../lib/libgrnxx.la -test_db_array_SOURCES = test_db_array.cpp -test_db_array_LDADD = ../lib/libgrnxx.la - test_db_blob_vector_SOURCES = test_db_blob_vector.cpp test_db_blob_vector_LDADD = ../lib/libgrnxx.la Deleted: test/test_db_array.cpp (+0 -110) 100644 =================================================================== --- test/test_db_array.cpp 2013-02-22 13:22:09 +0900 (277f3d0) +++ /dev/null @@ -1,110 +0,0 @@ -/* - Copyright (C) 2012 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 <algorithm> -#include <cassert> -#include <cstdlib> -#include <random> -#include <vector> - -#include "db/array.hpp" -#include "logger.hpp" -#include "time.hpp" - -void test_array_1() { - enum { VECTOR_SIZE = 1 << 24 }; - - grnxx::io::File::unlink_if_exists("temp.grn"); - grnxx::io::File::unlink_if_exists("temp_000.grn"); - grnxx::io::File::unlink_if_exists("temp_E000.grn"); - - std::mt19937 random; - std::vector<std::uint32_t> vector(VECTOR_SIZE); - for (std::size_t i = 0; i < vector.size(); ++i) { - vector[i] = random(); - } - - grnxx::io::Pool pool(grnxx::io::POOL_CREATE, "temp.grn"); - - grnxx::db::Array<std::uint32_t> array; - array.create(&pool, VECTOR_SIZE); - - const std::uint32_t block_id = array.block_id(); - - GRNXX_NOTICE() << "array = " << array; - - assert(array.size() == VECTOR_SIZE); - - for (std::uint64_t i = 0; i < VECTOR_SIZE; ++i) { - array[i] = vector[i]; - } - - array.close(); - array.open(&pool, block_id); - - for (std::uint64_t i = 0; i < VECTOR_SIZE; ++i) { - assert(array[i] == vector[i]); - } - - array.close(); - - grnxx::db::Array<std::uint32_t>::unlink(&pool, block_id); - assert(pool.get_block_info(block_id)->status() == - grnxx::io::BLOCK_FROZEN); - - grnxx::io::File::unlink_if_exists("temp.grn"); - grnxx::io::File::unlink_if_exists("temp_000.grn"); - grnxx::io::File::unlink_if_exists("temp_E000.grn"); -} - -void test_array_2() { - enum { VECTOR_SIZE = 1 << 24 }; - - grnxx::io::Pool pool(grnxx::io::POOL_TEMPORARY, "temp.grn"); - - grnxx::db::Array<std::uint8_t[3]> array; - array.create(&pool, VECTOR_SIZE); - - GRNXX_NOTICE() << "array = " << array; - - assert(array.size() == VECTOR_SIZE); - - for (std::uint64_t i = 0; i < VECTOR_SIZE; ++i) { - array[i][0] = 'X'; - array[i][1] = 'Y'; - array[i][2] = 'Z'; - } - - for (std::uint64_t i = 0; i < VECTOR_SIZE; ++i) { - assert(array[i][0] == 'X'); - assert(array[i][1] == 'Y'); - assert(array[i][2] == 'Z'); - } - - array.close(); -} - -int main() { - grnxx::Logger::set_flags(grnxx::LOGGER_WITH_ALL | - grnxx::LOGGER_ENABLE_COUT); - grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER); - - test_array_1(); - test_array_2(); - - return 0; -} -------------- next part -------------- HTML����������������������������...ダウンロード