fix broken use of iterator
authorbdemsky <bdemsky@uci.edu>
Wed, 23 Nov 2016 03:21:16 +0000 (19:21 -0800)
committerbdemsky <bdemsky@uci.edu>
Wed, 23 Nov 2016 03:21:16 +0000 (19:21 -0800)
hashset.h
planner.cc

index c4274e2..ecda268 100644 (file)
--- a/hashset.h
+++ b/hashset.h
@@ -151,6 +151,10 @@ class HashSet {
                 return NULL;
  }
 
+ _Key getFirstKey() {
+        return list->key;
+ }
+
  bool contains(_Key key) {
         return table->get(key)!=NULL;
  }
@@ -209,7 +213,6 @@ class HashSet {
  void operator delete[](void *p, size_t size) {
         _free(p);
  }
-
  private:
  HashTable<_Key, LinkNode<_Key>*, _KeyInt, _Shift, _malloc, _calloc, _free, hash_function, equals> * table;
  LinkNode<_Key> *list;
index 5ca24af..f832fb9 100644 (file)
@@ -52,10 +52,11 @@ void Planner::addChange(MCChange *change) {
 }
 
 void Planner::processChanges() {
-       ChangeIterator *cit=changeset->iterator();
-       for(;cit->hasNext();) {
-               MCChange *change=cit->next();
-               cit->remove();
+       while(!changeset->isEmpty()) {
+               MCChange *change=changeset->getFirstKey();
+               if (change==NULL)
+                       break;
+               changeset->remove(change);
                if (completedset->contains(change)) {
                        delete change;
                        continue;
@@ -73,9 +74,10 @@ void Planner::processChanges() {
                } else ASSERT(false);
                completedset->add(change);
        }
-       delete cit;
 
-       for(cit=completedset->iterator();cit->hasNext();) {
+       ChangeIterator *cit=completedset->iterator();
+
+       for(;cit->hasNext();) {
                MCChange *change=cit->next();
                cit->remove();
                delete change;