当前位置: 首页>>代码示例>>C#>>正文


C# SortedSet.Add方法代码示例

本文整理汇总了C#中System.Collections.SortedSet.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.Add方法的具体用法?C# SortedSet.Add怎么用?C# SortedSet.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.SortedSet的用法示例。


在下文中一共展示了SortedSet.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindDuplicateFiles

        public ScanResult FindDuplicateFiles(String dirPath)
        {
            worker.ReportProgress(0, "Preparing files ...");
            FileInfo[] files = new DirectoryInfo(dirPath).GetFiles("*", SearchOption.AllDirectories);
            Array.Sort(files, Comparer<FileInfo>.Create((a,b) => b.FullName.CompareTo(a.FullName)));
            
            int total = files.Length;
            double progress = 0;
            IDictionary<long, IDictionary<FileInfo, IList<FileInfo>>> byteTable = new Dictionary<long, IDictionary<FileInfo, IList<FileInfo>>>();
            foreach (FileInfo file in files) {
                worker.ReportProgress((int)(++progress/total*100), String.Format("Scanning files... ({0}/{1})", progress, total));

                // Compare size
                long fileSize = file.Length;
                if (!byteTable.ContainsKey(fileSize))
                    byteTable.Add(fileSize, new Dictionary<FileInfo, IList<FileInfo>>());
                
                // Compare contents of the files with the same size
                IDictionary<FileInfo, IList<FileInfo>> fileTable = byteTable[fileSize]; // All files in fileMap have the same size
                bool foundDuplicate = false;
                // Compare the current file to each file in fileTable
                foreach (KeyValuePair<FileInfo, IList<FileInfo>> pair in fileTable) {
                    // If find a duplicate, add the file to the duplicate-files-list and break the iteration
                    if (FilesAreEqual(pair.Key, file)) {
                        foundDuplicate = true;
                        pair.Value.Add(file);
                        break;
                    }
                }
                // No duplicate found, create a new entry in fileTable
                if (!foundDuplicate)
                    fileTable.Add(file, new List<FileInfo>());
            }

            // Build the result
            worker.ReportProgress(100, "Build the result ...");
            ScanResult result = new ScanResult();
            int sum = 0;
            foreach (IDictionary<FileInfo, IList<FileInfo>> fileTable in byteTable.Values) {
                foreach (KeyValuePair<FileInfo, IList<FileInfo>> pair in fileTable) {
                    if (pair.Value.Count > 0) {
                        ISet<FileInfo> list = new SortedSet<FileInfo>(Comparer<FileInfo>.Create((a, b) => b.FullName.CompareTo(a.FullName)));
                        list.Add(pair.Key);
                        result.RemoveList.Add(pair.Key, false);
                        foreach (FileInfo file in pair.Value) { 
                            list.Add(file);
                            result.RemoveList.Add(file, true);
                        }
                        result.FileList.Add(pair.Key, list);
                        sum += pair.Value.Count;
                    }
                }
            }
            result.NumDuplicates = sum;
            return result;
        }
开发者ID:smilecatx3,项目名称:DudDuRu,代码行数:56,代码来源:DuplicateFinder.cs

示例2: Add

		public void Add ()
		{
			var set = new SortedSet<int> ();
			Assert.AreEqual (0, set.Count);
			Assert.IsTrue (set.Add (2));
			Assert.IsTrue (set.Add (4));
			Assert.IsTrue (set.Add (3));
			Assert.AreEqual (3, set.Count);
			Assert.IsFalse (set.Add (2));
		}
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:10,代码来源:SortedSetTest.cs

示例3: Remove

		public void Remove ()
		{
			var set = new SortedSet<int> ();
			Assert.IsTrue (set.Add (2));
			Assert.IsTrue (set.Add (4));
			Assert.AreEqual (2, set.Count);
			Assert.IsTrue (set.Remove (4));
			Assert.IsTrue (set.Remove (2));
			Assert.AreEqual (0, set.Count);
			Assert.IsFalse (set.Remove (4));
			Assert.IsFalse (set.Remove (2));
		}
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:12,代码来源:SortedSetTest.cs

示例4: FindPrimesBySieveOfAtkins

        static SortedSet<int> FindPrimesBySieveOfAtkins(int max)
        {
            //  var isPrime = new BitArray((int)max+1, false);
            //  Can't use BitArray because of threading issues.
            var isPrime = new bool[max + 1];
            var sqrt = (int)Math.Sqrt(max);

            Parallel.For(1, sqrt, x =>
            {
                var xx = x * x;
                for (int y = 1; y <= sqrt; y++)
                {
                    var yy = y * y;
                    var n = 4 * xx + yy;
                    if (n <= max && (n % 12 == 1 || n % 12 == 5))
                        isPrime[n] ^= true;

                    n = 3 * xx + yy;
                    if (n <= max && n % 12 == 7)
                        isPrime[n] ^= true;

                    n = 3 * xx - yy;
                    if (x > y && n <= max && n % 12 == 11)
                        isPrime[n] ^= true;
                }
            });

            var primes = new SortedSet<int>() { 2, 3 };
            for (int n = 5; n <= sqrt; n++)
            {
                if (isPrime[n])
                {
                    primes.Add(n);
                    int nn = n * n;
                    for (int k = nn; k <= max; k += nn)
                        isPrime[k] = false;
                }
            }
            try
            {

                for (int n = sqrt + 1; n <= max; n++)
                    if (isPrime[n])
                        primes.Add(n);
            }
            catch (OutOfMemoryException e)
            {

            }

            return primes;
        }
开发者ID:patrickdean,项目名称:euler,代码行数:52,代码来源:Program.cs

示例5: CreateNamesDictionary

    /// <summary>
    /// Creates dictionaries that maps from types full names to 
    /// a suitable collection name. The resulting name is usually
    /// simple the name of the type. When there is more than
    /// one type with the same name, FullName is progressively
    /// perpended to name until there is no ambiguity.
    /// Two dictionaries are generated, one with pluralized last name
    /// and one with singular one.
    /// </summary>
    /// <param name="pPersistables">Types to be translated.</param>
    /// <param name="pSchema">Schema to add names dictionaries.</param>
    private static void CreateNamesDictionary(Type[] pPersistables, ref SchemaInfo pSchema)
    {
      Dictionary<string, string> lPlural;
      SortedSet<string> lSingular = new SortedSet<string>();

      // Initially maps FullName to Name.
      lPlural = pPersistables.ToDictionary(lPersistable => lPersistable.ToGenericTypeString(), lPersistable => lPersistable.Name + "s");
      foreach (Type type in pPersistables)
        lSingular.Add(type.ToGenericTypeString());
      // Solve name clashes.
      pPersistables
          .ToLookup(lPersistable => lPersistable.Name)
          .Where(lGroup => lGroup.Count() > 1)
          .Select(lGroup => SolveNameClash(lGroup))
          .ToList()
          .ForEach(delegate(Dictionary<string, string[]> lSub)
          {
            foreach (KeyValuePair<string, string[]> lPair in lSub)
            {
              // Singular names just join names.
             // lSingular[lPair.Key] = String.Join("_", lPair.Value);
              // Last name gets pluralized for plural names.
              lPair.Value[lPair.Value.Count() - 1] = lPair.Value.Last() + "s";
              lPlural[lPair.Key] = String.Join("_", lPair.Value);

            }
          });
      pSchema.SingularNames = lSingular;
      pSchema.TypesNameToPluralName = lPlural;
    }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:41,代码来源:SchemaExtractor.cs

示例6: ReadSourceFiles

        public static ISet<string> ReadSourceFiles(string pdbPath)
        {
            var clsid = new Guid("3BFCEA48-620F-4B6B-81F7-B9AF75454C7D");
            var type = Type.GetTypeFromCLSID(clsid);
            var source = (DiaSource)Activator.CreateInstance(type);
            source.loadDataFromPdb(pdbPath);

            IDiaSession session;
            source.openSession(out session);

            IDiaEnumTables enumTables;
            session.getEnumTables(out enumTables);

            var result = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);

            foreach (IDiaTable diaEnumTable in enumTables)
            {
                var sourceFiles = diaEnumTable as IDiaEnumSourceFiles;
                if (sourceFiles == null)
                    continue;

                foreach (IDiaSourceFile sourceFile in sourceFiles)
                    result.Add(sourceFile.fileName);
            }

            return result;
        }
开发者ID:NN---,项目名称:nuproj,代码行数:27,代码来源:ReadPdbSourceFiles.cs

示例7: Main

        static void Main(string[] args)
        {
            long[] primes = ESieve(7071);
            long[][] powers = new long[3][];
            int target = 50000000;

            List<long> templist = new List<long>(primes);
            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < primes.Length; i++)
                {
                    templist[i] *= primes[i];
                }
                powers[j] = templist.ToArray();
            }

            SortedSet<long> numbers = new SortedSet<long>();
            for (int i = 0; i < primes.Length; i++)
            {
                for (int j = 0; j < primes.Length; j++)
                {
                    for (int k = 0; k < primes.Length; k++)
                    {
                        long number = powers[0][i] + powers[1][j] + powers[2][k];
                        if (number > target) break;
                        numbers.Add(number);
                    }
                }
            }
            Console.Write(numbers.Count);
            Console.WriteLine();
        }
开发者ID:HaochenLiu,项目名称:My-Project-Euler,代码行数:32,代码来源:087.cs

示例8: BackTrack

        private static SortedSet<string> BackTrack(string s1, string s2, int i, int j, int[,] matrix)
        {
            if (i == 0 || j == 0)
            {
                return new SortedSet<string>() { "" };
            }
            else if (s1[i - 1] == s2[j - 1])
            {
                SortedSet<string> temp = new SortedSet<string>();
                SortedSet<string> holder = BackTrack(s1, s2, i - 1, j - 1, matrix);
                foreach (string str in holder)
                {
                    temp.Add(str + s1[i - 1]);
                }
                return temp;
            }
            else
            {
                SortedSet<string> Result = new SortedSet<string>();
                if (matrix[i - 1, j] >= matrix[i, j - 1])
                {
                    SortedSet<string> holder = BackTrack(s1, s2, i - 1, j, matrix);
                    foreach (string s in holder)
                    {
                        Result.Add(s);
                    }
                }

                if (matrix[i, j - 1] >= matrix[i - 1, j])
                {
                    SortedSet<string> holder = BackTrack(s1, s2, i, j - 1, matrix);
                    foreach (string s in holder)
                    {
                        Result.Add(s);
                    }
                }

                return Result;
            }
        }
开发者ID:tangxuehua,项目名称:textdiff,代码行数:40,代码来源:Program.cs

示例9: Module

        public Module(string name)
        {
            Name     = Helpers.RequireName(name);
            Provides = new SortedSet<string>();
            Requires = new SortedSet<string>();
            Script   = new StringBuilder();
            WorkerId = Worker.Any;

            Provides.Add(name);

            if (name != InitModuleName)
                Requires.Add(InitModuleName);
        }
开发者ID:sharpjs,项目名称:PSql,代码行数:13,代码来源:PSql.ModuleRunner.cs

示例10: GenericStack

        public void GenericStack()
        {
            Stack<Product> stack = new Stack<Product>();
            stack.Push(new Product(001, "mouse stack", 12));
            stack.Push(new Product(002, "cookies", 20));
            Console.WriteLine("\npeek: " + stack.Peek());

            Queue<Product> q = new Queue<Product>();
            q.Enqueue(new Product(001, "mouse q", 12));
            q.Enqueue(new Product(002, "coffee", 4.78));
            Console.WriteLine(q.Peek());

            SortedSet<Product> ss = new SortedSet<Product>(new Product());
            ss.Add(new Product(001, "mouse", 19.78));
            ss.Add(new Product(002, "hello", 200));
            ss.Add(new Product(004, "cup", 4.6));
            ss.Add(new Product(003, "cake", 1.56));
            ss.Add(new Product(005, "tv", 120));
            Console.WriteLine("\nsorted set");
            foreach (Product item in ss)
            {
                Console.WriteLine(item);
            }
        }
开发者ID:naynishchaughule,项目名称:CSharp,代码行数:24,代码来源:Program.cs

示例11: GetArtists

        private static SortedSet<string> GetArtists()
        {
            SortedSet<string> artists = new SortedSet<string>();
            XmlDocument catalogueDocument = new XmlDocument();
            catalogueDocument.Load(XmlCatalogueFilePath);
            XmlNode catalogueNode = catalogueDocument.DocumentElement;

            foreach (XmlNode album in catalogueNode.ChildNodes)
            {
                var xmlElement = album[@"artist"];
                if (xmlElement != null)
                {
                    string artist = xmlElement.InnerText;
                    artists.Add(artist);
                }
            }

            return artists;
        }
开发者ID:GeorgiLambov,项目名称:SoftwareUniversity,代码行数:19,代码来源:ExtractAllDifferentArtists.cs

示例12: OrderedCaseInsensitiveEnumeration

		public void OrderedCaseInsensitiveEnumeration()
		{
			ArrayList expectedOrder = new ArrayList(3);
			expectedOrder.Add("ONE");
			expectedOrder.Add("two");
			expectedOrder.Add("tHree");

			SortedSet<string> theSet = new SortedSet<string>(StringComparer.CurrentCultureIgnoreCase);
			foreach (string str in expectedOrder)
				theSet.Add(str);

			expectedOrder.Sort(StringComparer.CurrentCultureIgnoreCase);

			int index = 0;
			foreach (string str in theSet)
			{
				Assert.AreEqual(str, expectedOrder[index], index.ToString() + " did not have same value");
				index++;
			}
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:20,代码来源:SortedSetFixture.cs

示例13: FilterByPrice

        public IEnumerable<Product> FilterByPrice(double minPrice, double maxPrice)
        {
            var prices = this.allPrices.GetViewBetween(minPrice, maxPrice);

            var filteredProducts = new SortedSet<Product>();

            int taken = 0;

            foreach (var price in prices)
            {
                foreach (var product in this.productsByPrice[price])
                {
                    if (taken == 10)
                    {
                        return filteredProducts;
                    }

                    filteredProducts.Add(product);
                    taken++;
                }
            }

            return filteredProducts;
        }
开发者ID:kaizer04,项目名称:Telerik-Academy-2015-2016,代码行数:24,代码来源:Supermarket.cs

示例14: Open

		/// <summary>
		/// Open
		/// </summary>
		/// <param name="fname"></param>
		public void Open(string fname)
		{
			lock(this.TableBlocking)
			{
				RaiseExceptionIfOpened();
				if(fname.ToLower().EndsWith(".hnd"))
					fname=fname.Substring(0,fname.Length-4);
				DatabaseFilePath=System.IO.Path.GetFullPath(fname)+".hnd";

				// Initial values
				if(!File.Exists(this.DatabaseFilePath))
				{
					try
					{
						fsDB = new FileStream(this.DatabaseFilePath,FileMode.Create,FileAccess.ReadWrite,FileShare.None,8*1024);
					}
					catch
					{
						throw new Exception("Can't create file.");
					}
				}
				else
				{
					try
					{
						fsDB = new FileStream(this.DatabaseFilePath,FileMode.Open,FileAccess.ReadWrite,FileShare.None,8*1024);
					}
					catch
					{
						throw new Exception("Database in use.");
					}
				}
				long len = (fsDB.Length/PageSize); len*=PageSize;
				if(fsDB.Length>len)
				{
					this.LogToFile("Warning","File size fixed.");
					fsDB.SetLength(len);
				}
				slFID2Pages = new SortedList();
				TableName2TID = new Hashtable();
				TID2Def = new Hashtable();
				pcInit();
				//PagesInUse = new SortedSet();
				DeletedPages = new SortedSet();
				br = new BinaryReader(fsDB,System.Text.Encoding.Unicode);
				bw = new BinaryWriter(fsDB,System.Text.Encoding.Unicode);

				// check log file
				if(true)
				{
					string lfn = DatabaseFilePath+".hlg";
					if(File.Exists(lfn))
					{
						FileStream lf = new FileStream(lfn,FileMode.Open,FileAccess.ReadWrite,FileShare.None);
						BinaryReader lfr = new BinaryReader(lf,System.Text.Encoding.Unicode);
						try
						{
							if((lfr.BaseStream.Length>0)&&lfr.ReadBoolean())
							{// recover from last crash
								byte logtype = lfr.ReadByte();
								if(logtype==0)
								{// delete pages op
									this.LogToFile("Warning","Deleted pages fixed.");
									ArrayList al = new ArrayList();
									int cnt = lfr.ReadInt32();
									for(int n=0;n<cnt;n++)
									{
										al.Add( lfr.ReadInt32() );
									}
									for(int n=0;n<cnt;n++)
									{
										bw.BaseStream.Position=PageSize*( (int)al[n] );
										bw.Write( true ); // deleted
									}
									bw.Flush();
									lf.SetLength(0);
									lf.Flush();
								}
								if(logtype==1)
								{// rollback pages
									this.LogToFile("Warning","Rollback modified pages.");
									int pcount = lfr.ReadInt32(); // num of pages

									for(int p=0;p<pcount;p++)
									{
										int page = lfr.ReadInt32();
										fsDB.Position=PageSize*page;
										byte[] buf = lfr.ReadBytes( Database.PageSize );
										bw.Write( buf );
									}

									bw.Flush();
									lf.SetLength(0);
									lf.Flush();
								}
							}
//.........这里部分代码省略.........
开发者ID:Orvid,项目名称:SQLInterfaceCollection,代码行数:101,代码来源:Database.cs

示例15: Permutation

    /// <summary>
    /// Returns n unique random numbers in the range [1, n], inclusive. 
    /// This is equivalent to getting the first n numbers of some random permutation of the sequential numbers from 1 to max. 
    /// Runs in O(k^2) time.
    /// </summary>
    /// <param name="rand"></param>
    /// <param name="n">Maximum number possible.</param>
    /// <param name="k">How many numbers to return.</param>
    /// <returns></returns>
    public static int[] Permutation(this Random rand, int n, int k)
    {
      var result = new List<int>();
      var sorted = new SortedSet<int>();

      for (var i = 0; i < k; i++) {
        var r = rand.Next(1, n + 1 - i);

        foreach (var q in sorted) if (r >= q) r++;

        result.Add(r);
        sorted.Add(r);
      }

      return result.ToArray();
    }
开发者ID:andykras,项目名称:Luke-StarWalker,代码行数:25,代码来源:Rnd.cs


注:本文中的System.Collections.SortedSet.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。