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); }
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); }
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); }
public void IndexedLinkedList_RemoveFirst() { IndexedLinkedList<string> list = new IndexedLinkedList<string>(); list.AddFirst("3"); list.AddFirst("2"); list.AddFirst("1"); Assert.AreEqual("1", list.First); list.RemoveFirst(); Assert.AreEqual("2", list.First); }