susumu.yata
null+****@clear*****
Wed Feb 20 14:19:35 JST 2013
susumu.yata 2013-02-20 14:19:35 +0900 (Wed, 20 Feb 2013) New Revision: 494701106c951a16cdac2586d27f0c1199f9ce43 https://github.com/groonga/grnxx/commit/494701106c951a16cdac2586d27f0c1199f9ce43 Log: Implement open() of DoubleArray family. Modified files: lib/map/da/basic_trie.cpp lib/map/da/basic_trie.hpp lib/map/da/large_trie.cpp lib/map/da/large_trie.hpp lib/map/da/trie.cpp lib/map/da/trie.hpp Modified: lib/map/da/basic_trie.cpp (+2 -1) =================================================================== --- lib/map/da/basic_trie.cpp 2013-02-20 14:04:59 +0900 (0a4d6ec) +++ lib/map/da/basic_trie.cpp 2013-02-20 14:19:35 +0900 (74f4e91) @@ -10,7 +10,8 @@ namespace da { namespace basic { Header::Header() - : nodes_block_id(io::BLOCK_INVALID_ID), + : type(TRIE_BASIC), + nodes_block_id(io::BLOCK_INVALID_ID), chunks_block_id(io::BLOCK_INVALID_ID), entries_block_id(io::BLOCK_INVALID_ID), keys_block_id(io::BLOCK_INVALID_ID), Modified: lib/map/da/basic_trie.hpp (+1 -0) =================================================================== --- lib/map/da/basic_trie.hpp 2013-02-20 14:04:59 +0900 (7122baa) +++ lib/map/da/basic_trie.hpp 2013-02-20 14:19:35 +0900 (ce826c5) @@ -87,6 +87,7 @@ constexpr uint32_t MAX_CHUNK_LEVEL = 5; constexpr uint32_t INVALID_LEADER = std::numeric_limits<uint32_t>::max(); struct Header { + TrieType type; uint32_t nodes_block_id; uint32_t chunks_block_id; uint32_t entries_block_id; Modified: lib/map/da/large_trie.cpp (+2 -1) =================================================================== --- lib/map/da/large_trie.cpp 2013-02-20 14:04:59 +0900 (2451cf5) +++ lib/map/da/large_trie.cpp 2013-02-20 14:19:35 +0900 (bcca758) @@ -9,7 +9,8 @@ namespace da { namespace large { Header::Header() - : nodes_block_id(io::BLOCK_INVALID_ID), + : type(TRIE_LARGE), + nodes_block_id(io::BLOCK_INVALID_ID), siblings_block_id(io::BLOCK_INVALID_ID), chunks_block_id(io::BLOCK_INVALID_ID), entries_block_id(io::BLOCK_INVALID_ID), Modified: lib/map/da/large_trie.hpp (+1 -0) =================================================================== --- lib/map/da/large_trie.hpp 2013-02-20 14:04:59 +0900 (321a44d) +++ lib/map/da/large_trie.hpp 2013-02-20 14:19:35 +0900 (4f45878) @@ -70,6 +70,7 @@ constexpr uint64_t MAX_CHUNK_LEVEL = 5; constexpr uint64_t INVALID_LEADER = std::numeric_limits<uint64_t>::max(); struct Header { + TrieType type; uint32_t nodes_block_id; uint32_t siblings_block_id; uint32_t chunks_block_id; Modified: lib/map/da/trie.cpp (+43 -2) =================================================================== --- lib/map/da/trie.cpp 2013-02-20 14:04:59 +0900 (58dc441) +++ lib/map/da/trie.cpp 2013-02-20 14:19:35 +0900 (ad78e9f) @@ -1,5 +1,8 @@ #include "trie.hpp" #include "basic_trie.hpp" +#include "large_trie.hpp" + +#include "../../logger.hpp" namespace grnxx { namespace map { @@ -18,11 +21,49 @@ Trie *Trie::create(const TrieOptions &options, io::Pool pool) { } Trie *Trie::open(io::Pool pool, uint32_t block_id) { - return basic::Trie::open(pool, block_id); + // Check the type and call the appropriate function. + auto block_info = pool.get_block_info(block_id); + auto block_address = pool.get_block_address(*block_info); + const TrieType type = *static_cast<const TrieType *>(block_address); + switch (type) { + case TRIE_UNKNOWN: { + break; + } + case TRIE_BASIC: { + return basic::Trie::open(pool, block_id); + } + case TRIE_LARGE: { + return large::Trie::open(pool, block_id); + } + } + + GRNXX_ERROR() << "unknown trie type"; + GRNXX_THROW(); + +// return basic::Trie::open(pool, block_id); } void Trie::unlink(io::Pool pool, uint32_t block_id) { - return basic::Trie::unlink(pool, block_id); + // Check the type and call the appropriate function. + auto block_info = pool.get_block_info(block_id); + auto block_address = pool.get_block_address(*block_info); + const TrieType type = *static_cast<const TrieType *>(block_address); + switch (type) { + case TRIE_UNKNOWN: { + break; + } + case TRIE_BASIC: { + return basic::Trie::unlink(pool, block_id); + } + case TRIE_LARGE: { + return large::Trie::unlink(pool, block_id); + } + } + + GRNXX_ERROR() << "unknown trie type"; + GRNXX_THROW(); + +// return basic::Trie::unlink(pool, block_id); } } // namespace da Modified: lib/map/da/trie.hpp (+6 -0) =================================================================== --- lib/map/da/trie.hpp 2013-02-20 14:04:59 +0900 (9798805) +++ lib/map/da/trie.hpp 2013-02-20 14:19:35 +0900 (56950d8) @@ -25,6 +25,12 @@ namespace grnxx { namespace map { namespace da { +enum TrieType : int32_t { + TRIE_UNKNOWN = 0, + TRIE_BASIC = 1, + TRIE_LARGE = 2 +}; + class TrieException : Exception { public: TrieException() noexcept {} -------------- next part -------------- HTML����������������������������...Download