>Note that instances of this class are constant values i.e., add/remove etc return new values.See Okasaki, Kahrs, Larsen et al
public static PersistentTreeMap create(IComparer comp, ISeq items) { IPersistentMap ret = new PersistentTreeMap(comp); for (; items != null; items = items.next().next()) { if (items.next() == null) { throw new ArgumentException(string.Format("No value supplied for key: {0}", items.first())); } ret = ret.assoc(items.first(), RT.second(items)); } return((PersistentTreeMap)ret); }
static Symbol registerArg(int n) { PersistentTreeMap argsyms = (PersistentTreeMap)ARG_ENV.deref(); if (argsyms == null) { throw new InvalidOperationException("arg literal not in #()"); } Symbol ret = (Symbol)argsyms.valAt(n); if (ret == null) { ret = garg(n); ARG_ENV.set(argsyms.assoc(n, ret)); } return(ret); }
//static ListReader _listReader = new ListReader(); protected override object Read(PushbackTextReader r, char lparen) { if (ARG_ENV.deref() != null) { throw new InvalidOperationException("Nested #()s are not allowed"); } try { Var.pushThreadBindings(RT.map(ARG_ENV, PersistentTreeMap.EMPTY)); r.Unread('('); ////object form = ReadAux(r, true, null, true); object form = ReadAux(r); //object form = _listReader.invoke(r, '('); IPersistentVector args = PersistentVector.EMPTY; PersistentTreeMap argsyms = (PersistentTreeMap)ARG_ENV.deref(); ISeq rargs = argsyms.rseq(); if (rargs != null) { int higharg = (int)((IMapEntry)rargs.first()).key(); if (higharg > 0) { for (int i = 1; i <= higharg; ++i) { object sym = argsyms.valAt(i); if (sym == null) { sym = garg(i); } args = args.cons(sym); } } object restsym = argsyms.valAt(-1); if (restsym != null) { args = args.cons(Compiler._AMP_); args = args.cons(restsym); } } return(RT.list(Compiler.FN, args, form)); } finally { Var.popThreadBindings(); } }
public void DefaultCtorReturnsEmptyMap() { PersistentTreeMap m = new PersistentTreeMap(); Expect(m.count(), EqualTo(0)); Expect(m.meta(), Null); }
/// <summary> /// Returns an <see cref="ISeq">ISeq</see> to iterate through the collection in the designated direction starting from a particular key. /// </summary> /// <param name="key">The key at which to start the iteration.</param> /// <param name="ascending">A flag indicating if the iteration is ascending or descending.</param> /// <returns>A sequence for first/rest iteration.</returns> /// <remarks>The key need not be in the collection. If not present, the iteration will start with /// the first element with a key greater than (if asscending) or less than (if descending) the given key.</remarks> public ISeq seqFrom(object key, bool ascending) { PersistentTreeMap m = (PersistentTreeMap)_impl; return(RT.keys(m.seqFrom(key, ascending))); }
/// <summary> /// Returns an <see cref="ISeq">ISeq</see> to iterate through the collection in the designated direction. /// </summary> /// <param name="ascending">A flag indicating if the iteration is ascending or descending.</param> /// <returns>A sequence for first/rest iteration.</returns> public ISeq seq(bool ascending) { PersistentTreeMap m = (PersistentTreeMap)_impl; return(RT.keys(m.seq(ascending))); }
/// <summary> /// Create a <see cref="PersistentTreeMap">PersistentTreeMap</see> from a comparison method /// an <see cref="ISeq">ISeq</see> of alternating keys and values. /// </summary> /// <param name="comp">A comparison method.</param> /// <param name="items">The <see cref="ISeq">ISeq</see> of alternating keys and values.</param> /// <returns>A <see cref="PersistentTreeMap">PersistentTreeMap</see>.</returns> public static PersistentTreeMap create(IComparer comp, ISeq items) { IPersistentMap ret = new PersistentTreeMap(comp); for (; items != null; items = items.rest().rest()) { if (items.rest() == null) throw new ArgumentException(string.Format("No value supplied for key: %s", items.first())); ret = ret.assoc(items.first(), items.rest().first()); } return (PersistentTreeMap)ret; }