static void Main()
        {
            var crayons = new RankedBag <string> (StringComparer.InvariantCultureIgnoreCase)
            {
                "red", "yellow", "black", "BLACK"
            };

            crayons.Add("blue");

            Console.WriteLine($"There are {crayons.Count} total crayons:");
            foreach (var crayon in crayons)
            {
                Console.WriteLine($"  {crayon}");
            }

            Console.WriteLine($"\nThere are {crayons.GetDistinctCount()} distinct colors:");
            foreach (var crayon in crayons.Distinct())
            {
                Console.WriteLine($"  {crayon}");
            }

            Console.WriteLine($"\nGot 'gold' crayon? {crayons.Contains ("gold")}");

            // RetainAll respects cardinality so the oldest 'black' is removed:
            crayons.RetainAll(new string[] { "white", "grey", "Black", "red" });

            Console.WriteLine("\nAfter RetainAll: ");
            foreach (var crayon in crayons)
            {
                Console.WriteLine($"  {crayon}");
            }
        }
Beispiel #2
0
        public void CrashRbq_DistinctHotUpdate()
        {
            var rb = new RankedBag <int> {
                Capacity = 4
            };

            foreach (int ii in new int[] { 1, 1, 3, 5, 7, 9 })
            {
                rb.Add(ii);
            }
            int n = 0;

#if TEST_BCL
            foreach (var x in Enumerable.Distinct(rb))
#else
            foreach (var x in rb.Distinct())
#endif
            { if (++n == 2)
              {
                  rb.Remove(3);
              }
            }
        }
Beispiel #3
0
        public void UnitRbq_Distinct()
        {
            var rb0 = new RankedBag <int>();
            var rb1 = new RankedBag <int> {
                Capacity = 4
            };

            int a0 = 0, a1 = 0;

            foreach (var ii in new int[] { 3, 5, 5, 7, 7 })
            {
                rb1.Add(ii);
            }
#if TEST_BCL
            foreach (var k0 in Enumerable.Distinct(rb0))
            {
                ++a0;
            }
            foreach (var k1 in Enumerable.Distinct(rb1))
            {
                ++a1;
            }
#else
            foreach (var k0 in rb0.Distinct())
            {
                ++a0;
            }
            foreach (var k1 in rb1.Distinct())
            {
                ++a1;
            }
#endif

            Assert.AreEqual(0, a0);
            Assert.AreEqual(3, a1);
        }