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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? redblack.cs

?? C#寫的類似于STL的集合類,首先是C#編寫,可以用于.net變程.
?? CS
?? 第 1 頁 / 共 4 頁
字號:
//******************************
// 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.Diagnostics;
using System.Collections.Generic;


namespace Wintellect.PowerCollections 
{
    /// <summary>
    /// Describes what to do if a key is already in the tree when doing an
    /// insertion.
    /// </summary>
    internal enum DuplicatePolicy { 
        InsertFirst,               // Insert a new node before duplicates
        InsertLast,               // Insert a new node after duplicates
        ReplaceFirst,            // Replace the first of the duplicate nodes
        ReplaceLast,            // Replace the last of the duplicate nodes
        DoNothing                // Do nothing to the tree
    };

	/// <summary>
	/// The base implementation for various collections classes that use Red-Black trees
	/// as part of their implementation. This class should not (and can not) be 
	/// used directly by end users; it's only for internal use by the collections package.
	/// </summary>
	/// <remarks>
	/// The Red-Black tree manages items of type T, and uses a IComparer&lt;T&gt; that
	/// compares items to sort the tree. Multiple items can compare equal and be stored
	/// in the tree. Insert, Delete, and Find operations are provided in their full generality;
	/// all operations allow dealing with either the first or last of items that compare equal. 
	///</remarks>
    [Serializable]
	internal class RedBlackTree<T>: IEnumerable<T> {
		private IComparer<T> comparer;			// interface for comparing elements, only Compare is used.
		private Node root;					// The root of the tree. Can be null when tree is empty.
		private int count;						// The count of elements in the tree.

        private int changeStamp;        // An integer that is changed every time the tree structurally changes.
                                                        // Used so that enumerations throw an exception if the tree is changed
                                                        // during enumeration.

        private Node[] stack;               // A stack of nodes. This is cached locally to avoid constant re-allocated it.

        /// <summary>
        /// Create an array of Nodes big enough for any path from top 
        /// to bottom. This is cached, and reused from call-to-call, so only one
        /// can be around at a time per tree.
        /// </summary>
        /// <returns>The node stack.</returns>
        private Node[] GetNodeStack()
        {
            // Maximum depth needed is 2 * lg count + 1.
            int maxDepth;
            if (count < 0x400)
                maxDepth = 21;
            else if (count < 0x10000)
                maxDepth = 41;
            else
                maxDepth = 65;

            if (stack == null || stack.Length < maxDepth)
                stack = new Node[maxDepth];

            return stack;
        }

        /// <summary>
		/// The class that is each node in the red-black tree.
		/// </summary>
        [Serializable]
		private class Node {
			public Node left, right;
			public T item;

            private const uint REDMASK = 0x80000000;
            private uint count;

            /// <summary>
            /// Is this a red node?
            /// </summary>
            public bool IsRed {
                get { return (count & REDMASK) != 0; }
                set { 
                    if (value) 
                        count |= REDMASK; 
                    else
                        count &= ~REDMASK;
                }
            }

            /// <summary>
            /// Get or set the Count field -- a 31-bit field
            /// that holds the number of nodes at or below this
            /// level.
            /// </summary>
            public int Count
            {
                get { return (int)(count & ~REDMASK); }
                set { count = (count & REDMASK) | (uint)value; }
            }

            /// <summary>
            /// Add one to the Count.
            /// </summary>
            public void IncrementCount()
            {
                ++count;
            }

            /// <summary>
            /// Subtract one from the Count. The current
            /// Count must be non-zero.
            /// </summary>
            public void DecrementCount()
            {
                Debug.Assert(Count != 0);
                --count;
            }

            /// <summary>
            /// Clones a node and all its descendants.
            /// </summary>
            /// <returns>The cloned node.</returns>
            public Node Clone()
            {
                Node newNode = new Node();
                newNode.item = item;

                newNode.count = count;

                if (left != null)
                    newNode.left = left.Clone();

                if (right != null)
                    newNode.right = right.Clone();

                return newNode;
            }
        }

        /// <summary>
        /// Must be called whenever there is a structural change in the tree. Causes
        /// changeStamp to be changed, which causes any in-progress enumerations
        /// to throw exceptions.
        /// </summary>
        internal void StopEnumerations()
        {
            ++changeStamp;
        }

        /// <summary>
        /// Checks the given stamp against the current change stamp. If different, the
        /// collection has changed during enumeration and an InvalidOperationException
        /// must be thrown
        /// </summary>
        /// <param name="startStamp">changeStamp at the start of the enumeration.</param>
        private void CheckEnumerationStamp(int startStamp)
        {
            if (startStamp != changeStamp) {
                throw new InvalidOperationException(Strings.ChangeDuringEnumeration);
            }
        }

        /// <summary>
		/// Initialize a red-black tree, using the given interface instance to compare elements. Only
		/// Compare is used on the IComparer interface.
		/// </summary>
		/// <param name="comparer">The IComparer&lt;T&gt; used to sort keys.</param>
		public RedBlackTree(IComparer<T> comparer) {
			this.comparer = comparer;
			this.count = 0;
			this.root = null;
		}

		/// <summary>
		/// Returns the number of elements in the tree.
		/// </summary>
		public int ElementCount {
			get {
				return count;
			}
		}

        /// <summary>
        /// Clone the tree, returning a new tree containing the same items. Should
        /// take O(N) take.
        /// </summary>
        /// <returns>Clone version of this tree.</returns>
        public RedBlackTree<T> Clone()
        {
            RedBlackTree<T> newTree = new RedBlackTree<T>(comparer);
            newTree.count = this.count;
            if (this.root != null)
                newTree.root = this.root.Clone();
            return newTree;
        }

		/// <summary>
		/// Finds the key in the tree. If multiple items in the tree have
		/// compare equal to the key, finds the first or last one. Optionally replaces the item
		/// with the one searched for.
		/// </summary>
		/// <param name="key">Key to search for.</param>
		/// <param name="findFirst">If true, find the first of duplicates, else finds the last of duplicates.</param>
        /// <param name="replace">If true, replaces the item with key (if function returns true)</param>
        /// <param name="item">Returns the found item, before replacing (if function returns true).</param>
        /// <returns>True if the key was found.</returns>
		public bool Find(T key, bool findFirst, bool replace, out T item) {
			Node current = root;			// current search location in the tree
			Node found = null;			// last node found with the key, or null if none.
			
			while (current != null) {
				int compare = comparer.Compare(key, current.item);

				if (compare < 0) {
					current = current.left;
				}
				else if (compare > 0) {
					current = current.right;
				}
				else {
					// Go left/right on equality to find first/last of elements with this key.
					Debug.Assert(compare == 0);
					found = current;
					if (findFirst)
						current = current.left;
					else
						current = current.right;
				}
			}

			if (found != null) {
				item = found.item;
                if (replace)
                    found.item = key;
                return true;
			}
			else {
				item = default(T);	
				return false;
			}
		}

        /// <summary>
        /// Finds the index of the key in the tree. If multiple items in the tree have
        /// compare equal to the key, finds the first or last one. 
        /// </summary>
        /// <param name="key">Key to search for.</param>
        /// <param name="findFirst">If true, find the first of duplicates, else finds the last of duplicates.</param>
        /// <returns>Index of the item found if the key was found, -1 if not found.</returns>
        public int FindIndex(T key, bool findFirst)
        {
            T dummy;
            if (findFirst)
                return FirstItemInRange(EqualRangeTester(key), out dummy);
            else
                return LastItemInRange(EqualRangeTester(key), out dummy);
        }

        /// <summary>
        /// Find the item at a particular index in the tree.
        /// </summary>
        /// <param name="index">The zero-based index of the item. Must be &gt;= 0 and &lt; Count.</param>
        /// <returns>The item at the particular index.</returns>
        public T GetItemByIndex(int index)
        {
            if (index < 0 || index >= count)
                throw new ArgumentOutOfRangeException("index");

			Node current = root;			// current search location in the tree

            for (; ; ) {
                int leftCount;

                if (current.left != null) 
                    leftCount = current.left.Count;
                else 
                    leftCount = 0;

                if (leftCount > index)
                    current = current.left;
                else if (leftCount == index)
                    return current.item;
                else {
                    index -= leftCount + 1;
                    current = current.right;
                }
            }
		}

		/// <summary>
		/// Insert a new node into the tree, maintaining the red-black invariants.
		/// </summary>
		/// <remarks>Algorithm from Sedgewick, "Algorithms".</remarks>
		/// <param name="item">The new item to insert</param>
		/// <param name="dupPolicy">What to do if equal item is already present.</param>
		/// <param name="previous">If false, returned, the previous item.</param>
		/// <returns>false if duplicate exists, otherwise true.</returns>
		public bool Insert(T item, DuplicatePolicy dupPolicy, out T previous) {
			Node node = root;
			Node parent = null, gparent = null, ggparent = null;	// parent, grand, a great-grantparent of node.
			bool wentLeft = false, wentRight = false;				// direction from parent to node.
            bool rotated;
			Node duplicateFound = null;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区久久久| 国产在线播精品第三| 欧美激情一区二区三区蜜桃视频| 欧美高清视频一二三区| 欧美主播一区二区三区美女| 色综合视频一区二区三区高清| 成熟亚洲日本毛茸茸凸凹| thepron国产精品| 成人动漫一区二区在线| 91在线观看一区二区| 99re视频这里只有精品| 欧美性大战xxxxx久久久| 欧美男男青年gay1069videost | 国产精品无人区| 中文字幕一区免费在线观看| 欧美高清在线视频| 中文字幕的久久| 国产精品久久久久久久久晋中| 国产精品麻豆一区二区 | 亚洲精品成人在线| 亚洲男人的天堂在线aⅴ视频| 一区在线观看视频| 亚洲午夜成aⅴ人片| 日本不卡视频在线观看| 国产一区二区精品在线观看| 99亚偷拍自图区亚洲| 欧美日韩一区高清| 久久免费的精品国产v∧| 亚洲欧美另类在线| 麻豆成人在线观看| 91免费国产视频网站| 欧美一区二区三区免费视频| 久久久国产精品午夜一区ai换脸| 综合久久久久久久| 五月天国产精品| 国产99精品国产| 欧美精品1区2区| 亚洲精品自拍动漫在线| 午夜成人免费视频| av亚洲产国偷v产偷v自拍| 欧美日韩一级大片网址| 国产欧美综合在线| 全部av―极品视觉盛宴亚洲| 成人av资源下载| 日韩美女一区二区三区四区| 国产精品久久久久婷婷| 久久99久久99小草精品免视看| 91啪九色porn原创视频在线观看| 日韩欧美在线一区二区三区| 亚洲色图视频网站| 国产黄色精品视频| 日韩欧美一卡二卡| 亚洲r级在线视频| 91亚洲国产成人精品一区二三| 精品国产欧美一区二区| 亚洲成人精品影院| 色网综合在线观看| 中文字幕一区二区三区不卡| 国产在线播放一区三区四| 欧美精品丝袜中出| 国产精品视频一二三区| 在线视频你懂得一区二区三区| 久久日一线二线三线suv| 日韩高清国产一区在线| 欧美午夜精品理论片a级按摩| 国产精品久久久久国产精品日日 | 欧美日韩一区久久| 亚洲欧美色综合| 粉嫩aⅴ一区二区三区四区| 精品久久久久一区| 蜜桃久久久久久久| 日韩精品自拍偷拍| 精品一区免费av| 精品少妇一区二区| 美女网站一区二区| 日韩欧美激情四射| 日韩不卡免费视频| 91精品国产综合久久蜜臀| 亚洲午夜国产一区99re久久| 在线观看免费一区| 婷婷一区二区三区| 欧美日韩国产免费一区二区| 一区二区三区精品| 欧美美女一区二区在线观看| 亚洲桃色在线一区| 国产福利一区二区三区视频在线| 337p粉嫩大胆色噜噜噜噜亚洲 | 日韩精品午夜视频| 日韩一区二区三区电影在线观看 | 国产一区二区三区四| 91精品国产高清一区二区三区 | 中文一区二区在线观看| 波多野结衣中文字幕一区| 1区2区3区国产精品| 91免费观看国产| 亚欧色一区w666天堂| 日韩欧美高清dvd碟片| 国产精品亚洲人在线观看| 国产精品麻豆久久久| 欧美亚洲一区三区| 激情图区综合网| 最新久久zyz资源站| 久久综合给合久久狠狠狠97色69| 国产黄色精品视频| 亚洲精品亚洲人成人网 | 日韩一区二区三区电影在线观看| 丝袜美腿亚洲一区二区图片| 精品人伦一区二区色婷婷| 高清国产一区二区| 日韩高清国产一区在线| 国产女主播一区| 69成人精品免费视频| 9i在线看片成人免费| 秋霞影院一区二区| 亚洲欧美日韩系列| 2023国产精品| 欧美日本一道本| 91免费看片在线观看| 国产一区二区三区四区五区入口| 亚洲在线一区二区三区| 国产亚洲成aⅴ人片在线观看| 欧美综合色免费| 懂色av一区二区三区免费观看| 亚洲亚洲精品在线观看| 欧美国产一区在线| 精品美女在线观看| 欧美人xxxx| 精品婷婷伊人一区三区三| 国产二区国产一区在线观看| 免费精品视频最新在线| 亚洲成a人片综合在线| 中文字幕视频一区| 国产日韩欧美综合在线| 精品伦理精品一区| 91麻豆精品国产91久久久更新时间| 成人午夜精品在线| 国产成人8x视频一区二区 | 日韩你懂的在线播放| 91黄色免费版| 99久久精品免费看国产| 国产成人av一区二区三区在线| 午夜精品久久久久影视| 亚洲免费观看高清完整版在线观看熊 | 久久精品国产澳门| 亚洲一区在线观看免费| 亚洲色图色小说| 中文子幕无线码一区tr| 欧美国产一区在线| 国产拍欧美日韩视频二区| 91超碰这里只有精品国产| 欧美三级日韩三级| 欧美日韩不卡一区二区| 欧美日韩亚洲综合一区二区三区| 欧美午夜不卡在线观看免费| 欧美午夜一区二区三区免费大片| 日本韩国一区二区三区视频| 91久久精品日日躁夜夜躁欧美| 91丨porny丨蝌蚪视频| 一本色道久久综合亚洲91 | 亚洲精品老司机| 亚洲国产乱码最新视频| 婷婷国产v国产偷v亚洲高清| 欧美变态口味重另类| 欧美日韩精品免费| 日韩一区二区精品| www久久久久| 亚洲欧洲日韩一区二区三区| 日韩毛片精品高清免费| 亚洲精品中文字幕乱码三区 | 久久精品国产网站| 国产一区二区三区精品视频| 国产91在线观看丝袜| 色av一区二区| 精品蜜桃在线看| 国产精品超碰97尤物18| 夜色激情一区二区| 日本欧美肥老太交大片| 亚洲mv大片欧洲mv大片精品| 日本美女视频一区二区| 国产精品福利一区二区三区| 亚洲视频在线观看三级| 一个色在线综合| 蜜桃视频一区二区| 不卡视频免费播放| 欧美一区永久视频免费观看| 国产精品污www在线观看| 精品久久久久久久人人人人传媒 | 亚洲麻豆国产自偷在线| 8x8x8国产精品| 欧美探花视频资源| 91蝌蚪porny| 精品久久一二三区| 亚洲一区视频在线观看视频| 国产一区二区精品久久99| 91亚洲国产成人精品一区二区三| 欧美肥大bbwbbw高潮| 国产日韩欧美一区二区三区乱码 | 日韩欧美一区二区在线视频| 国产精品人妖ts系列视频| 日韩国产高清在线|