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

Class PersistentQueue

src/jvm/clojure/lang/PersistentQueue.java:25–342  ·  view source on GitHub ↗

conses onto rear, peeks/pops from front See Okasaki's Batched Queues This differs in that it uses a PersistentVector as the rear, which is in-order, so no reversing or suspensions required for persistent use

Source from the content-addressed store, hash-verified

23 */
24
25public class PersistentQueue extends Obj implements IPersistentList, Collection, Counted, IHashEq{
26
27private static final long serialVersionUID = 8247184423915313132L;
28
29final public static PersistentQueue EMPTY = new PersistentQueue(null, 0, null, null);
30
31//*
32final int cnt;
33final ISeq f;
34final PersistentVector r;
35//static final int INITIAL_REAR_SIZE = 4;
36int _hash;
37int _hasheq;
38
39PersistentQueue(IPersistentMap meta, int cnt, ISeq f, PersistentVector r){
40 super(meta);
41 this.cnt = cnt;
42 this.f = f;
43 this.r = r;
44}
45
46public boolean equiv(Object obj){
47
48 if(!(obj instanceof Sequential))
49 return false;
50 ISeq ms = RT.seq(obj);
51 for(ISeq s = seq(); s != null; s = s.next(), ms = ms.next())
52 {
53 if(ms == null || !Util.equiv(s.first(), ms.first()))
54 return false;
55 }
56 return ms == null;
57
58}
59
60public boolean equals(Object obj){
61
62 if(!(obj instanceof Sequential))
63 return false;
64 ISeq ms = RT.seq(obj);
65 for(ISeq s = seq(); s != null; s = s.next(), ms = ms.next())
66 {
67 if(ms == null || !Util.equals(s.first(), ms.first()))
68 return false;
69 }
70 return ms == null;
71
72}
73
74public int hashCode(){
75 int hash = this._hash;
76 if(hash == 0)
77 {
78 hash = 1;
79 for(ISeq s = seq(); s != null; s = s.next())
80 {
81 hash = 31 * hash + (s.first() == null ? 0 : s.first().hashCode());
82 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected