Handle decrementing end
This commit is contained in:
16
Facade.h
16
Facade.h
@@ -19,12 +19,20 @@ struct Facade {
|
|||||||
int limit,
|
int limit,
|
||||||
bool reverse) const {
|
bool reverse) const {
|
||||||
std::vector<std::pair<String, String>> result;
|
std::vector<std::pair<String, String>> result;
|
||||||
|
if (begin >= end) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
weaselab::VersionedMap::Iterator versionedIter[2];
|
weaselab::VersionedMap::Iterator versionedIter[2];
|
||||||
const weaselab::VersionedMap::Key key[] = {
|
const weaselab::VersionedMap::Key key[] = {
|
||||||
{begin.data(), int(begin.size())}, {end.data(), int(end.size())}};
|
{begin.data(), int(begin.size())}, {end.data(), int(end.size())}};
|
||||||
const int64_t v[] = {version, version};
|
const int64_t v[] = {version, version};
|
||||||
facade->versioned.firstGeq(key, v, versionedIter, 2);
|
facade->versioned.firstGeq(key, v, versionedIter, 2);
|
||||||
|
|
||||||
|
if (versionedIter[0] == versionedIter[1]) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static const uint8_t zero_[] = {0};
|
static const uint8_t zero_[] = {0};
|
||||||
static const String zero{zero_, 1};
|
static const String zero{zero_, 1};
|
||||||
|
|
||||||
@@ -32,7 +40,10 @@ struct Facade {
|
|||||||
weaselab::VersionedMap::Iterator iter = versionedIter[1];
|
weaselab::VersionedMap::Iterator iter = versionedIter[1];
|
||||||
weaselab::VersionedMap::Iterator endIter = versionedIter[0];
|
weaselab::VersionedMap::Iterator endIter = versionedIter[0];
|
||||||
String readUntil = end;
|
String readUntil = end;
|
||||||
for (; iter != endIter; --iter) {
|
if (iter == facade->versioned.end(version)) {
|
||||||
|
--iter;
|
||||||
|
}
|
||||||
|
for (;; --iter) {
|
||||||
auto m = *iter;
|
auto m = *iter;
|
||||||
const auto mEnd =
|
const auto mEnd =
|
||||||
m.type == weaselab::VersionedMap::Set || m.param2Len == 0
|
m.type == weaselab::VersionedMap::Set || m.param2Len == 0
|
||||||
@@ -56,6 +67,9 @@ struct Facade {
|
|||||||
readUntil = String(m.param1, m.param1Len);
|
readUntil = String(m.param1, m.param1Len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (iter == endIter) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
facade->unversionedRead(begin, readUntil, limit, true, result);
|
facade->unversionedRead(begin, readUntil, limit, true, result);
|
||||||
return result;
|
return result;
|
||||||
|
@@ -1015,6 +1015,8 @@ void materializeMutations(VersionedMap::Iterator::Impl *impl, const Entry *prev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
VersionedMap::Iterator &VersionedMap::Iterator::operator++() {
|
VersionedMap::Iterator &VersionedMap::Iterator::operator++() {
|
||||||
|
impl->cmp = 1;
|
||||||
|
|
||||||
if (impl->mutationIndex < impl->mutationCount - 1) {
|
if (impl->mutationIndex < impl->mutationCount - 1) {
|
||||||
++impl->mutationIndex;
|
++impl->mutationIndex;
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1040,19 +1042,46 @@ VersionedMap::Iterator VersionedMap::Iterator::operator++(int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VersionedMap::Iterator &VersionedMap::Iterator::operator--() {
|
VersionedMap::Iterator &VersionedMap::Iterator::operator--() {
|
||||||
|
impl->cmp = -1;
|
||||||
|
|
||||||
if (impl->mutationIndex > 0) {
|
if (impl->mutationIndex > 0) {
|
||||||
--impl->mutationIndex;
|
--impl->mutationIndex;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO support decrementing end
|
// Handle decrementing end
|
||||||
|
if (impl->finger.searchPathSize() == 0) {
|
||||||
|
bool ignored;
|
||||||
|
impl->finger.push(
|
||||||
|
impl->map->roots.getThreadSafeHandle().rootForVersion(impl->version),
|
||||||
|
ignored);
|
||||||
|
assert(impl->finger.backNode() != 0);
|
||||||
|
uint32_t c;
|
||||||
|
while ((c = impl->map->child<std::memory_order_acquire>(
|
||||||
|
impl->finger.backNode(), true, impl->version)) != 0) {
|
||||||
|
impl->finger.push(c, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Entry *next = nullptr;
|
||||||
|
for (;;) {
|
||||||
|
materializeMutations(impl, nullptr, next);
|
||||||
|
if (impl->mutationCount > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
next = impl->map->mm.base[impl->finger.backNode()].entry;
|
||||||
|
impl->map->move<std::memory_order_acquire>(impl->finger, impl->version,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
impl->mutationIndex = impl->mutationCount - 1;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const auto &entry = *impl->map->mm.base[impl->finger.backNode()].entry;
|
const Entry *entry = impl->map->mm.base[impl->finger.backNode()].entry;
|
||||||
impl->map->move<std::memory_order_acquire>(impl->finger, impl->version,
|
impl->map->move<std::memory_order_acquire>(impl->finger, impl->version,
|
||||||
false);
|
false);
|
||||||
if (impl->finger.searchPathSize() > 0) {
|
if (impl->finger.searchPathSize() > 0) {
|
||||||
materializeMutations(impl, nullptr, &entry);
|
materializeMutations(impl, nullptr, entry);
|
||||||
}
|
}
|
||||||
} while (impl->mutationCount == 0);
|
} while (impl->mutationCount == 0);
|
||||||
impl->mutationIndex = impl->mutationCount - 1;
|
impl->mutationIndex = impl->mutationCount - 1;
|
||||||
|
Reference in New Issue
Block a user