Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
InMemorySemanticLine.cs
3using System.Threading.Tasks;
5
7{
12 {
14 private readonly ISemanticElement reference1;
15 private readonly ISemanticElement reference2;
16 private SortedDictionary<ISemanticElement, ChunkedList<ISemanticTriple>> points = null;
17
24 {
25 this.reference1 = Reference1;
26 this.reference2 = Reference2;
27 }
28
32 public ISemanticElement Reference1 => this.reference1;
33
37 public ISemanticElement Reference2 => this.reference2;
38
44 public void Add(ISemanticElement Point, ISemanticTriple Triple)
45 {
46 this.points = null;
47 this.elements.Add(new KeyValuePair<ISemanticElement, ISemanticTriple>(Point, Triple));
48 }
49
55 public void Add(IEnumerable<ISemanticTriple> Triples, int ZIndex)
56 {
57 if (!(Triples is null))
58 {
59 foreach (ISemanticTriple Triple in Triples)
60 this.Add(Triple[ZIndex], Triple);
61 }
62 }
63
68 public IEnumerator<ISemanticTriple> GetEnumerator()
69 {
70 return new TripleEnumerator(this.elements.GetEnumerator());
71 }
72
77 IEnumerator IEnumerable.GetEnumerator()
78 {
79 return new TripleEnumerator(this.elements.GetEnumerator());
80 }
81
82 private class TripleEnumerator : IEnumerator<ISemanticTriple>
83 {
84 private readonly IEnumerator<KeyValuePair<ISemanticElement, ISemanticTriple>> e;
85
86 public TripleEnumerator(IEnumerator<KeyValuePair<ISemanticElement, ISemanticTriple>> e)
87 {
88 this.e = e;
89 }
90
91 public ISemanticTriple Current => this.e.Current.Value;
92 object IEnumerator.Current => this.e.Current.Value;
93 public void Dispose() => this.e.Dispose();
94 public bool MoveNext() => this.e.MoveNext();
95 public void Reset() => this.e.Reset();
96 }
97
103 public Task<IEnumerable<ISemanticTriple>> GetTriples(ISemanticElement X)
104 {
105 this.CheckOrdered();
106
107 if (!this.points.TryGetValue(X, out ChunkedList<ISemanticTriple> Points))
108 Points = null;
109
110 return Task.FromResult<IEnumerable<ISemanticTriple>>(Points);
111 }
112
117 public Task<IEnumerator<ISemanticElement>> GetValueEnumerator()
118 {
119 this.CheckOrdered();
120
121 return Task.FromResult<IEnumerator<ISemanticElement>>(this.points.Keys.GetEnumerator());
122 }
123
124 private void CheckOrdered()
125 {
126 if (this.points is null)
127 {
128 SortedDictionary<ISemanticElement, ChunkedList<ISemanticTriple>> Ordered =
129 new SortedDictionary<ISemanticElement, ChunkedList<ISemanticTriple>>();
130 ISemanticElement LastPoint = null;
132
133 foreach (KeyValuePair<ISemanticElement, ISemanticTriple> P in this.elements)
134 {
135 if ((LastPoint is null || !LastPoint.Equals(P.Key)) &&
136 !Ordered.TryGetValue(P.Key, out Last))
137 {
138 Last = new ChunkedList<ISemanticTriple>();
139 Ordered[P.Key] = Last;
140 }
141
142 Last.Add(P.Value);
143 }
144
145 this.points = Ordered;
146 }
147 }
148 }
149}
Task< IEnumerator< ISemanticElement > > GetValueEnumerator()
Gets an enumerator of all values along the line.
IEnumerator< ISemanticTriple > GetEnumerator()
Gets an enumerator over all elements in plance.
void Add(ISemanticElement Point, ISemanticTriple Triple)
Adds an element to the line.
void Add(IEnumerable< ISemanticTriple > Triples, int ZIndex)
Adds a set of triples to the plane.
ISemanticElement Reference2
Line reference 2.
Task< IEnumerable< ISemanticTriple > > GetTriples(ISemanticElement X)
Gets available triples on the line, having a given coordinate.
InMemorySemanticLine(ISemanticElement Reference1, ISemanticElement Reference2)
In-memory semantic line.
ISemanticElement Reference1
Line reference 1.
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
Interface for semantic nodes.
Interface for semantic lines.
Interface for semantic triples.