bool ReducerContext<KeyIn, ValueIn, KeyOut, ValueOut>::NextKey() { while (same_as_previous_key_ && !exhausted_) { NextPair(); } if (!exhausted_) { // Deserialize key/value. NextPair(); return true; } else { return false; } }
Point_2* ch_chan::FindHull(Point_2* start, Point_2* end, Point_2* result){ #if USE_SDL sdl = new SDL(1280, 720, Point_2(-100,-100), Point_2(100,100)); #endif int size = end-start; int t = 0; int m = pow(2,pow(2 , t++)); int k; int hIndex; int pIndex; vector< Point_2 > out; vector<vector< Point_2 > > hulls; while(m <= size){ hulls = GetSubHulls(start, end, m); #if USE_SDL if(sdl) { sdl->clear_buffer(); sdl->draw_points_to_buffer(end - start, start); for (int i = 0; i < hulls.size(); i++) { sdl->draw_hull_to_buffer(hulls[i]); } sdl->display_buffer(); } sdl->wait_for_msecs(1000); #endif FindLeftmostHull(hulls, hIndex, pIndex); Point_2 firstPoint =hulls[hIndex][pIndex]; Point_2 nextPoint; k = 0; result[k++] = firstPoint; for(int i =1;i<m;i++){ NextPair(hulls,hIndex,pIndex); nextPoint = hulls[hIndex][pIndex]; #if USE_SDL if(sdl) { sdl->draw_line_between(result[k-1], nextPoint, 0, 255, 0); sdl->display_buffer(); sdl->wait_for_msecs(500); } #endif if(nextPoint==firstPoint) break; result[k++] = nextPoint; } if(nextPoint==firstPoint || m == size) break; m = min((int)pow(2,pow(2 , t++)),size); #if USE_SDL if(sdl) sdl->wait_for_msecs(1000); #endif } return result+k; }
bool ReducerContext<KeyIn, ValueIn, KeyOut, ValueOut>::Next() { if (iterator_begin_ || !stop_) { if (iterator_begin_) { // Key/value has been deserialized by NextKey(). iterator_begin_ = false; if (!same_as_previous_key_) { stop_ = true; } } else { NextPair(); if (!same_as_previous_key_) { stop_ = true; } } return true; } else { return false; } }