From 3c297d1a66069837dace5eaf1e6f211285305a20 Mon Sep 17 00:00:00 2001 From: sears Date: Thu, 4 Feb 2010 22:19:42 +0000 Subject: [PATCH] fix iterator bug git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@550 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe --- logiterators.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/logiterators.h b/logiterators.h index 36bb35a..85f3d07 100644 --- a/logiterators.h +++ b/logiterators.h @@ -21,15 +21,16 @@ private: typedef typename MEMTREE::const_iterator MTITER; public: - memTreeIterator( MEMTREE *s ) : first_(true), it_(s->begin()), itend_(s->end()) { } - memTreeIterator( MEMTREE *s, TUPLE &key ) : first_(true), it_(s->find(key)), itend_(s->end()) { } + memTreeIterator( MEMTREE *s ) : first_(true), done_(false), it_(s->begin()), itend_(s->end()) { } + memTreeIterator( MEMTREE *s, TUPLE &key ) : first_(true), done_(false), it_(s->find(key)), itend_(s->end()) { } ~memTreeIterator() { } TUPLE* getnext() { - if(it_==itend_) { return NULL; } - if(first_) { first_ = 0;} else { it_++; } - TUPLE *t = new TUPLE(); + if(done_) { return NULL; } + if(first_) { first_ = 0;} else { it_++; } + if(it_==itend_) { done_= true; return NULL; } + TUPLE *t = new TUPLE(); t->clone(*it_); return t; } @@ -41,6 +42,7 @@ private: int operator-(memTreeIterator & t) { abort(); } private: bool first_; + bool done_; MTITER it_; MTITER itend_; };