示例#1
0
        /// <summary>
        /// Adds a new key-value pair to this bucket. The key-value pair's
        /// key must not be present in the bucket yet.
        /// </summary>
        /// <param name="kvPair">The key-value pair to add.</param>
        public void Add(
            HashedKeyValuePair <WeakReference <TKey>, WeakReference <TValue> > kvPair)
        {
            if (!IsEmpty)
            {
                var newSpilloverlist = new WeakCacheBucketNode <TKey, TValue>(this);
                this.spilloverList = newSpilloverlist;
            }

            this.keyValuePair = kvPair;
        }
示例#2
0
        /// <summary>
        /// Cleans up all dead key-value pairs in this bucket.
        /// </summary>
        public void Cleanup()
        {
            TKey   kvPairKey;
            TValue kvPairValue;

            if (!TryIsolateFirstLiveEntry(out kvPairKey, out kvPairValue))
            {
                return;
            }

            if (spilloverList != null)
            {
                var newSpilloverContents = spilloverList.contents;
                newSpilloverContents.Cleanup();
                if (newSpilloverContents.IsEmpty)
                {
                    spilloverList = null;
                }
                else
                {
                    spilloverList.contents = newSpilloverContents;
                }
            }
        }