예제 #1
0
 public void Find()
 {
     Assert.IsFalse(list.Find(pred, out int i));
     list.AddAll(new int[] { 4, 22, 67, 37 });
     Assert.IsFalse(list.Find(pred, out i));
     list.AddAll(new int[] { 45, 122, 675, 137 });
     Assert.IsTrue(list.Find(pred, out i));
     Assert.AreEqual(45, i);
 }
예제 #2
0
        public static void CharBagSet()
        {
            String text =
                @"three sorted streams aligned by leading masters are stored 
          there; an integral triangle ends, and stable tables keep;
          being alert, they later reread the logarithm, peek at the
          recent center, then begin to send their reader algorithm.";

            String[] words = text.Split(' ', '\n', '\r', ';', ',', '.');
            ICollection <ICollection <char> > anagrams
                = new HashSet <ICollection <char> >();
            int count = 0;

            foreach (String word in words)
            {
                if (word != "")
                {
                    count++;
                    HashBag <char> anagram = new HashBag <char>();
                    anagram.AddAll(word.ToCharArray());
                    anagrams.Add(anagram);
                }
            }
            Console.WriteLine("Found {0} anagrams", count - anagrams.Count);
        }
예제 #3
0
파일: EventPatterns.cs 프로젝트: sestoft/C5
    public static void UnindexedCollectionEvents()
    {
        ICollection <int> coll = new ArrayList <int>();
        ICollection <int> bag1 = new HashBag <int>();

        bag1.AddAll(new[] { 3, 2, 5, 5, 7, 7, 5, 3, 7, 7 });
        // Add change handler
        coll.CollectionChanged += o => Console.WriteLine("Collection changed");

        // Add cleared handler
        coll.CollectionCleared += (o, a) => Console.WriteLine("Collection cleared");

        // Add added handler
        coll.ItemsAdded += (o, args) => Console.WriteLine($"Item {args.Item} added");

        // Add item count handler
        AddItemsAddedCounter(coll);
        AddItemsRemovedCounter(coll);

        coll.AddAll(bag1);
        coll.RemoveAll(new[] { 2, 5, 6, 3, 7, 2 });
        coll.Clear();

        ICollection <int> bag2 = new HashBag <int>();

        // Add added handler with multiplicity
        bag2.ItemsAdded += (o, args) => Console.WriteLine($"{args.Count} copies of {args.Item} added");
        bag2.AddAll(bag1);

        // Add removed handler with multiplicity
        bag2.ItemsRemoved += (o, args) => Console.WriteLine($"{args.Count} copies of {args.Item} removed");
        bag2.RemoveAllCopies(7);
    }
예제 #4
0
 public HashPrimes(int endOfRange)
 {
     EndOfRange = endOfRange;
     Primes = new HashBag<int>();
     Primes.AddAll(Enumerable.Range(2, endOfRange - 1).ToList());
     //SieveLoop();
 }
예제 #5
0
        // Event patterns on indexed collections

        public static void IndexedCollectionEvents()
        {
            IList <int>       coll = new ArrayList <int>();
            ICollection <int> bag  = new HashBag <int>();

            bag.AddAll(new[] { 3, 2, 5, 5, 7, 7, 5, 3, 7, 7 });
            // Add item inserted handler
            coll.ItemInserted
                += delegate(Object c, ItemAtEventArgs <int> args)
                {
                Console.WriteLine("Item {0} inserted at {1}",
                                  args.Item, args.Index);
                };
            coll.InsertAll(0, bag);
            // Add item removed-at handler
            coll.ItemRemovedAt
                += delegate(Object c, ItemAtEventArgs <int> args)
                {
                Console.WriteLine("Item {0} removed at {1}",
                                  args.Item, args.Index);
                };
            coll.RemoveLast();
            coll.RemoveFirst();
            coll.RemoveAt(1);
        }
예제 #6
0
 public void Test()
 {
     Assert.IsTrue(IC.seteq(list.UniqueItems()));
     Assert.IsTrue(IC.seteq(list.ItemMultiplicities()));
     list.AddAll(new int[] { 7, 9, 7 });
     Assert.IsTrue(IC.seteq(list.UniqueItems(), 7, 9));
     Assert.IsTrue(IC.seteq(list.ItemMultiplicities(), 7, 2, 9, 1));
 }
예제 #7
0
        public void AddAll()
        {
            hashbag.Add(3); hashbag.Add(4); hashbag.Add(4); hashbag.Add(5); hashbag.Add(4);

            HashBag <int> hashbag2 = new HashBag <int>();

            hashbag2.AddAll(hashbag);
            Assert.IsTrue(IC.seteq(hashbag2, 3, 4, 4, 4, 5));
            hashbag.Add(9);
            hashbag.AddAll(hashbag2);
            Assert.IsTrue(IC.seteq(hashbag2, 3, 4, 4, 4, 5));
            Assert.IsTrue(IC.seteq(hashbag, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 9));
        }
예제 #8
0
        public static void UnindexedCollectionEvents()
        {
            ICollection <int> coll = new ArrayList <int>();
            ICollection <int> bag1 = new HashBag <int>();

            bag1.AddAll(new[] { 3, 2, 5, 5, 7, 7, 5, 3, 7, 7 });
            // Add change handler
            coll.CollectionChanged
                += delegate(Object c)
                {
                Console.WriteLine("Collection changed");
                };
            // Add cleared handler
            coll.CollectionCleared
                += delegate(Object c, ClearedEventArgs args)
                {
                Console.WriteLine("Collection cleared");
                };
            // Add added handler
            coll.ItemsAdded
                += delegate(Object c, ItemCountEventArgs <int> args)
                {
                Console.WriteLine("Item {0} added", args.Item);
                };
            // Add item count handler
            AddItemsAddedCounter(coll);
            AddItemsRemovedCounter(coll);
            coll.AddAll(bag1);
            coll.RemoveAll(new[] { 2, 5, 6, 3, 7, 2 });
            coll.Clear();
            ICollection <int> bag2 = new HashBag <int>();

            // Add added handler with multiplicity
            bag2.ItemsAdded
                += delegate(Object c, ItemCountEventArgs <int> args)
                {
                Console.WriteLine("{0} copies of {1} added",
                                  args.Count, args.Item);
                };
            bag2.AddAll(bag1);
            // Add removed handler with multiplicity
            bag2.ItemsRemoved
                += delegate(Object c, ItemCountEventArgs <int> args)
                {
                Console.WriteLine("{0} copies of {1} removed",
                                  args.Count, args.Item);
                };
            bag2.RemoveAllCopies(7);
        }
예제 #9
0
파일: EventPatterns.cs 프로젝트: sestoft/C5
    // Event patterns on indexed collections
    public static void IndexedCollectionEvents()
    {
        var coll = new ArrayList <int>();
        var bag  = new HashBag <int>();

        bag.AddAll(new[] { 3, 2, 5, 5, 7, 7, 5, 3, 7, 7 });

        // Add item inserted handler
        coll.ItemInserted += (o, args) => Console.WriteLine($"Item {args.Item} inserted at {args.Index}");
        coll.InsertAll(0, bag);

        // Add item removed-at handler
        coll.ItemRemovedAt += (o, args) => Console.WriteLine($"Item {args.Item} removed at {args.Index}");
        coll.RemoveLast();
        coll.RemoveFirst();
        coll.RemoveAt(1);
    }
예제 #10
0
        internal void AddFunction(SdfInfo info, ICollection <FullCellAddr> addrs)
        {
            HashSet <FullCellAddr> inputCellSet = new HashSet <FullCellAddr>();

            inputCellSet.UnionWith(info.inputCells);
            foreach (FullCellAddr addr in addrs)
            {
                if (!inputCellSet.Contains(addr))
                {
                    AddCellToFunction(info.name, addr);
                }
            }
            List <FullCellAddr> addrsList = new List <FullCellAddr>(addrs);

            functionToAddressList[info.name] = addrsList;
            inputCellBag.AddAll(info.inputCells);
            outputCellBag.Add(info.outputCell);
        }
예제 #11
0
 public static void CharBagSet()
 {
     String text =
       @"three sorted streams aligned by leading masters are stored
       there; an integral triangle ends, and stable tables keep;
       being alert, they later reread the logarithm, peek at the
       recent center, then begin to send their reader algorithm.";
     String[] words = text.Split(' ', '\n', '\r', ';', ',', '.');
     ICollection<ICollection<char>> anagrams
       = new HashSet<ICollection<char>>();
     int count = 0;
     foreach (String word in words)
     {
         if (word != "")
         {
             count++;
             HashBag<char> anagram = new HashBag<char>();
             anagram.AddAll(word.ToCharArray());
             anagrams.Add(anagram);
         }
     }
     Console.WriteLine("Found {0} anagrams", count - anagrams.Count);
 }