Esempio n. 1
0
        public TValue this[TKey key]
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get
            {
                var oldValObj = _table.TryGetValue(key);

                Debug.Assert(!(oldValObj is DictionaryImpl.Prime));

                if (oldValObj != null)
                {
                    // PERF: this would be nice to have as a helper,
                    // but it does not get inlined
                    TValue value;
                    if (default(TValue) == null && oldValObj == DictionaryImpl.NULLVALUE)
                    {
                        value = default(TValue);
                    }
                    else
                    {
                        value = (TValue)oldValObj;
                    }

                    return(value);
                }

                return(ThrowKeyNotFound());
            }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            set
            {
                object oldValObj = null;
                var    newValObj = DictionaryImpl.ToObjectValue(value);
                _table.PutIfMatch(key, newValObj, ref oldValObj, DictionaryImpl.ValueMatch.Any);
            }
        }
            public bool MoveNext()
            {
                if (_nextV == NULLVALUE)
                {
                    return(false);
                }

                _curKey   = _nextK;
                _curValue = _nextV;
                _nextV    = NULLVALUE;

                var entries = _table._entries;

                while (_idx < entries.Length)
                {
                    // Scan array
                    var nextEntry = entries[_idx++];

                    if (nextEntry.value != null)
                    {
                        var nextK = _table.keyFromEntry(nextEntry.key);

                        var nextV = _table.TryGetValue(nextK);
                        if (nextV != null)
                        {
                            _nextK = nextK;

                            // PERF: this would be nice to have as a helper,
                            // but it does not get inlined
                            if (default(TValue) == null && nextV == NULLVALUE)
                            {
                                _nextV = default(TValue);
                            }
                            else
                            {
                                _nextV = (TValue)nextV;
                            }


                            break;
                        }
                    }
                }

                return(_curValue != NULLVALUE);
            }