public MutablePersistentHashSet<K> beginWrite() {
        return new MutablePersistentHashSet<>(this);
    }
@Test
    public void forEachKeyTest() {
        Random random = new Random(8234890);
        PersistentHashSet.MutablePersistentHashSet<Integer> tree = new PersistentHashSet<Integer>().beginWrite();
        int[] p = genPermutation(random);
        HashSet<Integer> added = new HashSet<>();
        for (int i = 0; i < ENTRIES_TO_ADD; i++) {
            int size = tree.size();
            Assert.assertEquals(i, size);
            if ((size & 1023) == 0 || size < 100) {
                final Collection<Integer> actual = new HashSet<>(size);
                ObjectProcedure<Integer> proc = object -> {
                    Assert.assertFalse(actual.contains(object));
                    actual.add(object);
                    return true;
                };
                tree.forEachKey(proc);
                Assert.assertEquals(size, actual.size());
                for (Integer key : added) {
                    Assert.assertTrue(actual.contains(key));
                }
            }
            tree.add(p[i]);
            added.add(p[i]);
        }
    }