|
@ -20,6 +20,7 @@ class RehashFunction : public Jupiter::Rehashable |
|
|
public: |
|
|
public: |
|
|
int(*function)(void); |
|
|
int(*function)(void); |
|
|
int OnRehash() { return function(); }; |
|
|
int OnRehash() { return function(); }; |
|
|
|
|
|
bool OnBadRehash(bool removed) { return removed; }; |
|
|
RehashFunction(int(*func)(void)) { RehashFunction::function = func; }; |
|
|
RehashFunction(int(*func)(void)) { RehashFunction::function = func; }; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -60,6 +61,7 @@ unsigned int Jupiter::rehash() |
|
|
unsigned int total = 0; |
|
|
unsigned int total = 0; |
|
|
int r; |
|
|
int r; |
|
|
Jupiter::DLList<Jupiter::Rehashable>::Node *n = rehashables.getNode(0); |
|
|
Jupiter::DLList<Jupiter::Rehashable>::Node *n = rehashables.getNode(0); |
|
|
|
|
|
Jupiter::DLList<Jupiter::Rehashable>::Node *d; |
|
|
while (n != nullptr) |
|
|
while (n != nullptr) |
|
|
{ |
|
|
{ |
|
|
r = n->data->OnRehash(); |
|
|
r = n->data->OnRehash(); |
|
@ -68,10 +70,14 @@ unsigned int Jupiter::rehash() |
|
|
total++; |
|
|
total++; |
|
|
if (r < 0) |
|
|
if (r < 0) |
|
|
{ |
|
|
{ |
|
|
|
|
|
d = n; |
|
|
n = n->next; |
|
|
n = n->next; |
|
|
delete rehashables.remove(n->previous); |
|
|
if (d->data->OnBadRehash(true)) |
|
|
|
|
|
delete rehashables.remove(d); |
|
|
|
|
|
else rehashables.remove(d); |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
rehashables.remove(n)->OnBadRehash(false); |
|
|
} |
|
|
} |
|
|
n = n->next; |
|
|
n = n->next; |
|
|
} |
|
|
} |
|
|