Merge branch 'tgrabiec/tuple_type_iterator' of github.com:cloudius-systems/urchin into db

Iterators for composites, from Tomasz.
This commit is contained in:
Avi Kivity
2015-04-16 17:52:38 +03:00
2 changed files with 60 additions and 6 deletions

37
keys.hh
View File

@@ -109,6 +109,16 @@ public:
operator bytes_view() const {
return _bytes;
}
// begin() and end() return iterators over components of this tuple. The iterator yields a bytes_view to the component.
auto begin(const schema& s) const {
return get_tuple_type(s)->begin(_bytes);
}
// See begin()
auto end(const schema& s) const {
return get_tuple_type(s)->end(_bytes);
}
};
template <typename TopLevel, typename PrefixTopLevel>
@@ -264,8 +274,13 @@ public:
public:
using tuple = lw_shared_ptr<tuple_type<allow_prefixes::no>>;
static partition_key from_bytes(bytes b) { return partition_key(std::move(b)); }
static auto get_tuple_type(const schema& s) { return s.partition_key_type; }
static partition_key from_bytes(bytes b) {
return partition_key(std::move(b));
}
static const tuple& get_tuple_type(const schema& s) {
return s.partition_key_type;
}
};
class exploded_clustering_prefix {
@@ -294,8 +309,13 @@ public:
public:
using tuple = lw_shared_ptr<tuple_type<allow_prefixes::no>>;
static clustering_key from_bytes(bytes b) { return clustering_key(std::move(b)); }
static auto get_tuple_type(const schema& s) { return s.clustering_key_type; }
static clustering_key from_bytes(bytes b) {
return clustering_key(std::move(b));
}
static const tuple& get_tuple_type(const schema& s) {
return s.clustering_key_type;
}
static clustering_key from_clustering_prefix(const schema& s, const exploded_clustering_prefix& prefix) {
assert(prefix.is_full(s));
@@ -308,8 +328,13 @@ class clustering_key_prefix : public prefix_tuple_wrapper<clustering_key_prefix,
public:
using tuple = lw_shared_ptr<tuple_type<allow_prefixes::yes>>;
static clustering_key_prefix from_bytes(bytes b) { return clustering_key_prefix(std::move(b)); }
static auto get_tuple_type(const schema& s) { return s.clustering_key_prefix_type; }
static clustering_key_prefix from_bytes(bytes b) {
return clustering_key_prefix(std::move(b));
}
static const tuple& get_tuple_type(const schema& s) {
return s.clustering_key_prefix_type;
}
static clustering_key_prefix from_clustering_prefix(const schema& s, const exploded_clustering_prefix& prefix) {
return from_exploded(s, prefix.components());

View File

@@ -25,3 +25,32 @@ BOOST_AUTO_TEST_CASE(test_key_is_prefixed_by) {
BOOST_REQUIRE(!key.is_prefixed_by(s, clustering_key_prefix::from_exploded(s, {bytes("abc")})));
BOOST_REQUIRE(!key.is_prefixed_by(s, clustering_key_prefix::from_exploded(s, {bytes("ab")})));
}
BOOST_AUTO_TEST_CASE(test_key_component_iterator) {
schema s({}, "", "",
{
{"c1", bytes_type}
}, {
{"c2", bytes_type}, {"c3", bytes_type}, {"c4", bytes_type}
},
{}, {}, utf8_type);
auto key = clustering_key::from_exploded(s, {bytes("a"), bytes("b"), bytes("c")});
auto i = key.begin(s);
auto end = key.end(s);
BOOST_REQUIRE(i != end);
BOOST_REQUIRE(*i == bytes_view(bytes("a")));
++i;
BOOST_REQUIRE(i != end);
BOOST_REQUIRE(*i == bytes_view(bytes("b")));
++i;
BOOST_REQUIRE(i != end);
BOOST_REQUIRE(*i == bytes_view(bytes("c")));
++i;
BOOST_REQUIRE(i == end);
}