| 174 | } |
| 175 | |
| 176 | public PersistentVector assocN(int i, Object val){ |
| 177 | if(i >= 0 && i < cnt) |
| 178 | { |
| 179 | if(i >= tailoff()) |
| 180 | { |
| 181 | Object[] newTail = new Object[tail.length]; |
| 182 | System.arraycopy(tail, 0, newTail, 0, tail.length); |
| 183 | newTail[i & 0x01f] = val; |
| 184 | |
| 185 | return new PersistentVector(meta(), cnt, shift, root, newTail); |
| 186 | } |
| 187 | |
| 188 | return new PersistentVector(meta(), cnt, shift, doAssoc(shift, root, i, val), tail); |
| 189 | } |
| 190 | if(i == cnt) |
| 191 | return cons(val); |
| 192 | throw new IndexOutOfBoundsException(); |
| 193 | } |
| 194 | |
| 195 | private static Node doAssoc(int level, Node node, int i, Object val){ |
| 196 | Node ret = new Node(node.edit,node.array.clone()); |