| 616 | //} |
| 617 | |
| 618 | public PersistentVector pop(){ |
| 619 | if(cnt == 0) |
| 620 | throw new IllegalStateException("Can't pop empty vector"); |
| 621 | if(cnt == 1) |
| 622 | return EMPTY.withMeta(meta()); |
| 623 | //if(tail.length > 1) |
| 624 | if(cnt-tailoff() > 1) |
| 625 | { |
| 626 | Object[] newTail = new Object[tail.length - 1]; |
| 627 | System.arraycopy(tail, 0, newTail, 0, newTail.length); |
| 628 | return new PersistentVector(meta(), cnt - 1, shift, root, newTail); |
| 629 | } |
| 630 | Object[] newtail = arrayFor(cnt - 2); |
| 631 | |
| 632 | Node newroot = popTail(shift, root); |
| 633 | int newshift = shift; |
| 634 | if(newroot == null) |
| 635 | { |
| 636 | newroot = EMPTY_NODE; |
| 637 | } |
| 638 | if(shift > 5 && newroot.array[1] == null) |
| 639 | { |
| 640 | newroot = (Node) newroot.array[0]; |
| 641 | newshift -= 5; |
| 642 | } |
| 643 | return new PersistentVector(meta(), cnt - 1, newshift, newroot, newtail); |
| 644 | } |
| 645 | |
| 646 | private Node popTail(int level, Node node){ |
| 647 | int subidx = ((cnt-2) >>> level) & 0x01f; |