| 456 | } |
| 457 | |
| 458 | HashSet::~HashSet() |
| 459 | { |
| 460 | for (int i = 0; i < tableSize; i++) { |
| 461 | Node *n1 = table[i]; |
| 462 | while (n1) { |
| 463 | Node *n2 = n1->next; |
| 464 | |
| 465 | // It seems appropriate to call "clearNode(n1)" here instead |
| 466 | // of "delete n1->object", but since this is the destructor, |
| 467 | // the implementation of a sub class would not be called |
| 468 | // anymore. This is the reason why HashTable has an |
| 469 | // destructor. |
| 470 | if (ownerOfObjects) { |
| 471 | PRINTF ("- deleting object: %s\n", n1->object->toString()); |
| 472 | delete n1->object; |
| 473 | } |
| 474 | |
| 475 | delete n1; |
| 476 | n1 = n2; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | delete[] table; |
| 481 | } |
| 482 | |
| 483 | int HashSet::size () |
| 484 | { |