public MutableTree<K> beginWrite() {
        return new MutableTree<>(this);
    }
@Test
    public void iterationTest() {
        Random random = new Random(8234890);
        Persistent23Tree.MutableTree<Integer> tree = new Persistent23Tree<Integer>().beginWrite();
        int[] p = genPermutation(random);
        TreeSet<Integer> added = new TreeSet<>();
        for (int i = 0; i < ENTRIES_TO_ADD; i++) {
            int size = tree.size();
            Assert.assertEquals(i, size);
            if ((size & 1023) == 0 || size < 100) {
                Iterator<Integer> iterator = added.iterator();
                for (Integer key : tree) {
                    Assert.assertTrue(iterator.hasNext());
                    Assert.assertEquals(iterator.next(), key);
                }
                Assert.assertFalse(iterator.hasNext());

                iterator = added.iterator();
                Iterator<Integer> treeItr = tree.iterator();
                for (int j = 0; j < size; j++) {
                    Integer key = treeItr.next();
                    Assert.assertTrue(iterator.hasNext());
                    Assert.assertEquals(iterator.next(), key);
                }
                Assert.assertFalse(iterator.hasNext());
                try {
                    treeItr.next();
                    Assert.fail();
                } catch (NoSuchElementException e) {
                }
                Assert.assertFalse(treeItr.hasNext());
            }
            tree.add(p[i]);
            added.add(p[i]);
        }
    }