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
| 23 | */ |
| 24 | |
| 25 | public class PersistentQueue extends Obj implements IPersistentList, Collection, Counted, IHashEq{ |
| 26 | |
| 27 | private static final long serialVersionUID = 8247184423915313132L; |
| 28 | |
| 29 | final public static PersistentQueue EMPTY = new PersistentQueue(null, 0, null, null); |
| 30 | |
| 31 | //* |
| 32 | final int cnt; |
| 33 | final ISeq f; |
| 34 | final PersistentVector r; |
| 35 | //static final int INITIAL_REAR_SIZE = 4; |
| 36 | int _hash; |
| 37 | int _hasheq; |
| 38 | |
| 39 | PersistentQueue(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 | |
| 46 | public 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 | |
| 60 | public 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 | |
| 74 | public 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected