susumu.yata
null+****@clear*****
Thu May 16 14:59:23 JST 2013
susumu.yata 2013-05-16 14:59:23 +0900 (Thu, 16 May 2013) New Revision: d352c961e13d87cf151c0bae9b4865e96631f426 https://github.com/groonga/grnxx/commit/d352c961e13d87cf151c0bae9b4865e96631f426 Message: Rename grnxx::map::Array to grnxx::map::ArrayMap. Added files: lib/grnxx/map/array_map.hpp Removed files: lib/grnxx/map/array.cpp Modified files: lib/grnxx/map/Makefile.am Renamed files: lib/grnxx/map/array_map.cpp (from lib/grnxx/map/array.hpp) Modified: lib/grnxx/map/Makefile.am (+2 -2) =================================================================== --- lib/grnxx/map/Makefile.am 2013-05-16 13:22:41 +0900 (ec46cf8) +++ lib/grnxx/map/Makefile.am 2013-05-16 14:59:23 +0900 (77fb4f7) @@ -3,13 +3,13 @@ noinst_LTLIBRARIES = libgrnxx_map.la libgrnxx_map_la_LDFLAGS = @AM_LTLDFLAGS@ libgrnxx_map_la_SOURCES = \ - array.cpp \ + array_map.cpp \ cursor.cpp \ scanner.cpp libgrnxx_map_includedir = ${includedir}/grnxx/map libgrnxx_map_include_HEADERS = \ - array.hpp \ + array_map.hpp \ cursor.hpp \ header.hpp \ helper.hpp \ Deleted: lib/grnxx/map/array.cpp (+0 -24) 100644 =================================================================== --- lib/grnxx/map/array.cpp 2013-05-16 13:22:41 +0900 (5c60f41) +++ /dev/null @@ -1,24 +0,0 @@ -/* - 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 "grnxx/map/array.hpp" - -namespace grnxx { -namespace map { - -} // namespace map -} // namespace grnxx Renamed: lib/grnxx/map/array_map.cpp (+14 -5) 70% =================================================================== --- lib/grnxx/map/array.hpp 2013-05-16 13:22:41 +0900 (0b9011b) +++ lib/grnxx/map/array_map.cpp 2013-05-16 14:59:23 +0900 (c8c6ea3) @@ -15,15 +15,24 @@ 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_ARRAY_HPP -#define GRNXX_MAP_ARRAY_HPP +#include "grnxx/map/array_map.hpp" -#include "grnxx/features.hpp" +#include <cmath> +#include <string> + +#include "grnxx/geo_point.hpp" +#include "grnxx/storage.hpp" namespace grnxx { namespace map { +ArrayMapHeader::ArrayMapHeader() + : map_type(MAP_ARRAY), + bits_storage_node_id(STORAGE_INVALID_NODE_ID), + keys_storage_node_id(STORAGE_INVALID_NODE_ID), + max_key_id(-1), + next_key_id(0), + num_keys(0) {} + } // namespace map } // namespace grnxx - -#endif // GRNXX_MAP_ARRAY_HPP Added: lib/grnxx/map/array_map.hpp (+99 -0) 100644 =================================================================== --- /dev/null +++ lib/grnxx/map/array_map.hpp 2013-05-16 14:59:23 +0900 (23fb874) @@ -0,0 +1,99 @@ +/* + 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_ARRAY_MAP_HPP +#define GRNXX_MAP_ARRAY_MAP_HPP + +#include "grnxx/map.hpp" +#include "grnxx/array.hpp" + +namespace grnxx { +namespace map { + +class Storage; + +struct ArrayMapHeader { + MapType map_type; + uint32_t bits_storage_node_id; + uint32_t keys_storage_node_id; + int64_t max_key_id; + int64_t next_key_id; + uint64_t num_keys; + + ArrayMapHeader(); +}; + +template <typename T> +class ArrayMap : public Map<T> { + public: + using Key = typename Map<T>::Key; + using KeyArg = typename Map<T>::KeyArg; + using Cursor = typename Map<T>::Cursor; + + ArrayMap(); + ~ArrayMap(); + + static ArrayMap *create(Storage *storage, uint32_t storage_node_id, + const MapOptions &options = MapOptions()); + static ArrayMap *open(Storage *storage, uint32_t storage_node_id); + + static bool unlink(Storage *storage, uint32_t storage_node_id); + + uint32_t storage_node_id() const; + MapType type() const; + + int64_t max_key_id() const; + int64_t next_key_id() const; + uint64_t num_keys() const; + + bool get(int64_t key_id, Key *key = nullptr); +// bool get_next(int64_t key_id, int64_t *next_key_id = nullptr, +// Key *next_key = nullptr); +// bool unset(int64_t key_id); +// bool reset(int64_t key_id, KeyArg dest_key); + + bool find(KeyArg key, int64_t *key_id = nullptr); + bool add(KeyArg key, int64_t *key_id = nullptr); + bool remove(KeyArg key); + bool replace(KeyArg src_key, KeyArg dest_key, + int64_t *key_id = nullptr); + + bool truncate(); + + private: + Storage *storage_; + uint32_t storage_node_id_; + ArrayMapHeader *header_; + Array<uint32_t> bits_; + Array<T> keys_; + + bool get_bit(int64_t key_id) { + return bits_[key_id / 32] & (1U << (key_id % 32)); + } + void set_bit(int64_t key_id, bool bit) { + if (bit) { + bits_[key_id / 32] |= 1U << (key_id % 32); + } else { + bits_[key_id / 32] &= ~(1U << (key_id % 32)); + } + } +}; + +} // namespace map +} // namespace grnxx + +#endif // GRNXX_MAP_ARRAY_MAP_HPP -------------- next part -------------- HTML����������������������������... ダウンロード