Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MaxEvaluator.cs
6
8{
13 {
14 private IElement max = null;
15 private IOrderedSet maxSet = null;
16 private double? doubleMax = null;
17 private bool isDouble = true;
18 private bool first = true;
19
25 : base(Node.Argument)
26 {
27 }
28
32 public override void RestartEvaluator()
33 {
34 this.max = null;
35 this.doubleMax = null;
36 this.isDouble = true;
37 this.first = true;
38 }
39
44 public override void AggregateElement(IElement Element)
45 {
46 if (this.first)
47 {
48 this.first = false;
49
50 if (Element is DoubleNumber D)
51 {
52 this.doubleMax = D.Value;
53 this.max = D;
54 this.maxSet = (IOrderedSet)D.AssociatedSet;
55 }
56 else
57 {
60
61 this.isDouble = false;
62 this.max = Element;
63 this.maxSet = S;
64 }
65 }
66 else if (this.isDouble && Element is DoubleNumber D)
67 {
68 double d = D.Value;
69
70 if (d > this.doubleMax)
71 this.doubleMax = d;
72 }
73 else if (this.max is null || this.maxSet.Compare(this.max, Element) < 0)
74 {
77
78 this.max = Element;
79 this.maxSet = S;
80 this.isDouble = false;
81 }
82 }
83
87 public override IElement GetAggregatedResult()
88 {
89 if (this.isDouble)
90 {
91 if (this.doubleMax.HasValue)
92 return new DoubleNumber(this.doubleMax.Value);
93 else
94 return ObjectValue.Null;
95 }
96 else
97 return this.max ?? ObjectValue.Null;
98 }
99 }
100}
Base class for all types of elements.
Definition: Element.cs:14
abstract ISet AssociatedSet
Associated Set.
Definition: Element.cs:38
override IElement GetAggregatedResult()
Gets the aggregated result.
Definition: MaxEvaluator.cs:87
MaxEvaluator(Max Node)
Max(v) iterative evaluator
Definition: MaxEvaluator.cs:24
override void RestartEvaluator()
Restarts the evaluator.
Definition: MaxEvaluator.cs:32
override void AggregateElement(IElement Element)
Aggregates one new element.
Definition: MaxEvaluator.cs:44
An interative evaluator of a function or operation defined by a single ScriptNode.
ScriptNode Node
Node being iteratively evaluated.
static readonly ObjectValue Null
Null value.
Definition: ObjectValue.cs:88
Basic interface for all types of elements.
Definition: IElement.cs:21
Basic interface for ordered sets.
Definition: IOrderedSet.cs:11