protected override void DoBuild( EmitSyntax emit, Pipe <EmitSyntax> ldvalue, SwitchGeneratorAction action) { this.action = action; #if false var decisionTree = new BinaryDecisionTreeBuilder(intMap.DefaultValue, platformInfo); var node = decisionTree.Build(intMap.Enumerate().ToArray()); #else this.builder = new DecisionTreeBuilder(platformInfo); var node = builder.Build( intMap, possibleBounds, frequency); #endif this.emit = emit; this.ldvalue = ldvalue; this.labels = new List <Ref <Labels> >(); strategy.PlanCode(node); strategy.GenerateCode(); // Debug.Write(node); }
public void TestElementaryChecks() { const int DefaultValue = -100; var elementToAction = new MutableIntMap <int>(); elementToAction.DefaultValue = DefaultValue; var bounds = new IntInterval(0, 9); var frequency = new UniformIntFrequency(bounds); elementToAction.Set(new IntArrow <int>(2, 100)); elementToAction.Set(new IntArrow <int>(5, 200)); var target = new DecisionTreeBuilder(platformInfo); var node = target.Build(elementToAction, bounds, frequency); PrintProgram(node, target.DefaultActionDecision); }
public void TestSameActionUnification() { var frequency = new UniformIntFrequency(new IntInterval(-100, 100)); const int DefaultValue = -100; var elementToAction = new MutableIntMap <int>(); elementToAction.DefaultValue = DefaultValue; elementToAction.Set(new IntArrow <int>(1, 1)); elementToAction.Set(new IntArrow <int>(3, 49, 1)); elementToAction.Set(new IntArrow <int>(51, 1)); elementToAction.Set(new IntArrow <int>(54, 100, 1)); var target = new DecisionTreeBuilder(platformInfo); var bounds = new IntInterval(0, 1000); var node = target.Build(elementToAction, bounds, frequency); PrintProgram(node); }
public void TestBalanced() { var frequency = new MutableIntFrequency(); frequency.DefaultValue = 0.0000001; frequency.Set(new IntArrow <double>(1, 520.0)); frequency.Set(new IntArrow <double>(2, 49, 3.0)); frequency.Set(new IntArrow <double>(50, 236.0)); frequency.Set(new IntArrow <double>(51, 100, 2.0)); const int DefaultValue = -1; var elementToAction = new MutableIntMap <int>(); elementToAction.DefaultValue = DefaultValue; elementToAction.Set(new IntArrow <int>(1, 1)); elementToAction.Set(new IntArrow <int>(2, 49, 2)); elementToAction.Set(new IntArrow <int>(50, 3)); elementToAction.Set(new IntArrow <int>(51, 100, 4)); var target = new DecisionTreeBuilder(platformInfo); var bounds = new IntInterval(int.MinValue, int.MaxValue); var node = target.Build(elementToAction, bounds, frequency); PrintProgram(node, target.DefaultActionDecision); Assert.AreEqual(-1, node.Decide(int.MinValue)); Assert.AreEqual(-1, node.Decide(0)); Assert.AreEqual(1, node.Decide(1)); Assert.AreEqual(2, node.Decide(2)); Assert.AreEqual(2, node.Decide(49)); Assert.AreEqual(3, node.Decide(50)); Assert.AreEqual(4, node.Decide(51)); Assert.AreEqual(4, node.Decide(100)); Assert.AreEqual(-1, node.Decide(200)); Assert.AreEqual(-1, node.Decide(bounds.Last)); }