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


C# SortedSet.GetEnumerator方法代码示例

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


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

示例1: LevenshteinAutomata

        /// <summary>
        /// Expert: specify a custom maximum possible symbol
        /// (alphaMax); default is Character.MAX_CODE_POINT.
        /// </summary>
        public LevenshteinAutomata(int[] word, int alphaMax, bool withTranspositions)
        {
            this.Word = word;
            this.AlphaMax = alphaMax;

            // calculate the alphabet
            SortedSet<int> set = new SortedSet<int>();
            for (int i = 0; i < word.Length; i++)
            {
                int v = word[i];
                if (v > alphaMax)
                {
                    throw new System.ArgumentException("alphaMax exceeded by symbol " + v + " in word");
                }
                set.Add(v);
            }
            Alphabet = new int[set.Count];
            IEnumerator<int> iterator = set.GetEnumerator();
            for (int i = 0; i < Alphabet.Length; i++)
            {
                iterator.MoveNext();
                Alphabet[i] = iterator.Current;
            }

            RangeLower = new int[Alphabet.Length + 2];
            RangeUpper = new int[Alphabet.Length + 2];
            // calculate the unicode range intervals that exclude the alphabet
            // these are the ranges for all unicode characters not in the alphabet
            int lower = 0;
            for (int i = 0; i < Alphabet.Length; i++)
            {
                int higher = Alphabet[i];
                if (higher > lower)
                {
                    RangeLower[NumRanges] = lower;
                    RangeUpper[NumRanges] = higher - 1;
                    NumRanges++;
                }
                lower = higher + 1;
            }
            /* add the final endpoint */
            if (lower <= alphaMax)
            {
                RangeLower[NumRanges] = lower;
                RangeUpper[NumRanges] = alphaMax;
                NumRanges++;
            }

            Descriptions = new ParametricDescription[] {
            null,
            withTranspositions ? (ParametricDescription)new Lev1TParametricDescription(word.Length) : new Lev1ParametricDescription(word.Length),
            withTranspositions ? (ParametricDescription)new Lev2TParametricDescription(word.Length) : new Lev2ParametricDescription(word.Length)
        };
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:58,代码来源:LevenshteinAutomata.cs

示例2: TestCopyConstructor2

        public static void TestCopyConstructor2()
        {
            SortedSet<int> sortedSet = new SortedSet<int>();

            List<int> listOfItems = new List<int>();
            int c = 0;
            while (sortedSet.Count < 100000)
            {
                c++;
                if (!sortedSet.Contains(50000 - c))
                {
                    sortedSet.Add(50000 - c);
                    listOfItems.Add(50000 - c);
                }
            }

            SortedSet<int> newTree1 = new SortedSet<int>(listOfItems);

            Assert.True(newTree1.SetEquals(listOfItems)); //"Expected to be the same set."

            SortedSet<int> newTree2 = new SortedSet<int>(sortedSet);

            Assert.True(newTree2.SetEquals(sortedSet)); //"Expected to be the same set."

            IEnumerator<int> t1 = sortedSet.GetEnumerator();
            IEnumerator<int> t2 = newTree1.GetEnumerator();
            IEnumerator<int> t3 = newTree2.GetEnumerator();

            while (t1.MoveNext())
            {
                t2.MoveNext();
                t3.MoveNext();

                Assert.Equal(t1.Current, t2.Current); //"Not fully constructed"
                Assert.Equal(t2.Current, t3.Current); //"Not fullu constructed."
            }

            sortedSet.Clear();
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:39,代码来源:SortedSetSpecificTests.cs

示例3: TestRandom

        public virtual void TestRandom()
        {
            SortedSet<Term> terms = new SortedSet<Term>();
            int nterms = AtLeast(10000);
            for (int i = 0; i < nterms; i++)
            {
                Term term = new Term(TestUtil.RandomUnicodeString(Random(), 2), TestUtil.RandomUnicodeString(Random()));
                terms.Add(term);
            }

            PrefixCodedTerms.Builder b = new PrefixCodedTerms.Builder();
            foreach (Term @ref in terms)
            {
                b.Add(@ref);
            }
            PrefixCodedTerms pb = b.Finish();

            IEnumerator<Term> expected = terms.GetEnumerator();
            foreach (Term t in pb)
            {
                Assert.IsTrue(expected.MoveNext());
                Assert.AreEqual(expected.Current, t);
            }
            Assert.IsFalse(expected.MoveNext());
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:25,代码来源:TestPrefixCodedTerms.cs

示例4: TestMergeRandom

        public virtual void TestMergeRandom()
        {
            PrefixCodedTerms[] pb = new PrefixCodedTerms[TestUtil.NextInt(Random(), 2, 10)];
            SortedSet<Term> superSet = new SortedSet<Term>();

            for (int i = 0; i < pb.Length; i++)
            {
                SortedSet<Term> terms = new SortedSet<Term>();
                int nterms = TestUtil.NextInt(Random(), 0, 10000);
                for (int j = 0; j < nterms; j++)
                {
                    Term term = new Term(TestUtil.RandomUnicodeString(Random(), 2), TestUtil.RandomUnicodeString(Random(), 4));
                    terms.Add(term);
                }
                superSet.AddAll(terms);

                PrefixCodedTerms.Builder b = new PrefixCodedTerms.Builder();
                foreach (Term @ref in terms)
                {
                    b.Add(@ref);
                }
                pb[i] = b.Finish();
            }

            List<IEnumerator<Term>> subs = new List<IEnumerator<Term>>();
            for (int i = 0; i < pb.Length; i++)
            {
                subs.Add(pb[i].GetEnumerator());
            }

            IEnumerator<Term> expected = superSet.GetEnumerator();
            IEnumerator<Term> actual = new MergedIterator<Term>(subs.ToArray());
            while (actual.MoveNext())
            {
                Assert.IsTrue(expected.MoveNext());
                Assert.AreEqual(expected.Current, actual.Current);
            }
            Assert.IsFalse(expected.MoveNext());
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:39,代码来源:TestPrefixCodedTerms.cs

示例5: GetMaxStreak

        public int GetMaxStreak(IEnumerable<int> values)
        {
            int zerosCount = 0;
            var streaksList = new List<Streak>();
            var sortedSet = new SortedSet<int>();

            foreach (var value in values)
            {
                if (value == 0)
                {
                    zerosCount++;
                }
                else
                {
                    sortedSet.Add(value);
                }
            }

            var valuesIterator = sortedSet.GetEnumerator();
            valuesIterator.MoveNext();
            var previousValue = valuesIterator.Current;
            var firstStreak = new Streak { ZerosLeft = zerosCount, StartValue = valuesIterator.Current };
            streaksList.Add(firstStreak);

            if (sortedSet.Count == 0)
            {
                return zerosCount;
            }

            if (sortedSet.Count == 1)
            {
                firstStreak.EndValue = valuesIterator.Current;
            }

            while (valuesIterator.MoveNext())
            {
                int missingValuesGap = valuesIterator.Current - previousValue - 1;
                int streaksCount = streaksList.Count;

                if (missingValuesGap > 0)
                {
                    streaksList.Add(new Streak { ZerosLeft = zerosCount, StartValue = valuesIterator.Current });
                }

                for (int index = 0; index < streaksCount; index++)
                {
                    var streak = streaksList[index];

                    if (!streak.IsSealed)
                    {
                        if (streak.ZerosLeft >= missingValuesGap)
                        {
                            streak.ZerosLeft -= missingValuesGap;
                        }
                        else
                        {
                            streak.EndValue = previousValue;
                            streak.IsSealed = true;
                        }

                        streak.EndValue = missingValuesGap == 0 ? valuesIterator.Current : previousValue;
                    }
                }

                previousValue = valuesIterator.Current;
            }

            return streaksList.Max(x => x.GetValue());
        }
开发者ID:JustMeGaaRa,项目名称:Silent.Algorithms,代码行数:69,代码来源:lngpok.cs

示例6: Main

        static void Main(string[] args)
        {
            var chineseCharSet = new SortedSet<char>(new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                "../../../Dictionaries")).EnumerateFiles().SelectMany(file => File.ReadAllText(file.FullName)
                    .Where(c => c >= 128)));
            foreach (var arg in args.Where(File.Exists))
            {
                Console.WriteLine("Analyzing {0}...", arg);
                var bpath = arg.Remove(arg.Length - 15);    // .font.input.xml
                var doc = XDocument.Load(arg);
                XElement root = doc.Element("font"), firstKerning = root.Element("kerning");
                foreach (var ch in root.Elements("char")) chineseCharSet.Remove(ch.Attribute("value").Value.Single());

                const int charPerRow = 20;
                const int charPerPhoto = charPerRow * charPerRow;
                int photoCount = (chineseCharSet.Count + charPerPhoto - 1) / charPerPhoto, j = 0;
                var pointDictionary = new PointF[chineseCharSet.Count];
                var pageDictionary = new int[chineseCharSet.Count];
                var enumerator = chineseCharSet.GetEnumerator();
                for (var i = 0; i < photoCount; i++)
                    using (var bitmap = new Bitmap(charPerRow * PointSizeEx, charPerRow * PointSizeEx))
                    {
                        using (var graphics = Graphics.FromImage(bitmap))
                        {
                            graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                            for (var y = 0; y < charPerRow; y++) for (var x = 0; x < charPerRow; x++)
                            {
                                if (!enumerator.MoveNext()) goto generateXml;
                                graphics.DrawString(new string(enumerator.Current, 1),
                                    new Font(new FontFamily("方正兰亭特黑简体"), PointSize, FontStyle.Bold),
                                    Brushes.White, Move(pointDictionary[j] = new PointF(PointSizeEx * x, PointSizeEx * y)));
                                pageDictionary[j++] = i + 2;
                            }
                        generateXml:
                            ;
                        }
                        bitmap.Save(string.Format("{0}.page{1:00}.png", bpath, i + 2));
                    }
                var k = 0;
                foreach (var ch in chineseCharSet)
                {
                    var record = new XElement("char");
                    record.Add(new XAttribute("value", ch));
                    record.Add(new XAttribute("texpage", pageDictionary[k]));
                    record.Add(new XAttribute("texx", pointDictionary[k].X - 1));
                    record.Add(new XAttribute("texy", pointDictionary[k++].Y - 1));
                    record.Add(new XAttribute("texw", 76));
                    record.Add(new XAttribute("texh", 76));
                    record.Add(new XAttribute("offsetx", 0));
                    record.Add(new XAttribute("offsety", -76));
                    record.Add(new XAttribute("advance", 80));
                    firstKerning.AddBeforeSelf(record);
                }
                doc.Save(string.Format("{0}.font.xml", bpath));
                using (var writer = new StreamWriter(new FileStream("filelist.txt", FileMode.Create)))
                {
                    for (var i = 0; i < photoCount + 2; i++) writer.WriteLine("data/fonts/TwCen.page{0:00}.png", i);
                    writer.WriteLine();
                    for (var i = 0; i < photoCount + 2; i++)
                        writer.WriteLine("        <texture filename=\"data/fonts/TwCen.page{0:00}.png\"/>", i);
                }
            }
        }
开发者ID:Mygod,项目名称:little-inferno-chinesization,代码行数:63,代码来源:Program.cs

示例7: CalculateOptimalSplit

 private static double CalculateOptimalSplit(List<RenderItem> items, BoundingBox bb, double totalSurface, out double maxHeur, int dim)
 {
     SortedSet<AddRemoveEvent> events = new SortedSet<AddRemoveEvent>(GenerateEvents(items, dim));
     IEnumerator<AddRemoveEvent> aree = events.GetEnumerator();
     HashSet<int> activ = new HashSet<int>();
     HashSet<int> torem = new HashSet<int>();
     AddRemoveEvent are;
     double x0, x1;
     int nleft = 0x00;
     int ntotal = items.Count;
     double lsf = 0.0d;
     bb.GetDimensionBounds(dim, out x0, out x1);
     maxHeur = double.PositiveInfinity;
     double xheu = double.NaN, heu;
     while(aree.MoveNext()) {
         are = aree.Current;
         double x = are.X;
         int index = are.Index;
         if(are.Add) {
             if(!torem.Remove(index)) {
                 activ.Add(index);
             }
         }
         else {
             nleft++;
             lsf += items[index].Surface();
             if(!activ.Remove(index)) {
                 torem.Add(index);
             }
         }
         if(x0 < x && x < x1) {
             double lssf = 0.0d;
             foreach(int id in activ) {
                 lssf += items[id].SplitSurface(x, dim);
             }
             heu = (nleft+activ.Count)*(lsf+lssf)+(ntotal-nleft)*(totalSurface-lsf-lssf);
             if(heu < maxHeur) {
                 maxHeur = heu;
                 xheu = x;
             }
         }
     }
     if(double.IsNaN(xheu)) {
         return 0.5d*(x0+x1);
     }
     return xheu;
 }
开发者ID:KommuSoft,项目名称:MoRen,代码行数:47,代码来源:BinarySpacePartitionAccelerator.cs

示例8: syncSqlCmds

        /// <summary>
        /// Converts translations to sql commands that'll insert and/or update translations to the database.
        /// 
        /// To determine whether an update or translation is needed, translations already in the database are queried and compared against
        /// the translations passed into this method.
        /// 
        /// A two finger algorithm is used against the sorted database stream to the sorted translation parameter for a time
        /// complexity of O(n+m).  All statements are wrapped into a transaction.
        /// </summary>
        public string syncSqlCmds(SortedSet<Translation> translations)
        {
            var categoriesClause = categoriesSqlClause(translations.ToList());  //todo: change algorithm to work with HashSet.Enumerator

            StringBuilder buff = new StringBuilder();

            using (var conn = new MySqlConnection(FlashCardAppDB.instance.connectionString)){
                var cmd = new MySqlCommand(
                    $"select italiano,category from translation where category in ({categoriesClause}) order by category,italiano", conn);
                conn.Open();
                MySqlDataReader rdr = cmd.ExecuteReader();

                var translateEnumerator = translations.GetEnumerator();
                var comparer = new TranslationComparer();
                var hasNext = translateEnumerator.MoveNext();

                Func <string,string> printNull = x => (x != null) ? $"'{x}'" : "null";

                Translation dbt;
                if (hasNext){
                    buff.AppendLine("start transaction;");
                    while (hasNext){ //read-only, forward-only stream
                        dbt = (rdr.Read()) ?
                            new Translation{ italiano = rdr.GetString("italiano"), category = rdr.GetString("category") } : null;

                        if (dbt == null || comparer.Compare(translateEnumerator.Current, dbt) < 0){ //Less than or remaining parsed translations
                            buff.AppendLine("insert into translation (italiano,category,espanol,priority) " +
                                $"values ('{translateEnumerator.Current.italiano}','{translateEnumerator.Current.category}',{printNull(translateEnumerator.Current.espanol)},{translateEnumerator.Current.priority});");
                            hasNext = translateEnumerator.MoveNext();
                        }else if (comparer.Compare(translateEnumerator.Current, dbt) == 0){ //Equal
                            buff.AppendLine($"update translation set espanol={printNull(translateEnumerator.Current.espanol)},priority={translateEnumerator.Current.priority} " +
                                $"where italiano='{translateEnumerator.Current.italiano}' and category='{translateEnumerator.Current.category}';");
                            hasNext = translateEnumerator.MoveNext();
                        } //Greater than... skip
                    }
                    buff.AppendLine("commit;");
                }
                return buff.ToString();
            }
        }
开发者ID:dmacias,项目名称:flashCardApp,代码行数:49,代码来源:TranslationImporter.cs

示例9: newCustomName

 internal string newCustomName()
 {
     var r = new Regex(@"^Custom (\d*)$", RegexOptions.IgnoreCase);
     var ss = new SortedSet<int> ();
     foreach (var style in styles)
         {
             var m = r.Match(style.ToString ());
             if (m.Success)
             {
                 int res;
                 if (int.TryParse(m.Groups[1].Value, out res))
                     ss.Add(res);
             }
         }
     if (ss.Count == 0)
         return "Custom 1";
     var it = ss.GetEnumerator ();
     int prev = it.Current;
     while (it.MoveNext ())
     {
         if ((it.Current - prev) >= 2)
             return String.Format ("Custom {0}", prev + 1);
         prev = it.Current;
     }
     return String.Format("Custom {0}", prev + 1);
 }
开发者ID:Predelnik,项目名称:CppFormatter,代码行数:26,代码来源:StyleDatabase.cs


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