src/AnvilPacker/Util/Collections/DictionarySlim.cs
/// <summary>
/// Gets the value for the specified key, or, if the key is not present,
/// adds an entry and returns the value by ref. This makes it possible to
/// add or update a value in a single look up operation.
/// </summary>
/// <param name="key">Key to look for</param>
/// <returns>Reference to the new or existing value</returns>
Gets the value for the specified key, or, if the key is not present,
adds an entry and returns the value by ref. This makes it possible to
add or update a value in a single look up operation.
Gets the value for the specified key or if the key is not present adds an entry and returns the value by ref . This makes it possible to add or update a value in a single look up operation .
public ref TValue GetOrAdd(TKey key)
        {
            if (key == null) ThrowHelper.ThrowKeyArgumentNullException();
            Entry[] entries = _entries;
            int bucketIndex = key.GetHashCode() & (_buckets.Length - 1);
            for (int i = _buckets[bucketIndex] - 1; (uint)i < (uint)entries.Length; i = entries[i].next) {
                if (key.Equals(entries[i].key))
                    return ref entries[i].value;
            }
            return ref AddKey(key, bucketIndex);
        }
public ref TValue GetOrAdd ( TKey key ) { if ( key == null ) ThrowHelper . ThrowKeyArgumentNullException ( ) ; Entry [ ] entries = _entries ; int bucketIndex = key . GetHashCode ( ) & ( _buckets . Length - 1 ) ; for ( int i = _buckets [ bucketIndex ] - 1 ; ( uint ) i < ( uint ) entries . Length ; i = entries [ i ] . next ) { if ( key . Equals ( entries [ i ] . key ) ) return ref entries [ i ] . value ; } return ref AddKey ( key , bucketIndex ) ; }
Gets the value for the specified key, or, if the key is not present,
adds an entry and returns the value by ref.
Gets the value for the specified key or if the key is not present adds an entry and returns the value by ref .
Reference to the new or existing value
Reference to the new or existing value
key
TKey
Key to look for
Key to look for