susumu.yata
null+****@clear*****
Wed Feb 13 09:15:25 JST 2013
susumu.yata 2013-02-13 09:15:25 +0900 (Wed, 13 Feb 2013) New Revision: 6461c32c4b1dd955f4cb6d2af44e626d53141f36 https://github.com/groonga/grnxx/commit/6461c32c4b1dd955f4cb6d2af44e626d53141f36 Log: Add a prototype interface, grnxx::Map. Added files: lib/map.cpp lib/map.hpp Modified files: lib/Makefile.am Modified: lib/Makefile.am (+2 -0) =================================================================== --- lib/Makefile.am 2013-02-12 22:44:52 +0900 (24c43ef) +++ lib/Makefile.am 2013-02-13 09:15:25 +0900 (cfca9cc) @@ -15,6 +15,7 @@ libgrnxx_la_SOURCES = \ error.cpp \ grnxx.cpp \ logger.cpp \ + map.cpp \ mutex.cpp \ os.cpp \ recycler.cpp \ @@ -36,6 +37,7 @@ libgrnxx_include_HEADERS = \ intrinsic.hpp \ lock.hpp \ logger.hpp \ + map.hpp \ mutex.hpp \ os.hpp \ recycler.hpp \ Added: lib/map.cpp (+74 -0) 100644 =================================================================== --- /dev/null +++ lib/map.cpp 2013-02-13 09:15:25 +0900 (37c4bad) @@ -0,0 +1,74 @@ +/* + 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 "map.hpp" + +namespace grnxx { + +MapOptions::MapOptions() : type(MAP_UNKNOWN) {} + +MapHeader::MapHeader() : type(MAP_UNKNOWN) {} + +Map::Map() {} +Map::~Map() {} + +Map *Map::create(const MapOptions &options, io::Pool pool) { + switch (options.type) { + case MAP_DOUBLE_ARRAY: { +// return map::DoubleArray::create(options, pool); + break; + } + // TODO: Other map types will be supported in future. +// case ???: { +// return map::???::create(options, pool); +// } + default: { + // TODO: Invalid type! + break; + } + } + return nullptr; +} + +Map *Map::open(io::Pool pool, uint32_t block_id) { + // Get the address to the header. + auto block_info = pool.get_block_info(block_id); + auto block_address = pool.get_block_address(*block_info); + auto header = static_cast<MapHeader *>(block_address); + + // Check the type. + MapType type = header->type; + + // Call the appropriate function. + switch (type) { + case MAP_DOUBLE_ARRAY: { +// return map::DoubleArray::open(pool, block_id); + break; + } + // TODO: Other map types will be supported in future. + default: { + // TODO: Invalid type! + break; + } + } + + // Return the result. + + return nullptr; +} + +} // namespace grnxx Added: lib/map.hpp (+70 -0) 100644 =================================================================== --- /dev/null +++ lib/map.hpp 2013-02-13 09:15:25 +0900 (3370bb1) @@ -0,0 +1,70 @@ +/* + 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_HPP +#define GRNXX_MAP_HPP + +// Tentative version. + +#include "io/pool.hpp" +#include "slice.hpp" + +namespace grnxx { + +enum MapType : int32_t { + MAP_UNKNOWN = 0, + MAP_DOUBLE_ARRAY = 1 +}; + +struct MapOptions { + MapType type; + + MapOptions(); +}; + +struct MapHeader { + MapType type; + + MapHeader(); +}; + +class Map { + public: + Map(); + virtual ~Map(); + + static Map *create(const MapOptions &options, io::Pool pool); + static Map *open(io::Pool pool, uint32_t block_id); + + virtual uint32_t block_id() const = 0; + + virtual bool search(int64_t id, Slice *key) = 0; + virtual bool search(const Slice &key, int64_t *id = nullptr) = 0; + + virtual bool insert(const Slice &key, int64_t *id = nullptr) = 0; + + virtual bool remove(int64_t id) = 0; + virtual bool remove(const Slice &key) = 0; + + virtual bool update(int64_t id, const Slice &dest) = 0; + virtual bool update(const Slice &src, const Slice &dest, + int64_t *id = nullptr) = 0; +}; + +} // namespace grnxx + +#endif // GRNXX_MAP_HPP -------------- next part -------------- HTML����������������������������...Download