2using System.Collections;
3using System.Collections.Generic;
4using System.Threading.Tasks;
13 private readonly LinkedList<Tuple<ISemanticElement, ISemanticElement, ISemanticTriple>> elements =
new LinkedList<Tuple<ISemanticElement, ISemanticElement, ISemanticTriple>>();
15 private SortedDictionary<ISemanticElement, InMemorySemanticLine> yPerX =
null;
16 private SortedDictionary<ISemanticElement, InMemorySemanticLine> xPerY =
null;
40 this.elements.AddLast(
new Tuple<ISemanticElement, ISemanticElement, ISemanticTriple>(X, Y, Triple));
51 public void Add(IEnumerable<ISemanticTriple> Triples,
int XIndex,
int YIndex)
53 if (!(Triples is
null))
56 this.
Add(Triple[XIndex], Triple[YIndex], Triple);
66 return new TripleEnumerator(this.elements.GetEnumerator());
73 IEnumerator IEnumerable.GetEnumerator()
75 return new TripleEnumerator(this.elements.GetEnumerator());
78 private class TripleEnumerator : IEnumerator<ISemanticTriple>
80 private readonly IEnumerator<Tuple<ISemanticElement, ISemanticElement, ISemanticTriple>> e;
82 public TripleEnumerator(IEnumerator<Tuple<ISemanticElement, ISemanticElement, ISemanticTriple>> e)
87 public ISemanticTriple Current => this.e.Current.Item3;
88 object IEnumerator.Current => this.e.Current.Item3;
89 public void Dispose() => this.e.Dispose();
90 public bool MoveNext() => this.e.MoveNext();
91 public void Reset() => this.e.Reset();
101 this.CheckXOrdered();
116 this.CheckYOrdered();
132 this.CheckXOrdered();
135 return Task.FromResult<IEnumerable<ISemanticTriple>>(
null);
137 return Line.GetTriples(Y);
146 this.CheckXOrdered();
148 return Task.FromResult<IEnumerator<ISemanticElement>>(this.yPerX.Keys.GetEnumerator());
157 this.CheckYOrdered();
159 return Task.FromResult<IEnumerator<ISemanticElement>>(this.xPerY.Keys.GetEnumerator());
162 private void CheckXOrdered()
164 if (this.yPerX is
null)
166 SortedDictionary<ISemanticElement, InMemorySemanticLine> Ordered =
167 new SortedDictionary<ISemanticElement, InMemorySemanticLine>();
171 foreach (Tuple<ISemanticElement, ISemanticElement, ISemanticTriple> P
in this.elements)
173 if ((LastPoint is
null || !LastPoint.Equals(P.Item1)) &&
174 !Ordered.TryGetValue(P.Item1, out Last))
177 Ordered[P.Item1] = Last;
180 Last.Add(P.Item2, P.Item3);
183 this.yPerX = Ordered;
187 private void CheckYOrdered()
189 if (this.xPerY is
null)
191 SortedDictionary<ISemanticElement, InMemorySemanticLine> Ordered =
192 new SortedDictionary<ISemanticElement, InMemorySemanticLine>();
193 ISemanticElement LastPoint =
null;
194 InMemorySemanticLine Last =
null;
196 foreach (Tuple<ISemanticElement, ISemanticElement, ISemanticTriple> P
in this.elements)
198 if ((LastPoint is
null || !LastPoint.Equals(P.Item2)) &&
199 !Ordered.TryGetValue(P.Item2, out Last))
201 Last =
new InMemorySemanticLine(P.Item2, P.Item1);
202 Ordered[P.Item2] = Last;
205 Last.Add(P.Item1, P.Item3);
208 this.xPerY = Ordered;
In-memory semantic plane.
Task< IEnumerable< ISemanticTriple > > GetTriplesByXAndY(ISemanticElement X, ISemanticElement Y)
Gets available triples in the plane, having a given X and Y-coordinate.
InMemorySemanticPlane(ISemanticElement Reference)
In-memory semantic plane.
ISemanticElement Reference
Plane reference.
IEnumerator< ISemanticTriple > GetEnumerator()
Gets an enumerator over all elements in plance.
Task< ISemanticLine > GetTriplesByX(ISemanticElement X)
Gets available triples in the plane, having a given X-coordinate.
Task< IEnumerator< ISemanticElement > > GetXAxisEnumerator()
Gets an enumerator of all elements along the X-axis.
Task< IEnumerator< ISemanticElement > > GetYAxisEnumerator()
Gets an enumerator of all elements along the Y-axis.
Task< ISemanticLine > GetTriplesByY(ISemanticElement Y)
Gets available triples in the plane, having a given Y-coordinate.
void Add(ISemanticElement X, ISemanticElement Y, ISemanticTriple Triple)
Adds an element to the plane.
void Add(IEnumerable< ISemanticTriple > Triples, int XIndex, int YIndex)
Adds a set of triples to the plane.
Interface for semantic nodes.
Interface for semantic lines.
Interface for semantic planes.
Interface for semantic triples.