提交 53ec8ed9 创建 作者: Austin Clements's avatar Austin Clements

radix: Normal beign/end interface

In standard collection types, begin and end are methods of the collection. The global begin and end are defined in <iterator> and simply call these methods.
上级 b1bdb3f4
......@@ -6,6 +6,8 @@
#include "gc.hh"
#include <iterator>
enum { bits_per_level = 9 };
enum { key_bits = 36 };
enum { radix_levels = (key_bits + bits_per_level - 1) / bits_per_level };
......@@ -184,6 +186,7 @@ static_assert(alignof(radix_elem) > entry_mask,
"radix_elem sufficiently aligned");
struct radix;
struct radix_iterator;
struct radix_range {
radix* r_;
......@@ -196,11 +199,16 @@ struct radix_range {
void replace(u64 start, u64 size, radix_elem* val);
radix_iterator begin() const;
radix_iterator end() const;
radix_range(const radix_range&) = delete;
void operator=(const radix_range&) = delete;
};
struct radix {
typedef radix_iterator iterator;
radix_ptr root_;
u32 shift_;
......@@ -210,6 +218,9 @@ struct radix {
radix_elem* search(u64 key);
radix_range search_lock(u64 start, u64 size);
radix_iterator begin() const;
radix_iterator end() const;
NEW_DELETE_OPS(radix)
};
......@@ -246,22 +257,22 @@ private:
void advance();
};
static inline radix_iterator
begin(const radix &r) {
return radix_iterator(&r, 0, (u64)1 << key_bits);
inline radix_iterator
radix_range::begin() const {
return radix_iterator(r_, start_, start_ + size_);
}
static inline radix_iterator
end(const radix &r) {
return radix_iterator(&r, (u64)1 << key_bits, (u64)1 << key_bits);
inline radix_iterator
radix_range::end() const {
return radix_iterator(r_, start_ + size_, start_ + size_);
}
static inline radix_iterator
begin(const radix_range &rr) {
return radix_iterator(rr.r_, rr.start_, rr.start_ + rr.size_);
inline radix_iterator
radix::begin() const {
return radix_iterator(this, 0, (u64)1 << key_bits);
}
static inline radix_iterator
end(const radix_range &rr) {
return radix_iterator(rr.r_, rr.start_ + rr.size_, rr.start_ + rr.size_);
inline radix_iterator
radix::end() const {
return radix_iterator(this, (u64)1 << key_bits, (u64)1 << key_bits);
}
// -*- c++ -*-
namespace std {
template <class C> auto begin(C& c) -> decltype(c.begin())
{
return c.begin();
}
template <class C> auto begin(const C& c) -> decltype(c.begin())
{
return c.begin();
}
template <class C> auto end(C& c) -> decltype(c.end())
{
return c.end();
}
template <class C> auto end(const C& c) -> decltype(c.end())
{
return c.end();
}
template <class T, size_t N> T* begin(T (&array)[N])
{
return array[0];
}
template <class T, size_t N> T* end(T (&array)[N])
{
return array[N];
}
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论