Exemplo n.º 1
0
        public TResult GetValue(TInput key)
        {
            TResult value;
            bool    found;

#if !SALTARELLE
            rwl.EnterReadLock();
            try
            {
                found = data.TryGetValue(key, out value);
            }
            finally
            {
                rwl.ExitReadLock();
            }
#else
            value = data[key];
            found = !Script.IsNullOrUndefined(value);
#endif


            if (!found)
            {
                value = evalutor(key);
            }

#if !SALTARELLE
            rwl.EnterWriteLock();
#endif
            try
            {
                if (found)
                {
                    lruList.Remove(key);
                    lruList.Add(key);
                }
                else
                {
                    data[key] = value;
                    lruList.Add(key);

                    if (data.Count > capacity)
                    {
                        data.Remove(lruList.First);
                        lruList.RemoveFirst();
                    }
                }
            }
            finally
            {
#if !SALTARELLE
                rwl.ExitWriteLock();
#endif
            }


            return(value);
        }
Exemplo n.º 2
0
        public TResult GetValue(TInput key)
        {
            TResult value;
            bool    found;

            _rwl.EnterReadLock();
            try
            {
                found = _data.TryGetValue(key, out value);
            }
            finally
            {
                _rwl.ExitReadLock();
            }


            if (!found)
            {
                value = _evalutor(key);
            }

            _rwl.EnterWriteLock();
            try
            {
                if (found)
                {
                    _lruList.Remove(key);
                    _lruList.Add(key);
                }
                else
                {
                    _data[key] = value;
                    _lruList.Add(key);

                    if (_data.Count > _capacity)
                    {
                        Remove(_lruList.First);
                        _lruList.RemoveFirst();
                    }
                }
            }
            finally
            {
                _rwl.ExitWriteLock();
            }


            return(value);
        }
Exemplo n.º 3
0
 public void AddTest()
 {
     var list = new IndexedLinkedList<int> { 1, 0, -1 };
     Assert.AreEqual(3, list.Count, "Did not add the items");
     list.Add(1);
     Assert.AreEqual(4, list.Count, "Did not add the item");
 }
Exemplo n.º 4
0
        public TResult GetValue(TInput key)
        {
            TResult value;
            bool    found;

            lock (_rwl)
            {
                found = _data.TryGetValue(key, out value);
            }

            if (!found)
            {
                value = _evalutor(key);
            }

            lock (_rwl)
            {
                if (found)
                {
                    _lruList.Remove(key);
                    _lruList.Add(key);
                }
                else
                {
                    _data[key] = value;
                    _lruList.Add(key);

                    if (_data.Count > _capacity)
                    {
                        Remove(_lruList.First);
                        _lruList.RemoveFirst();
                    }
                }
            }
            return(value);
        }
Exemplo n.º 5
0
        public void AddMove(IMove move)
        {
            var newItem = new MoveSequenceItem(NextMoveSequenceNumber(), move);

            movesSequence.Add(newItem);
        }