public static int hasheq(object o) { if (o == null) { return(0); } IHashEq ihe = o as IHashEq; if (ihe != null) { return(dohasheq(ihe)); } if (Util.IsNumeric(o)) { return(Numbers.hasheq(o)); } String s = o as string; if (s != null) { return(Murmur3.HashInt(s.GetHashCode())); } return(o.GetHashCode()); }
/// <summary> /// Add a node for a key /// </summary> /// <param name="t"></param> /// <param name="key"></param> /// <param name="val"></param> /// <param name="found"></param> /// <returns></returns> Node Add(Node t, object key, object val, Box found) { if (t == null) { if (_comp == RT.DefaultComparerInstance && !(key == null || Util.IsNumeric(key) || (key is IComparable))) { throw new InvalidCastException("Default comparator requires nil, Number, or Comparable: " + key); } return(val == null ? new Red(key) : new RedVal(key, val)); } int c = DoCompare(key, t.Key); if (c == 0) { found.Val = t; return(null); } Node ins = c < 0 ? Add(t.Left, key, val, found) : Add(t.Right, key, val, found); if (ins == null) { return(null); } return(c < 0 ? t.AddLeft(ins) : t.AddRight(ins)); }
/// <summary> /// Add a new key/value pair. /// </summary> /// <param name="key">The key</param> /// <param name="val">The value</param> /// <returns>A new map with the key/value added.</returns> public virtual Associative assoc(object key, object val) { if (Util.IsNumeric(key)) { int i = Util.ConvertToInt(key); return(assocN(i, val)); } throw new ArgumentException("Key must be an integer"); }
/// <summary> /// Test if the map contains a key. /// </summary> /// <param name="key">The key to test for membership</param> /// <returns>True if the key is in this map.</returns> public virtual bool containsKey(object key) { if (!Util.IsNumeric(key)) { return(false); } int i = Util.ConvertToInt(key); return(i >= 0 && i < count()); }
/// <summary> /// Gets the value associated with a key. /// </summary> /// <param name="key">The key to look up.</param> /// <param name="notFound">The value to return if the key is not present.</param> /// <returns>The associated value (or <c>notFound</c> if the key is not present.</returns> public virtual object valAt(object key, object notFound) { if (Util.IsNumeric(key)) { int i = Util.ConvertToInt(key); if (i >= 0 && i < count()) { return(nth(i)); } } return(notFound); }
/// <summary> /// Returns the key/value pair for this key. /// </summary> /// <param name="key">The key to retrieve</param> /// <returns>The key/value pair for the key, or null if the key is not in the map.</returns> public virtual IMapEntry entryAt(object key) { if (Util.IsNumeric(key)) { int i = Util.ConvertToInt(key); if (i >= 0 && i < count()) { return(MapEntry.create(key, nth(i))); } } return(null); }
public override int IndexOf(object value) { if (Util.IsNumeric(value)) { T v = ConvertNum(value); for (int j = _i; j < _array.Length; j++) { if (v.Equals(_array[j])) { return(j - _i); } } } return(-1); }
public static int hasheq(object o) { if (o == null) { return(0); } IHashEq ihe = o as IHashEq; if (ihe != null) { return(dohasheq(ihe)); } if (Util.IsNumeric(o)) { return(Numbers.hasheq(o)); } return(o.GetHashCode()); }
protected override object Read(PushbackTextReader r, char pct) { int ch = r.Read(); Unread(r, ch); //% alone is first arg if (ch == -1 || isWhitespace(ch) || isTerminatingMacro(ch)) { return(registerArg(1)); } //object n = ReadAux(r, true, null, true); object n = ReadAux(r); if (n.Equals(Compiler._AMP_)) { return(registerArg(-1)); } if (!Util.IsNumeric(n)) { throw new ArgumentException("arg literal must be %, %& or %integer"); } return(registerArg(Util.ConvertToInt(n))); }
static object syntaxQuote(object form) { object ret; if (Compiler.isSpecial(form)) { ret = RT.list(Compiler.QUOTE, form); } else if (form is Symbol) { Symbol sym = (Symbol)form; if (sym.Namespace == null && sym.Name.EndsWith("#")) { IPersistentMap gmap = (IPersistentMap)GENSYM_ENV.deref(); if (gmap == null) { throw new InvalidDataException("Gensym literal not in syntax-quote"); } Symbol gs = (Symbol)gmap.valAt(sym); if (gs == null) { GENSYM_ENV.set(gmap.assoc(sym, gs = Symbol.intern(null, sym.Name.Substring(0, sym.Name.Length - 1) + "__" + RT.nextID() + "__auto__"))); } sym = gs; } else if (sym.Namespace == null && sym.Name.EndsWith(".")) { Symbol csym = Symbol.intern(null, sym.Name.Substring(0, sym.Name.Length - 1)); csym = Compiler.resolveSymbol(csym); sym = Symbol.intern(null, csym.Name + "."); } else if (sym.Namespace == null && sym.Name.StartsWith(".")) { // simply quote method names } else { sym = Compiler.resolveSymbol(sym); } ret = RT.list(Compiler.QUOTE, sym); } //else if (form is Unquote) // return ((Unquote)form).Obj; // Rev 1184 else if (isUnquote(form)) { return(RT.second(form)); } else if (isUnquoteSplicing(form)) { throw new ArgumentException("splice not in list"); } else if (form is IPersistentCollection) { if (form is IPersistentMap) { IPersistentVector keyvals = flattenMap(form); ret = RT.list(APPLY, HASHMAP, RT.list(SEQ, RT.cons(CONCAT, sqExpandList(keyvals.seq())))); } else if (form is IPersistentVector) { ret = RT.list(APPLY, VECTOR, RT.list(SEQ, RT.cons(CONCAT, sqExpandList(((IPersistentVector)form).seq())))); } else if (form is IPersistentSet) { ret = RT.list(APPLY, HASHSET, RT.list(SEQ, RT.cons(CONCAT, sqExpandList(((IPersistentSet)form).seq())))); } else if (form is ISeq || form is IPersistentList) { ISeq seq = RT.seq(form); if (seq == null) { ret = RT.cons(LIST, null); } else { ret = RT.list(SEQ, RT.cons(CONCAT, sqExpandList(seq))); } } else { throw new InvalidOperationException("Unknown Collection type"); } } else if (form is Keyword || Util.IsNumeric(form) || form is Char || form is String) { ret = form; } else { ret = RT.list(Compiler.QUOTE, form); } if (form is IObj && RT.meta(form) != null) { //filter line numbers IPersistentMap newMeta = ((IObj)form).meta().without(RT.LINE_KEY); if (newMeta.count() > 0) { return(RT.list(WITH_META, ret, syntaxQuote(((IObj)form).meta()))); } } return(ret); }
public override int IndexOf(object value) { return(Util.IsNumeric(value) ? base.IndexOf(value) : -1); }