public MutableMap<K, V> beginWrite() {
        return new MutableMap<>(set);
    }
@SuppressWarnings({"OverlyLongMethod"})
    @Test
    public void reverseIterationTest() {
        Random random = new Random(5743);
        Persistent23TreeMap.MutableMap<Integer, String> tree = new Persistent23TreeMap<Integer, String>().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.descendingIterator();
                for (Iterator<Persistent23TreeMap.Entry<Integer, String>> treeItr = tree.reverseIterator();
                     treeItr.hasNext(); ) {
                    Assert.assertTrue(iterator.hasNext());
                    Persistent23TreeMap.Entry<Integer, String> key = treeItr.next();
                    Integer next = iterator.next();
                    Assert.assertEquals(next, key.getKey());
                    Assert.assertEquals(String.valueOf(next), key.getValue());
                }
                Assert.assertFalse(iterator.hasNext());

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