亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? multidictionary.cs

?? C#寫的類似于STL的集合類,首先是C#編寫,可以用于.net變程.
?? CS
?? 第 1 頁 / 共 2 頁
字號:
?//******************************
// Written by Peter Golde
// Copyright (c) 2004-2005, Wintellect
//
// Use and restribution of this code is subject to the license agreement 
// contained in the file "License.txt" accompanying this file.
//******************************

using System;
using System.Collections;
using System.Collections.Generic;

namespace Wintellect.PowerCollections
{
    /// <summary>
    /// <para>The MultiDictionary class that associates values with a key. Unlike an Dictionary,
    /// each key can have multiple values associated with it. When indexing an MultiDictionary, instead
    /// of a single value associated with a key, you retrieve an enumeration of values.</para>
    /// <para>When constructed, you can chose to allow the same value to be associated with a key multiple
    /// times, or only one time. </para>
    /// </summary>
    /// <typeparam name="TKey">The type of the keys.</typeparam>
    /// <typeparam name="TValue">The of values associated with the keys.</typeparam>
    ///<seealso cref="Dictionary&lt;TKey,TValue&gt;"/>
    ///<seealso cref="OrderedMultiDictionary&lt;TKey,TValue&gt;"/>
    [Serializable]
    public class MultiDictionary<TKey, TValue> : MultiDictionaryBase<TKey, TValue>, ICloneable
    {
        // The comparer for comparing keys
        private IEqualityComparer<TKey> keyEqualityComparer;

        // The comparer for comparing values;
        private IEqualityComparer<TValue> valueEqualityComparer;

        // The comparer for compaing keys and values.
        private IEqualityComparer<KeyAndValues> equalityComparer;

        // The hash that holds the keys and values.
        private Hash<KeyAndValues> hash;

        // Whether duplicate values for the same key are allowed.
        private bool allowDuplicateValues;

        /// <summary>
        /// A structure to hold the key and the values associated with the key.
        /// The number of values must always be 1 or greater in a version that is stored, but 
        /// can be zero in a dummy version used only for lookups.
        /// </summary>
        [Serializable]
        private struct KeyAndValues
        {
            /// <summary>
            /// The key.
            /// </summary>
            public TKey Key;

            /// <summary>
            /// The number of values. Always at least 1 except in a dummy version for lookups.
            /// </summary>
            public int Count;

            /// <summary>
            /// An array of values. 
            /// </summary>
            public TValue[] Values;

            /// <summary>
            /// Create a dummy KeyAndValues with just the key, for lookups.
            /// </summary>
            /// <param name="key">The key to use.</param>
            public KeyAndValues(TKey key)
            {
                this.Key = key;
                this.Count = 0;
                this.Values = null;
            }

            /// <summary>
            /// Make a copy of a KeyAndValues, copying the array.
            /// </summary>
            /// <param name="x">KeyAndValues to copy.</param>
            /// <returns>A copied version.</returns>
            public static KeyAndValues Copy(KeyAndValues x)
            {
                KeyAndValues result;

                result.Key = x.Key;
                result.Count = x.Count;

                if (x.Values != null)
                    result.Values = (TValue[])x.Values.Clone();
                else
                    result.Values = null;

                return result;
            }
        }

        /// <summary>
        /// This class implements IEqualityComparer for KeysAndValues, allowing them to be
        /// compared by their keys. An IEqualityComparer on keys is required.
        /// </summary>
        [Serializable]
        private class KeyAndValuesEqualityComparer : IEqualityComparer<KeyAndValues>
        {
            private IEqualityComparer<TKey> keyEqualityComparer;

            public KeyAndValuesEqualityComparer(IEqualityComparer<TKey> keyEqualityComparer)
            {
                this.keyEqualityComparer = keyEqualityComparer;
            }

            public bool Equals(KeyAndValues x, KeyAndValues y)
            {
                return keyEqualityComparer.Equals(x.Key, y.Key);
            }

            public int GetHashCode(KeyAndValues obj)
            {
                return Util.GetHashCode(obj.Key, keyEqualityComparer);
            }
        }


        #region Constructors

        /// <summary>
        /// Create a new MultiDictionary. The default ordering of keys and values are used. If duplicate values
        /// are allowed, multiple copies of the same value can be associated with the same key. For example, the key "foo"
        /// could have "a", "a", and "b" associated with it. If duplicate values are not allowed, only one copies of a given value can
        /// be associated with the same key, although different keys can have the same value. For example, the key "foo" could
        /// have "a" and "b" associated with it, which key "bar" has values "b" and "c" associated with it.
        /// </summary>
        /// <remarks>The default ordering of keys and values will be used, as defined by TKey and TValue's implementation
        /// of IComparable&lt;T&gt; (or IComparable if IComparable&lt;T&gt; is not implemented). If a different ordering should be
        /// used, other constructors allow a custom Comparer or IComparer to be passed to changed the ordering.</remarks>
        /// <param name="allowDuplicateValues">Can the same value be associated with a key multiple times?</param>
        /// <exception cref="InvalidOperationException">TKey or TValue does not implement either IComparable&lt;T&gt; or IComparable.</exception>
        public MultiDictionary(bool allowDuplicateValues)
            : this(allowDuplicateValues, EqualityComparer<TKey>.Default, EqualityComparer<TValue>.Default)
        {
        }

        /// <summary>
        /// Create a new MultiDictionary. If duplicate values
        /// are allowed, multiple copies of the same value can be associated with the same key. For example, the key "foo"
        /// could have "a", "a", and "b" associated with it. If duplicate values are not allowed, only one copies of a given value can
        /// be associated with the same key, although different keys can have the same value. For example, the key "foo" could
        /// have "a" and "b" associated with it, which key "bar" has values "b" and "c" associated with it.
        /// </summary>
        /// <param name="allowDuplicateValues">Can the same value be associated with a key multiple times?</param>
        /// <param name="keyEqualityComparer">An IEqualityComparer&lt;TKey&gt; instance that will be used to compare keys.</param>
        /// <exception cref="InvalidOperationException">TValue does not implement either IComparable&lt;TValue&gt; or IComparable.</exception>
        public MultiDictionary(bool allowDuplicateValues, IEqualityComparer<TKey> keyEqualityComparer)
            : this(allowDuplicateValues, keyEqualityComparer, EqualityComparer<TValue>.Default)
        {
        }

        /// <summary>
        /// Create a new MultiDictionary. If duplicate values
        /// are allowed, multiple copies of the same value can be associated with the same key. For example, the key "foo"
        /// could have "a", "a", and "b" associated with it. If duplicate values are not allowed, only one copies of a given value can
        /// be associated with the same key, although different keys can have the same value. For example, the key "foo" could
        /// have "a" and "b" associated with it, which key "bar" has values "b" and "c" associated with it.
        /// </summary>
        /// <param name="allowDuplicateValues">Can the same value be associated with a key multiple times?</param>
        /// <param name="keyEqualityComparer">An IEqualityComparer&lt;TKey&gt; instance that will be used to compare keys.</param>
        /// <param name="valueEqualityComparer">An IEqualityComparer&lt;TValue&gt; instance that will be used to compare values.</param>
        public MultiDictionary(bool allowDuplicateValues, IEqualityComparer<TKey> keyEqualityComparer, IEqualityComparer<TValue> valueEqualityComparer)
        {
            if (keyEqualityComparer == null)
                throw new ArgumentNullException("keyEqualityComparer");
            if (valueEqualityComparer == null)
                throw new ArgumentNullException("valueEqualityComparer");

            this.allowDuplicateValues = allowDuplicateValues;
            this.keyEqualityComparer = keyEqualityComparer;
            this.valueEqualityComparer = valueEqualityComparer;
            this.equalityComparer = new KeyAndValuesEqualityComparer(keyEqualityComparer);
            this.hash = new Hash<KeyAndValues>(equalityComparer);
        }

        /// <summary>
        /// Create a new MultiDictionary. Private constructor, for use by Clone().
        /// </summary>
        private MultiDictionary(bool allowDuplicateValues, IEqualityComparer<TKey> keyEqualityComparer, IEqualityComparer<TValue> valueEqualityComparer, IEqualityComparer<KeyAndValues> equalityComparer, Hash<KeyAndValues> hash)
        {
            if (keyEqualityComparer == null)
                throw new ArgumentNullException("keyEqualityComparer");
            if (valueEqualityComparer == null)
                throw new ArgumentNullException("valueEqualityComparer");

            this.allowDuplicateValues = allowDuplicateValues;
            this.keyEqualityComparer = keyEqualityComparer;
            this.valueEqualityComparer = valueEqualityComparer;
            this.equalityComparer = equalityComparer;
            this.hash = hash;
        }


        #endregion Constructors

        #region Add or remove items

        /// <summary>
        /// <para>Adds a new value to be associated with a key. If duplicate values are permitted, this
        /// method always adds a new key-value pair to the dictionary.</para>
        /// <para>If duplicate values are not permitted, and <paramref name="key"/> already has a value
        /// equal to <paramref name="value"/> associated with it, then that value is replaced with <paramref name="value"/>,
        /// and the number of values associate with <paramref name="key"/> is unchanged.</para>
        /// </summary>
        /// <param name="key">The key to associate with.</param>
        /// <param name="value">The value to associated with <paramref name="key"/>.</param>
        public sealed override void Add(TKey key, TValue value)
        {
            KeyAndValues keyValues = new KeyAndValues(key);
            KeyAndValues existing;

            if (hash.Find(keyValues, false, out existing)) {
                // There already is an item in the hash table equal to this key. Add the new value,
                // taking into account duplicates if needed.
                int existingCount = existing.Count;
                if (!allowDuplicateValues) {
                    int valueHash = Util.GetHashCode(value, valueEqualityComparer);
                    for (int i = 0; i < existingCount; ++i) {
                        if (Util.GetHashCode(existing.Values[i], valueEqualityComparer) == valueHash &&
                            valueEqualityComparer.Equals(existing.Values[i], value)) {
                            // Found an equal existing value. Replace it and we're done.
                            existing.Values[i] = value;
                            return;
                        }
                    }
                }

                // Add a new value to an existing key.
                if (existingCount == existing.Values.Length) {
                    // Grow the array to make room.
                    TValue[] newValues = new TValue[existingCount * 2];
                    Array.Copy(existing.Values, newValues, existingCount);
                    existing.Values = newValues;
                }
                existing.Values[existingCount] = value;
                existing.Count = existingCount + 1;

                // Update the hash table.
                hash.Find(existing, true, out keyValues);
                return;
            }
            else {
                // No item with this key. Add it.
                keyValues.Count = 1;
                keyValues.Values = new TValue[1] { value };
                hash.Insert(keyValues, true, out existing);
                return;
            }
        }

        /// <summary>
        /// Removes a given value from the values associated with a key. If the
        /// last value is removed from a key, the key is removed also.
        /// </summary>
        /// <param name="key">A key to remove a value from.</param>
        /// <param name="value">The value to remove.</param>
        /// <returns>True if <paramref name="value"/> was associated with <paramref name="key"/> (and was
        /// therefore removed). False if <paramref name="value"/> was not associated with <paramref name="key"/>.</returns>
        public sealed override bool Remove(TKey key, TValue value)
        {
            KeyAndValues keyValues = new KeyAndValues(key);
            KeyAndValues existing;

            if (hash.Find(keyValues, false, out existing)) {
                // There is an item in the hash table equal to this key. Find the value.
                int existingCount = existing.Count;
                int valueHash = Util.GetHashCode(value, valueEqualityComparer);
                int indexFound = -1;
                for (int i = 0; i < existingCount; ++i) {
                    if (Util.GetHashCode(existing.Values[i], valueEqualityComparer) == valueHash &&
                        valueEqualityComparer.Equals(existing.Values[i], value)) 
                    {
                        // Found an equal existing value
                        indexFound = i;
                    }
                }

                if (existingCount == 1) {
                    // Removing the last value. Remove the key.
                    hash.Delete(existing, out keyValues);
                    return true;
                }
                else if (indexFound >= 0) {
                    // Found a value. Remove it.
                    if (indexFound < existingCount - 1)
                        Array.Copy(existing.Values, indexFound + 1, existing.Values, indexFound, existingCount - indexFound - 1);
                    existing.Count = existingCount - 1;

                    // Update the hash.
                    hash.Find(existing, true, out keyValues);
                    return true;
                }
                else {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人免费毛片片v| 天堂在线亚洲视频| 秋霞电影网一区二区| 成人午夜看片网址| 欧美一区中文字幕| 亚洲色图在线视频| 国产一区二区精品久久99| 欧美日韩国产精选| 国产精品乱人伦一区二区| 美日韩黄色大片| 欧美色图12p| 亚洲人快播电影网| 高清成人免费视频| 久久一日本道色综合| 奇米影视7777精品一区二区| 欧美在线一区二区| 亚洲少妇中出一区| 成人免费高清在线观看| 亚洲精品在线网站| 蜜乳av一区二区三区| 91麻豆精品久久久久蜜臀| 亚洲精品免费看| 91女厕偷拍女厕偷拍高清| 中文字幕第一区二区| 国产伦精一区二区三区| 欧美电影免费观看高清完整版| 亚洲成人在线免费| 欧美午夜在线一二页| 一区二区三区成人| 972aa.com艺术欧美| 中文字幕制服丝袜一区二区三区| 国产福利一区二区| 久久色在线观看| 久久不见久久见免费视频7 | 国产一区高清在线| 日韩欧美国产一区在线观看| 日本美女视频一区二区| 欧美日高清视频| 天堂在线亚洲视频| 91精品国产一区二区人妖| 日日骚欧美日韩| 91精品国产麻豆| 免费看日韩a级影片| 欧美一区二区二区| 美国三级日本三级久久99| 日韩欧美专区在线| 精品一区二区三区免费播放| 2024国产精品| 国产精品一区三区| 欧美经典一区二区| 99免费精品视频| 亚洲制服欧美中文字幕中文字幕| 在线免费观看一区| 三级不卡在线观看| 欧美成人乱码一区二区三区| 毛片av一区二区| 2020国产精品久久精品美国| 粉嫩av一区二区三区在线播放| 国产精品久久午夜夜伦鲁鲁| 不卡免费追剧大全电视剧网站| 亚洲欧洲成人自拍| 精品视频在线免费看| 青椒成人免费视频| 久久久精品免费观看| 99久久精品费精品国产一区二区| 伊人一区二区三区| 欧美一区二区三区啪啪| 国产麻豆视频一区二区| 自拍视频在线观看一区二区| 欧美午夜片在线观看| 久久精品av麻豆的观看方式| 国产三级一区二区| av毛片久久久久**hd| 亚洲va韩国va欧美va精品| 精品日韩av一区二区| 不卡一区二区三区四区| 亚瑟在线精品视频| 久久嫩草精品久久久久| 91在线视频官网| 日韩av高清在线观看| 国产欧美精品一区二区色综合| 色婷婷精品久久二区二区蜜臀av| 天天影视网天天综合色在线播放 | 欧美亚洲国产一区二区三区va| 亚洲第一电影网| wwww国产精品欧美| 91女厕偷拍女厕偷拍高清| 蜜桃一区二区三区在线| 亚洲国产高清不卡| 欧美日本国产一区| 粉嫩av一区二区三区在线播放| 亚洲第一搞黄网站| 亚洲国产电影在线观看| 67194成人在线观看| 成人免费视频一区二区| 亚洲大片免费看| 国产女同性恋一区二区| 欧美日韩成人综合| 成人久久久精品乱码一区二区三区| 亚洲一区二区三区四区在线观看| 精品成a人在线观看| 欧洲激情一区二区| 高清在线不卡av| 强制捆绑调教一区二区| 日韩美女视频19| 精品国产亚洲一区二区三区在线观看| av一本久道久久综合久久鬼色| 日产国产欧美视频一区精品| 亚洲欧洲av一区二区三区久久| 这里只有精品99re| 在线视频国产一区| 成人夜色视频网站在线观看| 日韩国产一区二| 亚洲欧美色一区| 久久久久99精品一区| 666欧美在线视频| 欧美综合视频在线观看| 成人黄色在线视频| 极品少妇xxxx精品少妇| 亚洲一区二区三区视频在线 | 欧美国产一区视频在线观看| 欧美顶级少妇做爰| 色综合色狠狠天天综合色| 国产传媒欧美日韩成人| 美洲天堂一区二卡三卡四卡视频| 亚洲午夜私人影院| 亚洲人成网站影音先锋播放| 久久精品免视看| 精品少妇一区二区三区日产乱码| 欧美日韩国产综合一区二区三区| a美女胸又www黄视频久久| 国产伦精品一区二区三区视频青涩 | 国产精品久久三区| 久久亚洲一区二区三区四区| 777欧美精品| 91精品国产综合久久婷婷香蕉| 在线国产亚洲欧美| 91浏览器打开| av午夜一区麻豆| gogogo免费视频观看亚洲一| 国产99精品在线观看| 精品伊人久久久久7777人| 日韩经典中文字幕一区| 亚洲福利视频三区| 亚洲一区二区黄色| 亚洲激情图片qvod| 亚洲精品五月天| 亚洲免费观看视频| 亚洲色图欧洲色图婷婷| 亚洲视频中文字幕| 亚洲日本va午夜在线影院| 国产精品高潮久久久久无| 中文一区一区三区高中清不卡| 精品欧美一区二区久久| 欧美成人官网二区| 精品国产亚洲在线| 久久久久久久综合日本| 久久久国产精华| 国产欧美一区二区精品性| 国产欧美日韩视频在线观看| 国产欧美日韩三级| 1024成人网| 亚洲精品第一国产综合野| 亚洲激情av在线| 亚洲国产综合色| 亚洲成人黄色影院| 日本不卡一区二区| 久久99日本精品| 国产精品中文字幕欧美| 国产精品18久久久久久vr| 国产高清不卡一区| 91在线观看视频| 欧美亚洲愉拍一区二区| 欧美精品vⅰdeose4hd| 日韩一区二区三区电影| 精品国产免费久久| 国产精品天干天干在观线| 亚洲人成影院在线观看| 午夜精彩视频在线观看不卡| 蜜臀精品一区二区三区在线观看 | 91网站在线观看视频| 在线这里只有精品| 欧美精品在线视频| 精品国产麻豆免费人成网站| 欧美激情在线一区二区三区| 日韩伦理av电影| 丝袜美腿亚洲一区二区图片| 国模冰冰炮一区二区| 国产精品久久久久影院| 亚洲一区在线视频观看| 蜜臀av一区二区在线免费观看 | 久久国内精品自在自线400部| 国产精品1区2区3区在线观看| 91蜜桃网址入口| 欧美一区二区网站| 337p粉嫩大胆色噜噜噜噜亚洲| 国产精品久久久久久久久果冻传媒| 一区二区三区在线视频观看| 麻豆国产精品777777在线| 大美女一区二区三区|