[Groonga-commit] groonga/grnxx at 98b32c1 [master] Remove specialization for bit array (grnxx::Array).

Back to archive index

susumu.yata null+****@clear*****
Tue May 28 17:57:10 JST 2013


susumu.yata	2013-05-28 17:57:10 +0900 (Tue, 28 May 2013)

  New Revision: 98b32c1740b126a0e61f9f266e6d5688970fc7a1
  https://github.com/groonga/grnxx/commit/98b32c1740b126a0e61f9f266e6d5688970fc7a1

  Message:
    Remove specialization for bit array (grnxx::Array).

  Modified files:
    lib/grnxx/array.hpp
    test/test_array.cpp

  Modified: lib/grnxx/array.hpp (+0 -130)
===================================================================
--- lib/grnxx/array.hpp    2013-05-28 17:54:27 +0900 (c84f420)
+++ lib/grnxx/array.hpp    2013-05-28 17:57:10 +0900 (477b8fb)
@@ -463,136 +463,6 @@ class Array {
   }
 };
 
-// Bit array.
-template <uint64_t PAGE_SIZE_IN_BITS,
-          uint64_t TABLE_SIZE,
-          uint64_t SECONDARY_TABLE_SIZE>
-class Array<bool, PAGE_SIZE_IN_BITS, TABLE_SIZE, SECONDARY_TABLE_SIZE> {
- 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;
-
-  Array() : impl_() {}
-  ~Array() {}
-
-  // 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 value.
-  bool create(Storage *storage, uint32_t storage_node_id,
-              ValueArg default_value) {
-    return impl_.create(storage, storage_node_id,
-                        default_value ? ~Unit(0) : Unit(0));
-  }
-
-  // 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 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.
-  // This function throws an exception on failure.
-  Value operator[](uint64_t value_id) {
-    return (impl_[value_id / UNIT_SIZE] &
-            (Unit(1) << (value_id % UNIT_SIZE))) != 0;
-  }
-
-  // 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_value(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:
-  ArrayImpl impl_;
-};
-
 }  // namespace grnxx
 
 #endif  // GRNXX_ARRAY_HPP

  Modified: test/test_array.cpp (+3 -63)
===================================================================
--- test/test_array.cpp    2013-05-28 17:54:27 +0900 (b856314)
+++ test/test_array.cpp    2013-05-28 17:57:10 +0900 (9d47932)
@@ -79,65 +79,6 @@ void test_array() {
   }
 }
 
-void test_bit_array() {
-  constexpr std::uint64_t PAGE_SIZE            = 64;
-  constexpr std::uint64_t TABLE_SIZE           = 32;
-  constexpr std::uint64_t SECONDARY_TABLE_SIZE = 16;
-
-  GRNXX_NOTICE() << __PRETTY_FUNCTION__;
-
-  // Create an anonymous Storage.
-  std::unique_ptr<grnxx::Storage> storage(grnxx::Storage::create(nullptr));
-  grnxx::Array<bool, PAGE_SIZE, TABLE_SIZE, SECONDARY_TABLE_SIZE> array;
-  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 value = (i % 3) != 0;
-    assert(array.set(i, value));
-  }
-  for (std::uint64_t i = 0; i < array.size(); ++i) {
-    const bool expected_value = (i % 3) != 0;
-    bool value;
-    assert(array.get(i, &value));
-    assert(value == expected_value);
-  }
-  for (std::uint64_t i = 0; i < array.size(); ++i) {
-    const bool expected_value = (i % 3) != 0;
-    assert(array[i] == expected_value);
-  }
-  for (std::uint64_t i = 0; i < (array.size() / array.unit_size()); ++i) {
-    assert(array.get_unit(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_value = (i % 3) != 0;
-    bool value;
-    assert(array.get(i, &value));
-    assert(value == expected_value);
-  }
-
-  // Create an Array with default value.
-  assert(array.create(storage.get(), grnxx::STORAGE_ROOT_NODE_ID, true));
-  assert(array);
-  for (std::uint64_t i = 0; i < array.size(); ++i) {
-    assert(array[i]);
-  }
-}
-
 }  // namesapce
 
 int main() {
@@ -145,10 +86,9 @@ int main() {
                            grnxx::LOGGER_ENABLE_COUT);
   grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER);
 
-  test_array<64,  1,  1>();
-  test_array<64, 32,  1>();
-  test_array<64, 32, 16>();
-  test_bit_array();
+  test_array<256,  1,  1>();
+  test_array<256, 64,  1>();
+  test_array<256, 64, 16>();
 
   return 0;
 }
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index