mirror of https://gitee.com/bigwinds/arangodb
Transaction OperationCursor now implements a skip method.
This commit is contained in:
parent
f1d0875c4e
commit
6e7f9ef49c
|
@ -103,11 +103,12 @@ void IndexIterator::reset() {}
|
|||
/// @brief default implementation for skip
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void IndexIterator::skip(uint64_t count) {
|
||||
void IndexIterator::skip(uint64_t count, uint64_t& skipped) {
|
||||
// Skip the first count-many entries
|
||||
// TODO: Can be improved
|
||||
while (count > 0 && next() != nullptr) {
|
||||
--count;
|
||||
skipped++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ class IndexIterator {
|
|||
|
||||
virtual void reset();
|
||||
|
||||
virtual void skip(uint64_t count);
|
||||
virtual void skip(uint64_t count, uint64_t& skipped);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -64,3 +64,32 @@ int OperationCursor::getMore(uint64_t batchSize) {
|
|||
}
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Skip the next toSkip many elements.
|
||||
/// skipped will be increased by the amount of skipped elements afterwards
|
||||
/// Check hasMore()==true before using this
|
||||
/// NOTE: This will throw on OUT_OF_MEMORY
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int OperationCursor::skip(uint64_t toSkip, uint64_t& skipped) {
|
||||
if (!hasMore()) {
|
||||
TRI_ASSERT(false);
|
||||
// You requested more even if you should have checked it before.
|
||||
return TRI_ERROR_FORBIDDEN;
|
||||
}
|
||||
|
||||
if (toSkip > _limit) {
|
||||
// Short-cut, we jump to the end
|
||||
_limit = 0;
|
||||
_hasMore = false;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
_indexIterator->skip(toSkip, skipped);
|
||||
_limit -= skipped;
|
||||
if (skipped != toSkip || _limit == 0) {
|
||||
_hasMore = false;
|
||||
}
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ struct OperationCursor : public OperationResult {
|
|||
/// NOTE: This will throw on OUT_OF_MEMORY
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int getMore(uint64_t batchSize);
|
||||
int getMore(uint64_t);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Get next default batchSize many elements.
|
||||
|
@ -109,6 +109,15 @@ struct OperationCursor : public OperationResult {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int getMore();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Skip the next toSkip many elements.
|
||||
/// skipped will be increased by the amount of skipped elements afterwards
|
||||
/// Check hasMore()==true before using this
|
||||
/// NOTE: This will throw on OUT_OF_MEMORY
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int skip(uint64_t, uint64_t&);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1793,7 +1793,8 @@ OperationCursor Transaction::indexScan(
|
|||
return OperationCursor(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
iterator->skip(skip);
|
||||
uint64_t unused = 0;
|
||||
iterator->skip(skip, unused);
|
||||
|
||||
return OperationCursor(transactionContext()->orderCustomTypeHandler(),
|
||||
iterator.release(), limit, batchSize);
|
||||
|
|
Loading…
Reference in New Issue