Esempio n. 1
0
        /// <summary>
        ///     Releases the lookup and any key and/or value nodes it contains to their respective pools.
        /// </summary>
        public void Dispose()
        {
            var valuesAcc = new LinkedHeadTail <T>();
            var runner    = keys.head;

            while (runner != null)
            {
                valuesAcc.Append(RemoveValues(runner.value));
                runner = runner.next;
            }

            if (dictionary.Count > 0)
            {
                SmoothLogger.LogWarning("Lookup had dictionary keys that were not in the key list.");
                foreach (var values in dictionary.Values)
                {
                    valuesAcc.Append(values);
                }
                dictionary.Clear();
            }

            keys.Dispose();
            valuesAcc.Dispose();

            lock (pool)
            {
                pool.Push(this);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Appends the specified value to the value list for the specified key.  If the key was previously unmapped it is appended to the key
        ///     list.
        /// </summary>
        public void Add(K key, T value)
        {
            LinkedHeadTail <T> values;

            if (!dictionary.TryGetValue(key, out values))
            {
                keys.Append(key);
            }
            values.Append(value);
            dictionary[key] = values;
        }
Esempio n. 3
0
        /// <summary>
        ///     Returns a list of all the values contained in this lookup and adds the lookup to the disposal queue.
        ///     Items in the list will be ordered based on the ordering of the key list, then by the position within value list for the item's key.
        ///     Ownership of the returned nodes is transferred to the caller, who is responsible for their disposal.
        /// </summary>
        public LinkedHeadTail <T> FlattenAndDispose()
        {
            var values = new LinkedHeadTail <T>();
            var runner = keys.head;

            while (runner != null)
            {
                values.Append(RemoveValues(runner.value));
                runner = runner.next;
            }

            keys.DisposeInBackground();
            DisposeInBackground();

            return(values);
        }