Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
InMemorySemanticLine.cs
1using System.Collections;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4
6{
11 {
12 private readonly LinkedList<KeyValuePair<ISemanticElement, ISemanticTriple>> elements = new LinkedList<KeyValuePair<ISemanticElement, ISemanticTriple>>();
13 private readonly ISemanticElement reference1;
14 private readonly ISemanticElement reference2;
15 private SortedDictionary<ISemanticElement, LinkedList<ISemanticTriple>> points = null;
16
23 {
24 this.reference1 = Reference1;
25 this.reference2 = Reference2;
26 }
27
31 public ISemanticElement Reference1 => this.reference1;
32
36 public ISemanticElement Reference2 => this.reference2;
37
43 public void Add(ISemanticElement Point, ISemanticTriple Triple)
44 {
45 this.points = null;
46 this.elements.AddLast(new KeyValuePair<ISemanticElement, ISemanticTriple>(Point, Triple));
47 }
48
54 public void Add(IEnumerable<ISemanticTriple> Triples, int ZIndex)
55 {
56 if (!(Triples is null))
57 {
58 foreach (ISemanticTriple Triple in Triples)
59 this.Add(Triple[ZIndex], Triple);
60 }
61 }
62
67 public IEnumerator<ISemanticTriple> GetEnumerator()
68 {
69 return new TripleEnumerator(this.elements.GetEnumerator());
70 }
71
76 IEnumerator IEnumerable.GetEnumerator()
77 {
78 return new TripleEnumerator(this.elements.GetEnumerator());
79 }
80
81 private class TripleEnumerator : IEnumerator<ISemanticTriple>
82 {
83 private readonly IEnumerator<KeyValuePair<ISemanticElement, ISemanticTriple>> e;
84
85 public TripleEnumerator(IEnumerator<KeyValuePair<ISemanticElement, ISemanticTriple>> e)
86 {
87 this.e = e;
88 }
89
90 public ISemanticTriple Current => this.e.Current.Value;
91 object IEnumerator.Current => this.e.Current.Value;
92 public void Dispose() => this.e.Dispose();
93 public bool MoveNext() => this.e.MoveNext();
94 public void Reset() => this.e.Reset();
95 }
96
102 public Task<IEnumerable<ISemanticTriple>> GetTriples(ISemanticElement X)
103 {
104 this.CheckOrdered();
105
106 if (!this.points.TryGetValue(X, out LinkedList<ISemanticTriple> Points))
107 Points = null;
108
109 return Task.FromResult<IEnumerable<ISemanticTriple>>(Points);
110 }
111
116 public Task<IEnumerator<ISemanticElement>> GetValueEnumerator()
117 {
118 this.CheckOrdered();
119
120 return Task.FromResult<IEnumerator<ISemanticElement>>(this.points.Keys.GetEnumerator());
121 }
122
123 private void CheckOrdered()
124 {
125 if (this.points is null)
126 {
127 SortedDictionary<ISemanticElement, LinkedList<ISemanticTriple>> Ordered =
128 new SortedDictionary<ISemanticElement, LinkedList<ISemanticTriple>>();
129 ISemanticElement LastPoint = null;
130 LinkedList<ISemanticTriple> Last = null;
131
132 foreach (KeyValuePair<ISemanticElement, ISemanticTriple> P in this.elements)
133 {
134 if ((LastPoint is null || !LastPoint.Equals(P.Key)) &&
135 !Ordered.TryGetValue(P.Key, out Last))
136 {
137 Last = new LinkedList<ISemanticTriple>();
138 Ordered[P.Key] = Last;
139 }
140
141 Last.AddLast(P.Value);
142 }
143
144 this.points = Ordered;
145 }
146 }
147 }
148}
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.
Interface for semantic nodes.
Interface for semantic lines.
Interface for semantic triples.