forked from steemit/steem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request steemit#3614 from steemit/3610-rc-api-delegation-p…
…ools rc_api delegation pools
- Loading branch information
Showing
9 changed files
with
546 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...ies/plugins/apis/database_api/include/steem/plugins/database_api/util/iterate_results.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
namespace steem { namespace plugins { namespace database_api { namespace util { | ||
|
||
template< typename ResultType > | ||
static ResultType on_push_default( const ResultType& r ) { return r; } | ||
|
||
template< typename ValueType > | ||
static bool filter_default( const ValueType& r ) { return true; } | ||
|
||
template<typename IndexType, typename StartType, typename ResultType, typename OnPushType, typename FilterType> | ||
void iterate_results( | ||
const IndexType& idx, | ||
StartType start, | ||
std::vector<ResultType>& result, | ||
uint32_t limit, | ||
OnPushType&& on_push, | ||
FilterType&& filter, | ||
bool ascending = true ) | ||
{ | ||
if( ascending ) | ||
{ | ||
auto itr = idx.lower_bound( start ); | ||
auto end = idx.end(); | ||
|
||
while( result.size() < limit && itr != end ) | ||
{ | ||
if( filter( *itr ) ) | ||
result.push_back( on_push( *itr ) ); | ||
|
||
++itr; | ||
} | ||
} | ||
else | ||
{ | ||
auto itr = boost::make_reverse_iterator( idx.lower_bound( start ) ); | ||
auto end = idx.rend(); | ||
|
||
while( result.size() < limit && itr != end ) | ||
{ | ||
if( filter( *itr ) ) | ||
result.push_back( on_push( *itr ) ); | ||
|
||
++itr; | ||
} | ||
} | ||
} | ||
|
||
} } } } // steem::plugins::database_api::util |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.