Пример #1
0
 /// <summary>constructor</summary>
 /// <param name="owner">parent of index</param>
 /// <param name="getKey">delegate to get key from object</param>
 /// <param name="loadItem">delegate to load object if it is not found in index</param>
 public Index(LruItemCache <TItem> owner, GetKeyFunc <TKey> getKey, LoadItemFunc <TKey> loadItem)
 {
     _owner    = owner;
     _index    = new Dictionary <TKey, WeakReference>(_owner._capacity * 2);
     _getKey   = getKey;
     _loadItem = loadItem;
     RebuildIndex();
 }
Пример #2
0
 /// <summary>constructor</summary>
 /// <param name="owner">parent of index</param>
 /// <param name="getKey">delegate to get key from object</param>
 /// <param name="loadItem">delegate to load object if it is not found in index</param>
 public Index(LRUCache <ItemType> owner, GetKeyFunc <KeyType> getKey, LoadItemFunc <KeyType> loadItem)
 {
     Debug.Assert(owner != null, "owner argument required");
     Debug.Assert(getKey != null, "GetKey delegate required");
     _owner    = owner;
     _index    = new Dictionary <KeyType, WeakReference>(_owner._capacity * 2);
     _getKey   = getKey;
     _loadItem = loadItem;
     RebuildIndex();
 }
Пример #3
0
        /// <summary>Add a new index to the cache</summary>
        /// <typeparam name="KeyType">the type of the key value</typeparam>
        /// <param name="indexName">the name to be associated with this list</param>
        /// <param name="getKey">delegate to get key from object</param>
        /// <param name="loadItem">delegate to load object if it is not found in index</param>
        /// <returns>the newly created index</returns>
        public IIndex <KeyType> AddIndex <KeyType>(String indexName, GetKeyFunc <KeyType> getKey, LoadItemFunc <KeyType> loadItem)
        {
            var index = new Index <KeyType>(this, getKey, loadItem);

            _indexList[indexName] = index;
            return(index);
        }