public void PerfectFill() { var a = new Intervals<float>(); a.Add(0, 5); Assert.That(a.Contains(-float.Epsilon), Is.False); Assert.That(a.Contains(0)); Assert.That(a.Contains(4.999f)); Assert.That(a.Contains(5), Is.False); a.Add(6, 10); Assert.That(a.Contains(6)); Assert.That(a.Contains(9.999f)); Assert.That(a.Contains(10), Is.False); Assert.That(a.Count(), Is.EqualTo(2)); a.Add(5, 6); Assert.That(a.Count(), Is.EqualTo(1)); }
/// <summary> /// Get a collapsed version of the graph where interval heads become nodes /// </summary> /// <returns>A new collapsed graph</returns> public AbstractGraph GetIntervalSubgraph() { if (Intervals == null) { CalculateIntervals(); } if (Intervals.Count() == Nodes.Count() || Intervals.Values.All(i => i.Count == 1)) { return(null); } AbstractGraph cfg = new AbstractGraph(); foreach (var n in Intervals.Keys) { var node = new Node(); n.IntervalGraphChild = node; node.IntervalGraphParent = n; node.OriginalBlock = n.OriginalBlock; cfg.Nodes.Add(node); } var header = Intervals.SelectMany(e => e.Value.Select(i => (i, e.Key))).ToDictionary(i => i.i, i => i.Key); foreach (var entry in Nodes) { if (!header.ContainsKey(entry)) { continue; } var h1 = header[entry]; var hnode = h1.IntervalGraphChild; //hnode.Successors.UnionWith(entry.Successors.Select(n => header[n]).Where(h => h != h1).Select(n => n.IntervalGraphChild)); var nodestoadd = entry.Successors.Select(n => header[n]).Where(h => h != h1).Select(n => n.IntervalGraphChild); foreach (var n in nodestoadd) { if (!hnode.Successors.Contains(n)) { hnode.Successors.Add(n); } } } foreach (var entry in cfg.Nodes) { foreach (var succ in entry.Successors) { succ.Predecessors.Add(entry); } } cfg.StartNode = cfg.Nodes.First(x => !x.Predecessors.Any()); cfg.LabelReversePostorderNumbers(); cfg.CalculateIntervals(); return(cfg); }
public override string ToString() { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine(string.Format("Programmer 1: {0} Programmer 2: {1} Length: {2} Number of Intervals {3}", Programmer1, Programmer2, Length, Intervals.Count())); foreach (var interval in Intervals) { stringBuilder.AppendLine(interval.ToString()); } return(stringBuilder.ToString()); }
/// <summary> /// This makes the following tree. /// <para><code> /// 25/29 /// / \ /// 0/5 42/49 /// / \ /// -100/-50 10/12 /// </code></para> /// </summary> /// <returns></returns> private static Intervals<double> MakeTree() { var a = new Intervals<double>(); a.Add(0, 5); a.Add(-100, -50); a.Add(25, 29); a.Add(10, 12); a.Add(42, 49); Assert.That(a.Count(), Is.EqualTo(5)); return a; }