public int indexOf(Object o) { ISeq s = seq(); for (int i = 0; s != null; s = s.next(), i++) { if (Util.equiv(s.first(), o)) return i; } return -1; }
public Object[] toArray(Object[] a) { if (a.length >= count()) { ISeq s = seq(); for (int i = 0; s != null; ++i, s = s.next()) { a[i] = s.first(); } if (a.length > count()) a[count()] = null; return a; } else return toArray(); }
public static int mapHash(IPersistentMap m) { int hash = 0; for (ISeq s = m.seq(); s != null; s = s.next()) { Map.Entry e = (Map.Entry) s.first(); hash += (e.getKey() == null ? 0 : e.getKey().hashCode()) ^ (e.getValue() == null ? 0 : e.getValue().hashCode()); } return hash; }
public static boolean mapEquals(IPersistentMap m1, Object obj) { if (m1 == obj) return true; if (!(obj instanceof Map)) return false; Map m = (Map) obj; if (m.size() != m1.count()) return false; for (ISeq s = m1.seq(); s != null; s = s.next()) { Map.Entry e = (Map.Entry) s.first(); boolean found = m.containsKey(e.getKey()); if (!found || !Util.equals(e.getValue(), m.get(e.getKey()))) return false; } return true; }
public boolean equiv(Object obj) { if (!(obj instanceof Map)) return false; if (obj instanceof IPersistentMap && !(obj instanceof MapEquivalence)) return false; Map m = (Map) obj; if (m.size() != size()) return false; for (ISeq s = seq(); s != null; s = s.next()) { Map.Entry e = (Map.Entry) s.first(); boolean found = m.containsKey(e.getKey()); if (!found || !Util.equiv(e.getValue(), m.get(e.getKey()))) return false; } return true; }
public IPersistentCollection cons(Object o) { if (o instanceof Map.Entry) { Map.Entry e = (Map.Entry) o; return assoc(e.getKey(), e.getValue()); } else if (o instanceof IPersistentVector) { IPersistentVector v = (IPersistentVector) o; if (v.count() != 2) throw new IllegalArgumentException("Vector arg to map conj must be a pair"); return assoc(v.nth(0), v.nth(1)); } IPersistentMap ret = this; for (ISeq es = RT.seq(o); es != null; es = es.next()) { Map.Entry e = (Map.Entry) es.first(); ret = ret.assoc(e.getKey(), e.getValue()); } return ret; }
public ISeq next() { seq(); if (s == null) return null; return s.next(); }
public int count() { int c = 0; for (ISeq s = seq(); s != null; s = s.next()) ++c; return c; }
public boolean contains(Object o) { for (ISeq s = seq(); s != null; s = s.next()) { if (Util.equiv(s.first(), o)) return true; } return false; }
public ISeq next() { return create(seq.next()); }