removing duplicate logic
This commit is contained in:
@@ -140,10 +140,16 @@ namespace mongo {
|
||||
_advance();
|
||||
return ret;
|
||||
}
|
||||
|
||||
BSONObj FilteringClientCursor::peek(){
|
||||
if ( _next.isEmpty() )
|
||||
_advance();
|
||||
return _next;
|
||||
}
|
||||
|
||||
void FilteringClientCursor::_advance(){
|
||||
assert( _next.isEmpty() );
|
||||
if ( ! _cursor.get() )
|
||||
if ( ! _cursor.get() || _done )
|
||||
return;
|
||||
|
||||
while ( _cursor->more() ){
|
||||
@@ -215,7 +221,6 @@ namespace mongo {
|
||||
void ParallelSortClusteredCursor::_init(){
|
||||
_numServers = _servers.size();
|
||||
_cursors = new FilteringClientCursor[_numServers];
|
||||
_nexts = new BSONObj[_numServers];
|
||||
|
||||
// TODO: parellize
|
||||
int num = 0;
|
||||
@@ -228,14 +233,10 @@ namespace mongo {
|
||||
|
||||
ParallelSortClusteredCursor::~ParallelSortClusteredCursor(){
|
||||
delete [] _cursors;
|
||||
delete [] _nexts;
|
||||
}
|
||||
|
||||
bool ParallelSortClusteredCursor::more(){
|
||||
for ( int i=0; i<_numServers; i++ ){
|
||||
if ( ! _nexts[i].isEmpty() )
|
||||
return true;
|
||||
|
||||
if ( _cursors[i].more() )
|
||||
return true;
|
||||
}
|
||||
@@ -243,53 +244,35 @@ namespace mongo {
|
||||
}
|
||||
|
||||
BSONObj ParallelSortClusteredCursor::next(){
|
||||
advance();
|
||||
|
||||
BSONObj best = BSONObj();
|
||||
int bestFrom = -1;
|
||||
|
||||
for ( int i=0; i<_numServers; i++){
|
||||
if ( _nexts[i].isEmpty() )
|
||||
if ( ! _cursors[i].more() )
|
||||
continue;
|
||||
|
||||
BSONObj me = _cursors[i].peek();
|
||||
|
||||
if ( best.isEmpty() ){
|
||||
best = _nexts[i];
|
||||
best = me;
|
||||
bestFrom = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
int comp = best.woSortOrder( _nexts[i] , _sortKey );
|
||||
int comp = best.woSortOrder( me , _sortKey );
|
||||
if ( comp < 0 )
|
||||
continue;
|
||||
|
||||
best = _nexts[i];
|
||||
best = me;
|
||||
bestFrom = i;
|
||||
}
|
||||
|
||||
|
||||
uassert( 10019 , "no more elements" , ! best.isEmpty() );
|
||||
_nexts[bestFrom] = BSONObj();
|
||||
_cursors[bestFrom].next();
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
void ParallelSortClusteredCursor::advance(){
|
||||
for ( int i=0; i<_numServers; i++ ){
|
||||
|
||||
if ( ! _nexts[i].isEmpty() ){
|
||||
// already have a good object there
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! _cursors[i].more() ){
|
||||
// cursor is dead, oh well
|
||||
continue;
|
||||
}
|
||||
|
||||
_nexts[i] = _cursors[i].next();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// -----------------
|
||||
// ---- Future -----
|
||||
// -----------------
|
||||
|
||||
Reference in New Issue
Block a user