susumu.yata
null+****@clear*****
Wed May 29 17:36:06 JST 2013
susumu.yata 2013-05-29 17:36:06 +0900 (Wed, 29 May 2013) New Revision: 206aa5abd8f87c72e509254f961467cb7dffd8db https://github.com/groonga/grnxx/commit/206aa5abd8f87c72e509254f961467cb7dffd8db Message: Remove grnxx::BitArray. Removed files: lib/grnxx/bit_array.hpp test/test_bit_array.cpp Modified files: .gitignore lib/grnxx/Makefile.am test/Makefile.am Modified: .gitignore (+0 -1) =================================================================== --- .gitignore 2013-05-29 14:39:18 +0900 (4bdac9e) +++ .gitignore 2013-05-29 17:36:06 +0900 (2b0f2f4) @@ -31,7 +31,6 @@ test/test_alpha_double_array test/test_alpha_map test/test_array test/test_backtrace -test/test_bit_array test/test_bytes test/test_charset test/test_db_blob_vector Modified: lib/grnxx/Makefile.am (+0 -1) =================================================================== --- lib/grnxx/Makefile.am 2013-05-29 14:39:18 +0900 (97e8ef8) +++ lib/grnxx/Makefile.am 2013-05-29 17:36:06 +0900 (724b88e) @@ -50,7 +50,6 @@ libgrnxx_includedir = ${includedir}/grnxx libgrnxx_include_HEADERS = \ array.hpp \ array_impl.hpp \ - bit_array.hpp \ backtrace.hpp \ basic.hpp \ broken_down_time.hpp \ Deleted: lib/grnxx/bit_array.hpp (+0 -161) 100644 =================================================================== --- lib/grnxx/bit_array.hpp 2013-05-29 14:39:18 +0900 (45573c2) +++ /dev/null @@ -1,161 +0,0 @@ -/* - Copyright (C) 2012-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_BIT_ARRAY_HPP -#define GRNXX_BIT_ARRAY_HPP - -#include "grnxx/features.hpp" - -#include <memory> - -#include "grnxx/array.hpp" -#include "grnxx/traits.hpp" -#include "grnxx/types.hpp" - -namespace grnxx { - -class Storage; - -// Bit array. -template <uint64_t PAGE_SIZE_IN_BITS = ARRAY_DEFAULT_PAGE_SIZE, - uint64_t TABLE_SIZE = ARRAY_DEFAULT_TABLE_SIZE, - uint64_t SECONDARY_TABLE_SIZE = ARRAY_DEFAULT_SECONDARY_TABLE_SIZE> -class BitArray { - public: - // Internal type to store bits. - using Unit = uint64_t; - - private: - static constexpr uint64_t UNIT_SIZE = sizeof(Unit) * 8; - static constexpr uint64_t PAGE_SIZE = PAGE_SIZE_IN_BITS / UNIT_SIZE; - - static_assert((PAGE_SIZE_IN_BITS % UNIT_SIZE) == 0, - "(PAGE_SIZE_IN_BITS % UNIT_SIZE) != 0"); - using ArrayImpl = Array<Unit, PAGE_SIZE, TABLE_SIZE, SECONDARY_TABLE_SIZE>; - - public: - using Value = typename Traits<bool>::Type; - using ValueArg = typename Traits<bool>::ArgumentType; - - BitArray() : impl_() {} - ~BitArray() {} - - // 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) { - impl_.reset(ArrayImpl::create(storage, storage_node_id)); - return static_cast<bool>(impl_); - } - - // Create an array with the default value. - bool create(Storage *storage, uint32_t storage_node_id, - ValueArg default_value) { - impl_.reset(ArrayImpl::create(storage, storage_node_id, - default_value ? ~Unit(0) : Unit(0))); - return static_cast<bool>(impl_); - } - - // Open an array. - bool open(Storage *storage, uint32_t storage_node_id) { - impl_.reset(ArrayImpl::open(storage, storage_node_id)); - return static_cast<bool>(impl_); - } - - // Unlink an array. - static bool unlink(Storage *storage, uint32_t storage_node_id) { - return ArrayImpl::unlink(storage, storage_node_id); - } - - // Return the number of values in each unit. - static constexpr uint64_t unit_size() { - return UNIT_SIZE; - } - // Return the number of values in each page. - static constexpr uint64_t page_size() { - return PAGE_SIZE_IN_BITS; - } - // Return the number of pages in each table. - static constexpr uint64_t table_size() { - return TABLE_SIZE; - } - // Return the number of tables in each secondary table. - static constexpr uint64_t secondary_table_size() { - return SECONDARY_TABLE_SIZE; - } - // Return the number of values in Array. - static constexpr uint64_t size() { - return page_size() * table_size() * secondary_table_size(); - } - - // Return the storage node ID. - uint32_t storage_node_id() const { - return impl_->storage_node_id(); - } - - // Get a value and return true on success. - // The value is assigned to "*value" iff "value" != nullptr. - bool get(uint64_t value_id, Value *value) { - const uint64_t unit_id = value_id / UNIT_SIZE; - const Unit * const page = get_page(unit_id / PAGE_SIZE); - if (!page) { - return false; - } - if (value) { - *value = (page[unit_id % PAGE_SIZE] & - (Unit(1) << (value_id % UNIT_SIZE))) != 0; - } - return true; - } - - // Set a value 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 value_id, ValueArg value) { - const uint64_t unit_id = value_id / UNIT_SIZE; - Unit * const page = get_page(unit_id / PAGE_SIZE); - if (!page) { - return false; - } - if (value) { - page[unit_id % PAGE_SIZE] |= Unit(1) << (value_id % UNIT_SIZE); - } else { - page[unit_id % PAGE_SIZE] &= ~(Unit(1) << (value_id % UNIT_SIZE)); - } - return true; - } - - // Get a unit and return its address on success. - Unit *get_unit(uint64_t unit_id) { - return impl_->get_pointer(unit_id); - } - - // Get a page and return its starting address on success. - Unit *get_page(uint64_t page_id) { - return impl_->get_page(page_id); - } - - private: - std::unique_ptr<ArrayImpl> impl_; -}; - -} // namespace grnxx - -#endif // GRNXX_BIT_ARRAY_HPP Modified: test/Makefile.am (+0 -4) =================================================================== --- test/Makefile.am 2013-05-29 14:39:18 +0900 (325145e) +++ test/Makefile.am 2013-05-29 17:36:06 +0900 (85ac15a) @@ -5,7 +5,6 @@ TESTS = \ test_alpha_map \ test_array \ test_backtrace \ - test_bit_array \ test_bytes \ test_charset \ test_db_blob_vector \ @@ -47,9 +46,6 @@ test_array_LDADD = ../lib/grnxx/libgrnxx.la test_backtrace_SOURCES = test_backtrace.cpp test_backtrace_LDADD = ../lib/grnxx/libgrnxx.la -test_bit_array_SOURCES = test_bit_array.cpp -test_bit_array_LDADD = ../lib/grnxx/libgrnxx.la - test_bytes_SOURCES = test_bytes.cpp test_bytes_LDADD = ../lib/grnxx/libgrnxx.la Deleted: test/test_bit_array.cpp (+0 -117) 100644 =================================================================== --- test/test_bit_array.cpp 2013-05-29 14:39:18 +0900 (e7689f1) +++ /dev/null @@ -1,117 +0,0 @@ -/* - Copyright (C) 2012-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 <cassert> -#include <memory> -#include <random> -#include <vector> - -#include "grnxx/bit_array.hpp" -#include "grnxx/logger.hpp" -#include "grnxx/storage.hpp" - -namespace { - -std::mt19937_64 mersenne_twister; - -template <std::uint64_t PAGE_SIZE, - std::uint64_t TABLE_SIZE, - std::uint64_t SECONDARY_TABLE_SIZE> -void test_bit_array() { - GRNXX_NOTICE() << __PRETTY_FUNCTION__; - - using BitArray = grnxx::BitArray<PAGE_SIZE, TABLE_SIZE, SECONDARY_TABLE_SIZE>; - using Unit = typename BitArray::Unit; - - // Generate an array of random units. - std::vector<Unit> units(BitArray::size() / BitArray::unit_size()); - for (std::size_t i = 0; i < units.size(); ++i) { - units[i] = mersenne_twister(); - } - - // Create an anonymous Storage. - std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr)); - grnxx::BitArray<PAGE_SIZE, TABLE_SIZE, SECONDARY_TABLE_SIZE> array; - std::uint32_t storage_node_id; - - // Create an Array and test its member functions. - assert(array.create(storage.get(), grnxx::STORAGE_ROOT_NODE_ID)); - assert(array); - assert(array.page_size() == PAGE_SIZE); - assert(array.table_size() == TABLE_SIZE); - assert(array.secondary_table_size() == SECONDARY_TABLE_SIZE); - assert(array.size() == (PAGE_SIZE * TABLE_SIZE * SECONDARY_TABLE_SIZE)); - storage_node_id = array.storage_node_id(); - - for (std::uint64_t i = 0; i < array.size(); ++i) { - const bool bit = (units[i / 64] >> (i % 64)) & 1; - assert(array.set(i, bit)); - } - for (std::uint64_t i = 0; i < array.size(); ++i) { - const bool expected_bit = (units[i / 64] >> (i % 64)) & 1; - bool stored_bit; - assert(array.get(i, &stored_bit)); - assert(stored_bit == expected_bit); - } - for (std::uint64_t i = 0; i < (array.size() / array.unit_size()); ++i) { - const Unit * const unit = array.get_unit(i); - assert(unit); - assert(*unit == units[i]); - } - for (std::uint64_t i = 0; i < (array.size() / array.page_size()); ++i) { - assert(array.get_page(i)); - } - - // Open the Array. - assert(array.open(storage.get(), storage_node_id)); - for (std::uint64_t i = 0; i < array.size(); ++i) { - const bool expected_bit = (units[i / 64] >> (i % 64)) & 1; - bool stored_bit; - assert(array.get(i, &stored_bit)); - assert(stored_bit == expected_bit); - } - - // Create an Array with the default bit. - assert(array.create(storage.get(), grnxx::STORAGE_ROOT_NODE_ID, false)); - assert(array); - for (std::uint64_t i = 0; i < array.size(); ++i) { - bool bit; - assert(array.get(i, &bit)); - assert(!bit); - } - assert(array.create(storage.get(), grnxx::STORAGE_ROOT_NODE_ID, true)); - assert(array); - for (std::uint64_t i = 0; i < array.size(); ++i) { - bool bit; - assert(array.get(i, &bit)); - assert(bit); - } -} - -} // namesapce - -int main() { - grnxx::Logger::set_flags(grnxx::LOGGER_WITH_ALL | - grnxx::LOGGER_ENABLE_COUT); - grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER); - - test_bit_array<256, 1, 1>(); - test_bit_array<256, 64, 1>(); - test_bit_array<256, 64, 16>(); - - return 0; -} -------------- next part -------------- HTML����������������������������... ダウンロード