susumu.yata
null+****@clear*****
Tue Apr 16 19:12:26 JST 2013
susumu.yata 2013-04-16 19:12:26 +0900 (Tue, 16 Apr 2013) New Revision: 7e5993aef6dea74e6febba6d8d30724b41454288 https://github.com/groonga/grnxx/commit/7e5993aef6dea74e6febba6d8d30724b41454288 Message: Add grnxx::alpha::map::DoubleArray::next_key_id/num_keys(). Modified files: lib/grnxx/alpha/map/double_array-slice.cpp lib/grnxx/alpha/map/double_array.cpp lib/grnxx/alpha/map/double_array.hpp test/test_alpha_map.cpp Modified: lib/grnxx/alpha/map/double_array-slice.cpp (+8 -0) =================================================================== --- lib/grnxx/alpha/map/double_array-slice.cpp 2013-04-16 19:07:45 +0900 (176cc83) +++ lib/grnxx/alpha/map/double_array-slice.cpp 2013-04-16 19:12:26 +0900 (23c8cc5) @@ -491,6 +491,14 @@ int64_t DoubleArray<Slice>::max_key_id() const { return header_->max_key_id; } +int64_t DoubleArray<Slice>::next_key_id() const { + return header_->next_key_id; +} + +uint64_t DoubleArray<Slice>::num_keys() const { + return header_->num_keys; +} + bool DoubleArray<Slice>::get(int64_t key_id, Slice *key) { if ((key_id < MIN_KEY_ID) || (key_id > header_->max_key_id)) { return false; Modified: lib/grnxx/alpha/map/double_array.cpp (+10 -0) =================================================================== --- lib/grnxx/alpha/map/double_array.cpp 2013-04-16 19:07:45 +0900 (dc086ca) +++ lib/grnxx/alpha/map/double_array.cpp 2013-04-16 19:12:26 +0900 (371bbba) @@ -529,6 +529,16 @@ int64_t DoubleArray<T>::max_key_id() const { } template <typename T> +int64_t DoubleArray<T>::next_key_id() const { + return header_->next_key_id; +} + +template <typename T> +uint64_t DoubleArray<T>::num_keys() const { + return header_->num_keys; +} + +template <typename T> bool DoubleArray<T>::get(int64_t key_id, T *key) { if ((key_id < MIN_KEY_ID) || (key_id > header_->max_key_id)) { return false; Modified: lib/grnxx/alpha/map/double_array.hpp (+4 -0) =================================================================== --- lib/grnxx/alpha/map/double_array.hpp 2013-04-16 19:07:45 +0900 (7f214d6) +++ lib/grnxx/alpha/map/double_array.hpp 2013-04-16 19:12:26 +0900 (a1000fc) @@ -73,6 +73,8 @@ class DoubleArray : public Map<T> { 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, T *key = nullptr); bool unset(int64_t key_id); @@ -148,6 +150,8 @@ class DoubleArray<Slice> : public Map<Slice> { 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, Slice *key = nullptr); bool unset(int64_t key_id); Modified: test/test_alpha_map.cpp (+17 -0) =================================================================== --- test/test_alpha_map.cpp 2013-04-16 19:07:45 +0900 (171d27c) +++ test/test_alpha_map.cpp 2013-04-16 19:12:26 +0900 (b951866) @@ -472,9 +472,13 @@ void test_map_double_array() { const std::int64_t key_id = pair.first->second; const bool is_new = pair.second; + const std::int64_t next_key_id = map->next_key_id(); std::int64_t stored_key_id; assert(map->insert(key, &stored_key_id) == is_new); assert(stored_key_id == key_id); + if (is_new) { + assert(next_key_id == key_id); + } assert(!map->insert(key, &stored_key_id)); T stored_key; @@ -483,8 +487,21 @@ void test_map_double_array() { assert(map->find(key, &stored_key_id)); assert(stored_key_id == key_id); + + assert(map->num_keys() == hash_map.size()); } +// { +// std::int64_t key_id = -1; +// for (std::size_t i = 0; i < MAP_SIZE; ++i) { +// T key; +// assert(map->get_next(key_id, &key_id, &key)); +// assert(key_id == static_cast<std::int64_t>(i)); +// assert(key_id == hash_map[key]); +// } +// assert(!map->get_next(key_id)); +// } + compare_maps(map, hash_map); test_basic_cursor(map, MAP_SIZE); -------------- next part -------------- HTML����������������������������...Download