Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
IndexOrder.cs
1using System;
2using System.Collections.Generic;
6
7namespace Waher.Script.Order
8{
12 public class IndexOrder : IComparer<IElement>
13 {
14 private readonly ScriptNode node;
15 private readonly int index;
16 private readonly int sign;
17
24 public IndexOrder(ScriptNode Node, int Index, int Sign)
25 {
26 this.node = Node;
27 this.index = Index;
28 this.sign = Sign;
29 }
30
37 public int Compare(IElement x, IElement y)
38 {
39 if (x is IVector v1 && y is IVector v2)
40 {
41 IElement e1 = v1.GetElement(this.index);
42 IElement e2 = v2.GetElement(this.index);
43
44 return this.sign * ElementOrder.Compare(e1, e2, this.node);
45 }
46 else
47 throw new ScriptRuntimeException("Elements in array must be vectors.", this.node);
48 }
49 }
50}
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Orders elements based on their values.
Definition: ElementOrder.cs:14
int Compare(IElement x, IElement y)
Compares two elements.
Definition: ElementOrder.cs:32
Orders vectors based on values of elements at a given index position in the vectors.
Definition: IndexOrder.cs:13
IndexOrder(ScriptNode Node, int Index, int Sign)
Orders vectors based on values of elements at a given index position in the vectors.
Definition: IndexOrder.cs:24
int Compare(IElement x, IElement y)
Compares two elements.
Definition: IndexOrder.cs:37
Basic interface for all types of elements.
Definition: IElement.cs:20
Basic interface for vectors.
Definition: IVector.cs:9