MCPcopy Index your code
hub / github.com/clojure/clojure / PersistentVector

Class PersistentVector

src/jvm/clojure/lang/PersistentVector.java:24–1054  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22import java.util.function.Consumer;
23
24public class PersistentVector extends APersistentVector implements IObj, IEditableCollection, IReduce, IKVReduce, IDrop{
25
26private static final long serialVersionUID = -7896022351281214157L;
27
28public static class Node implements Serializable {
29 transient public final AtomicReference<Thread> edit;
30 public final Object[] array;
31
32 public Node(AtomicReference<Thread> edit, Object[] array){
33 this.edit = edit;
34 this.array = array;
35 }
36
37 Node(AtomicReference<Thread> edit){
38 this.edit = edit;
39 this.array = new Object[32];
40 }
41}
42
43final static AtomicReference<Thread> NOEDIT = new AtomicReference<Thread>(null);
44public final static Node EMPTY_NODE = new Node(NOEDIT, new Object[32]);
45
46final int cnt;
47public final int shift;
48public final Node root;
49public final Object[] tail;
50final IPersistentMap _meta;
51
52
53public final static PersistentVector EMPTY = new PersistentVector(0, 5, EMPTY_NODE, new Object[]{});
54
55private static final IFn TRANSIENT_VECTOR_CONJ = new AFn() {
56 public Object invoke(Object coll, Object val) {
57 return ((ITransientVector)coll).conj(val);
58 }
59 public Object invoke(Object coll) {
60 return coll;
61 }
62};
63
64static public PersistentVector adopt(Object [] items){
65 return new PersistentVector(items.length, 5, EMPTY_NODE, items);
66}
67
68static public PersistentVector create(IReduceInit items) {
69 TransientVector ret = EMPTY.asTransient();
70 items.reduce(TRANSIENT_VECTOR_CONJ, ret);
71 return ret.persistent();
72}
73
74static public PersistentVector create(ISeq items){
75 Object[] arr = new Object[32];
76 int i = 0;
77 for(;items != null && i < 32; items = items.next())
78 arr[i++] = items.first();
79
80 if(items != null) { // >32, construct with array directly
81 PersistentVector start = new PersistentVector(32, 5, EMPTY_NODE, arr);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected