| 264 | } |
| 265 | |
| 266 | public void clear() { |
| 267 | // Zero out all the entries so that existing iterators will skip them all |
| 268 | Iterator<Entry> it = iterator(); |
| 269 | it.forEachRemaining(Entry::clear); |
| 270 | |
| 271 | // Replace the existing list with a dummy, and make it the last node |
| 272 | // of the current list. If new nodes are added now, existing iterators |
| 273 | // will drive forward right into the new list. If they are not, then |
| 274 | // nothing is referencing the old list and it'll get GCed. |
| 275 | if (first != null) { |
| 276 | Entry dummy = makeDummy(); |
| 277 | last.next = dummy; |
| 278 | first = last = dummy; |
| 279 | } |
| 280 | |
| 281 | // Now we can clear the actual hashtable! |
| 282 | map.clear(); |
| 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public Iterator<Entry> iterator() { |