/// <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 key+value added.</returns> /// <remarks>Overwrites an exising value for the <paramref name="key"/>, if present.</remarks> public override IPersistentMap assoc(object key, object val) { Box addedLeaf = new Box(null); INode newroot = _root.assoc(0, Util.Hash(key), key, val, addedLeaf); return(newroot == _root ? this : new PersistentHashMap(meta(), addedLeaf.Val == null ? _count : _count + 1, newroot)); }
/// <summary> /// Remove a key entry. /// </summary> /// <param name="key">The key to remove</param> /// <returns>A new map with the key removed (or the same map if the key is not contained).</returns> public override IPersistentMap without(object key) { INode newroot = _root.without(Util.Hash(key), key); return(newroot == _root ? this : (newroot == null ? (IPersistentMap)EMPTY.withMeta(meta()) : new PersistentHashMap(meta(), _count - 1, newroot))); }
/// <summary> /// Get the hash code for the current object. /// </summary> /// <returns>The hash code.</returns> /// <remarks>Result is cached.</remarks> public override int GetHashCode() { if (_hash == -1) { int hash = 0; for (ISeq s = seq(); s != null; s = s.next()) { hash = Util.HashCombine(hash, Util.Hash(s.first())); } _hash = hash; } return(_hash); }
/// <summary> /// Compute a hash code for the current object. /// </summary> /// <returns>A hash code for the current object.</returns> public override int GetHashCode() { if (_hash == -1) { int hash = 0; for (int i = 0; i < count(); i++) { hash = Util.HashCombine(hash, Util.Hash(nth(i))); } this._hash = hash; } return(_hash); }
/// <summary> /// Computes a hash code for the current object. /// </summary> /// <returns>A hash code for the current object.</returns> /// <remarks>The hash code is value-based (based on the items in the set). /// Once computed, the value is cached.</remarks> public override int GetHashCode() { if (_hash == -1) { int hash = 0; for (ISeq s = seq(); s != null; s = s.next()) { object e = s.first(); hash += Util.Hash(e); } _hash = hash; } return(_hash); }
/// <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 override IMapEntry entryAt(object key) { return((IMapEntry)_root.find(Util.Hash(key), key)); }
/// <summary> /// Compute the hash code for the symbol. /// </summary> /// <returns>The hash code.</returns> private int ComputeHashCode() { return(Util.HashCombine(_name.GetHashCode(), Util.Hash(_ns))); }