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

radix: Add a method to skip nulls and use it when initializing

I think the semantics used to be that the iterator would always start at the first non-null element, which I broke when I switched to the iterative implementation. This fixes that and introduces a method that will be useful once iterators can point to null elements.
上级 e00b4d6c
...@@ -241,6 +241,14 @@ struct radix_iterator { ...@@ -241,6 +241,14 @@ struct radix_iterator {
return path_[level_]->load().elem(); return path_[level_]->load().elem();
} }
// Advance the iterator until it points at a non-null entry or end.
// If the current element is non-null, does nothing.
void skip_nulls()
{
if (path_[level_]->load().is_null())
++(*this);
}
// Compare equality on just the key. // Compare equality on just the key.
bool operator==(const radix_iterator &other) { bool operator==(const radix_iterator &other) {
return r_ == other.r_ && k_ == other.k_; } return r_ == other.r_ && k_ == other.k_; }
......
...@@ -261,6 +261,9 @@ radix_iterator::prime_path() ...@@ -261,6 +261,9 @@ radix_iterator::prime_path()
node = path_[level_]; node = path_[level_];
} }
// Find a real element
skip_nulls();
dprintf("%p: Adjusted: k = %lx\n", r_, k_); dprintf("%p: Adjusted: k = %lx\n", r_, k_);
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论