Exemplo n.º 1
0
 private static void Visit(UndirectedGraph graph, IReporter reporter,
                           ISet <Vertex> candidates, ISet <Vertex> excluded, ImmutableArray <Vertex> cliqueInProgress)
 {
     Debug.Assert(candidates.All(v => graph.Degree(v) > 0));
     Debug.Assert(excluded.All(v => graph.Degree(v) > 0));
     Debug.Assert(!candidates.Overlaps(excluded));
     Debug.Assert(candidates.Any());
     while (candidates.Any())
     {
         var v                      = CollectionsUtil.PopArbitrary(candidates);
         var neighbours             = graph.Neighbours(v);
         var neighbouringCandidates = CollectionsUtil.Intersection(candidates, neighbours);
         if (neighbouringCandidates.Any())
         {
             var neighbouringExcluded = CollectionsUtil.Intersection(excluded, neighbours);
             Visit(graph, reporter,
                   neighbouringCandidates, neighbouringExcluded,
                   CollectionsUtil.Append(cliqueInProgress, v));
         }
         else if (CollectionsUtil.AreDisjoint(excluded, neighbours))
         {
             reporter.Record(CollectionsUtil.Append(cliqueInProgress, v));
         }
         var added = excluded.Add(v);
         Debug.Assert(added);
     }
 }
Exemplo n.º 2
0
        public void Append()
        {
            var empty = ImmutableArray.Create <uint>();
            var one   = CollectionsUtil.Append(empty, 11u);
            var two   = CollectionsUtil.Append(one, 22u);

            Assert.That(empty.Length.Equals(0));
            Assert.That(one.Length.Equals(1));
            Assert.That(two.Length.Equals(2));
            Assert.That(one[0].Equals(11u));
            Assert.That(two[0].Equals(11u));
            Assert.That(two[1].Equals(22u));
        }