Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add skeletons of Patricia and DoubleArray.
- Loading branch information
Showing
7 changed files
with
490 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| /* | ||
| 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 "grnxx/map/double_array.hpp" | ||
|
|
||
| #include <new> | ||
|
|
||
| #include "grnxx/bytes.hpp" | ||
| #include "grnxx/geo_point.hpp" | ||
| #include "grnxx/logger.hpp" | ||
| #include "grnxx/map/helper.hpp" | ||
| #include "grnxx/storage.hpp" | ||
|
|
||
| namespace grnxx { | ||
| namespace map { | ||
|
|
||
| struct DoubleArrayHeader { | ||
| // TODO | ||
| int64_t max_key_id; | ||
| uint64_t num_keys; | ||
|
|
||
| DoubleArrayHeader(); | ||
| }; | ||
|
|
||
| DoubleArrayHeader::DoubleArrayHeader() | ||
| : max_key_id(MAP_MIN_KEY_ID - 1), | ||
| num_keys(0) {} | ||
|
|
||
| template <typename T> | ||
| Map<T> *DoubleArray<T>::create(Storage *, uint32_t, const MapOptions &) { | ||
| GRNXX_ERROR() << "invalid combination"; | ||
| return nullptr; | ||
| } | ||
|
|
||
| template <typename T> | ||
| Map<T> *DoubleArray<T>::open(Storage *, uint32_t) { | ||
| GRNXX_ERROR() << "invalid combination"; | ||
| return nullptr; | ||
| } | ||
|
|
||
| template class DoubleArray<int8_t>; | ||
| template class DoubleArray<uint8_t>; | ||
| template class DoubleArray<int16_t>; | ||
| template class DoubleArray<uint16_t>; | ||
| template class DoubleArray<int32_t>; | ||
| template class DoubleArray<uint32_t>; | ||
| template class DoubleArray<int64_t>; | ||
| template class DoubleArray<uint64_t>; | ||
| template class DoubleArray<double>; | ||
| template class DoubleArray<GeoPoint>; | ||
|
|
||
| DoubleArray<Bytes>::DoubleArray() | ||
| : storage_(nullptr), | ||
| storage_node_id_(STORAGE_INVALID_NODE_ID), | ||
| header_(nullptr) {} | ||
|
|
||
| DoubleArray<Bytes>::~DoubleArray() {} | ||
|
|
||
| DoubleArray<Bytes> *DoubleArray<Bytes>::create(Storage *storage, | ||
| uint32_t storage_node_id, | ||
| const MapOptions &options) { | ||
| std::unique_ptr<DoubleArray> map(new (std::nothrow) DoubleArray); | ||
| if (!map) { | ||
| GRNXX_ERROR() << "new grnxx::map::DoubleArray failed"; | ||
| return nullptr; | ||
| } | ||
| if (!map->create_map(storage, storage_node_id, options)) { | ||
| return nullptr; | ||
| } | ||
| return map.release(); | ||
| } | ||
|
|
||
| DoubleArray<Bytes> *DoubleArray<Bytes>::open(Storage *storage, | ||
| uint32_t storage_node_id) { | ||
| std::unique_ptr<DoubleArray> map(new (std::nothrow) DoubleArray); | ||
| if (!map) { | ||
| GRNXX_ERROR() << "new grnxx::map::DoubleArray failed"; | ||
| return nullptr; | ||
| } | ||
| if (!map->open_map(storage, storage_node_id)) { | ||
| return nullptr; | ||
| } | ||
| return map.release(); | ||
| } | ||
|
|
||
| uint32_t DoubleArray<Bytes>::storage_node_id() const { | ||
| return storage_node_id_; | ||
| } | ||
|
|
||
| MapType DoubleArray<Bytes>::type() const { | ||
| return MAP_DOUBLE_ARRAY; | ||
| } | ||
|
|
||
| int64_t DoubleArray<Bytes>::max_key_id() const { | ||
| return header_->max_key_id; | ||
| } | ||
|
|
||
| uint64_t DoubleArray<Bytes>::num_keys() const { | ||
| return header_->num_keys; | ||
| } | ||
|
|
||
| bool DoubleArray<Bytes>::create_map(Storage *storage, uint32_t storage_node_id, | ||
| const MapOptions &) { | ||
| storage_ = storage; | ||
| StorageNode storage_node = | ||
| storage->create_node(storage_node_id, sizeof(DoubleArrayHeader)); | ||
| if (!storage_node) { | ||
| return false; | ||
| } | ||
| storage_node_id_ = storage_node.id(); | ||
| header_ = static_cast<DoubleArrayHeader *>(storage_node.body()); | ||
| *header_ = DoubleArrayHeader(); | ||
| // TODO | ||
| return false; | ||
| } | ||
|
|
||
| bool DoubleArray<Bytes>::open_map(Storage *storage, uint32_t storage_node_id) { | ||
| storage_ = storage; | ||
| StorageNode storage_node = storage->open_node(storage_node_id); | ||
| if (!storage_node) { | ||
| return false; | ||
| } | ||
| if (storage_node.size() < sizeof(DoubleArrayHeader)) { | ||
| GRNXX_ERROR() << "invalid format: size = " << storage_node.size() | ||
| << ", header_size = " << sizeof(DoubleArrayHeader); | ||
| return false; | ||
| } | ||
| storage_node_id_ = storage_node_id; | ||
| header_ = static_cast<DoubleArrayHeader *>(storage_node.body()); | ||
| // TODO | ||
| return false; | ||
| } | ||
|
|
||
| } // namespace map | ||
| } // namespace grnxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| 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_MAP_DOUBLE_ARRAY_HPP | ||
| #define GRNXX_MAP_DOUBLE_ARRAY_HPP | ||
|
|
||
| #include "grnxx/features.hpp" | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "grnxx/bytes.hpp" | ||
| #include "grnxx/map.hpp" | ||
| #include "grnxx/map_cursor.hpp" | ||
| #include "grnxx/map_cursor_query.hpp" | ||
| #include "grnxx/types.hpp" | ||
|
|
||
| namespace grnxx { | ||
| namespace map { | ||
|
|
||
| struct DoubleArrayHeader; | ||
|
|
||
| template <typename T> | ||
| class DoubleArray { | ||
| public: | ||
| static Map<T> *create(Storage *storage, uint32_t storage_node_id, | ||
| const MapOptions &options = MapOptions()); | ||
| static Map<T> *open(Storage *storage, uint32_t storage_node_id); | ||
| }; | ||
|
|
||
| template <> | ||
| class DoubleArray<Bytes> : public Map<Bytes> { | ||
| public: | ||
| using Key = typename Map<Bytes>::Key; | ||
| using KeyArg = typename Map<Bytes>::KeyArg; | ||
| using Cursor = typename Map<Bytes>::Cursor; | ||
|
|
||
| DoubleArray(); | ||
| ~DoubleArray(); | ||
|
|
||
| static DoubleArray *create(Storage *storage, uint32_t storage_node_id, | ||
| const MapOptions &options = MapOptions()); | ||
| static DoubleArray *open(Storage *storage, uint32_t storage_node_id); | ||
|
|
||
| uint32_t storage_node_id() const; | ||
| MapType type() const; | ||
|
|
||
| int64_t max_key_id() const; | ||
| uint64_t num_keys() const; | ||
|
|
||
| // TODO | ||
| // bool get(int64_t key_id, Key *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(); | ||
|
|
||
| // bool find_longest_prefix_match(KeyArg query, | ||
| // int64_t *key_id = nullptr, | ||
| // Key *key = nullptr); | ||
|
|
||
| // Cursor *create_cursor( | ||
| // MapCursorAllKeys<T> query, | ||
| // const MapCursorOptions &options = MapCursorOptions()); | ||
| // Cursor *create_cursor( | ||
| // const MapCursorKeyIDRange<T> &query, | ||
| // const MapCursorOptions &options = MapCursorOptions()); | ||
| // Cursor *create_cursor( | ||
| // const MapCursorKeyRange<T> &query, | ||
| // const MapCursorOptions &options = MapCursorOptions()); | ||
|
|
||
| private: | ||
| Storage *storage_; | ||
| uint32_t storage_node_id_; | ||
| DoubleArrayHeader *header_; | ||
|
|
||
| bool create_map(Storage *storage, uint32_t storage_node_id, | ||
| const MapOptions &options); | ||
| bool open_map(Storage *storage, uint32_t storage_node_id); | ||
| }; | ||
|
|
||
| } // namespace map | ||
| } // namespace grnxx | ||
|
|
||
| #endif // GRNXX_MAP_DOUBLE_ARRAY_HPP |
Oops, something went wrong.