Esempio n. 1
0
        public virtual void put(K key, V value)
        {
            if (key == default(K) || value == default(V))
            {
                throw new System.NullReferenceException();
            }

            V previousValue = cache.put(key, value);

            if (previousValue != default(V))
            {
                keys.remove(key);
            }
            keys.add(key);

            if (cache.size() > capacity)
            {
                K lruKey = keys.poll();
                if (lruKey != default(K))
                {
                    cache.remove(lruKey);

                    // remove duplicated keys
                    this.removeAll(lruKey);

                    // queue may not contain any key of a possibly concurrently added entry of the same key in the cache
                    if (cache.containsKey(lruKey))
                    {
                        keys.add(lruKey);
                    }
                }
            }
        }
Esempio n. 2
0
        private static sbyte[][] SortedUpdates <Key>(KeyFormat <Key> keys, ConcurrentMap <Key, ChangeEntry> changes)
        {
            Entry[] buffer = new Entry[changes.size()];
            IEnumerator <KeyValuePair <Key, ChangeEntry> > entries = changes.entrySet().GetEnumerator();

            for (int i = 0; i < buffer.Length; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                KeyValuePair <Key, ChangeEntry> next = entries.next();                        // we hold the lock, so this should succeed
                sbyte[] key = new sbyte[keys.KeySize()];
                keys.WriteKey(next.Key, new BigEndianByteArrayBuffer(key));
                buffer[i] = new Entry(key, next.Value.data);
            }
            Arrays.sort(buffer);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            Debug.Assert(!entries.hasNext(), "We hold the lock, so we should see 'size' entries.");
            sbyte[][] result = new sbyte[buffer.Length * 2][];
            for (int i = 0; i < buffer.Length; i++)
            {
                result[i * 2]     = buffer[i].Key;
                result[i * 2 + 1] = buffer[i].Value;
            }
            return(result);
        }