Exemplo n.º 1
0
 private long GetIfAbsentPutForSentinelKey(long key, LongFunction0 supplier)
 {
     if (key == EMPTY_KEY)
     {
         if (!_hasZeroKey)
         {
             ++_modCount;
             _hasZeroKey = true;
             _zeroValue  = supplier.value();
         }
         return(_zeroValue);
     }
     if (key == REMOVED_KEY)
     {
         if (!_hasOneKey)
         {
             ++_modCount;
             _hasOneKey = true;
             _oneValue  = supplier.value();
         }
         return(_oneValue);
     }
     throw new AssertionError("Invalid sentinel key: " + key);
 }
Exemplo n.º 2
0
        public override long GetIfAbsentPut(long key, LongFunction0 supplier)
        {
            if (IsSentinelKey(key))
            {
                return(GetIfAbsentPutForSentinelKey(key, supplier));
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int idx = indexOf(key);
            int idx = IndexOf(key);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long keyAtIdx = getKeyAt(idx);
            long keyAtIdx = GetKeyAt(idx);

            if (keyAtIdx == key)
            {
                return(GetValueAt(idx));
            }

            ++_modCount;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long value = supplier.value();
            long value = supplier.value();

            if (keyAtIdx == REMOVED_KEY)
            {
                --_removals;
            }

            SetKeyAt(idx, key);
            SetValueAt(idx, value);

            ++_entriesInMemory;
            if (_entriesInMemory >= _resizeOccupancyThreshold)
            {
                GrowAndRehash();
            }

            return(value);
        }