Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
IntersectionSet.cs
1using System;
2using System.Collections.Generic;
5
7{
11 public sealed class IntersectionSet : Set
12 {
13 private readonly ISet set1;
14 private readonly ISet set2;
15
21 public IntersectionSet(ISet Set1, ISet Set2)
22 {
23 this.set1 = Set1;
24 this.set2 = Set2;
25 }
26
32 public override bool Contains(IElement Element)
33 {
34 return this.set1.Contains(Element) && this.set2.Contains(Element);
35 }
36
42 public override bool Equals(object obj)
43 {
44 if (!(obj is IntersectionSet S))
45 return false;
46
47 return (this.set1.Equals(S.set1) && this.set2.Equals(S.set2));
48
49 // TODO: This is not mathematically correct. For the time being, it serves the purpose of allowing the object to be included in dictionaries, etc.
50 }
51
56 public override int GetHashCode()
57 {
58 return this.set1.GetHashCode() ^ this.set2.GetHashCode();
59 }
60
64 public override ICollection<IElement> ChildElements
65 {
66 get
67 {
68 if (!(this.elements is null))
69 return this.elements.Keys;
70
71 ICollection<IElement> E1 = this.set1.ChildElements;
72 if (E1 is null)
73 return null;
74
75 ICollection<IElement> E2 = this.set2.ChildElements;
76 if (E2 is null)
77 return null;
78
79 Dictionary<IElement, bool> Elements = new Dictionary<IElement, bool>();
80
81 foreach (IElement E in E1)
82 Elements[E] = true;
83
84 Dictionary<IElement, bool> Elements2 = new Dictionary<IElement, bool>();
85
86 foreach (IElement E in E2)
87 {
88 if (Elements.ContainsKey(E))
89 Elements2[E] = true;
90 }
91
92 this.elements = Elements2;
93 return Elements2.Keys;
94 }
95 }
96
97 private Dictionary<IElement, bool> elements = null;
98
100 public override string ToString()
101 {
102 return this.set1.ToString() + "∩" + this.set2.ToString();
103 }
104
108 public override object AssociatedObjectValue
109 {
110 get
111 {
112 ICollection<IElement> Elements = this.ChildElements;
113 if (Elements is null)
114 return this;
115
116 object[] Elements2 = new object[Elements.Count];
117 int i = 0;
118
119 foreach (IElement E in Elements)
120 Elements2[i++] = E.AssociatedObjectValue;
121
122 return Elements2;
123 }
124 }
125
129 public override int? Size
130 {
131 get
132 {
133 ICollection<IElement> ChildElements = this.ChildElements;
134 if (ChildElements is null)
135 return null;
136 else
137 return ChildElements.Count;
138 }
139 }
140 }
141}
Base class for all types of elements.
Definition: Element.cs:13
Base class for all types of sets.
Definition: Set.cs:14
Represents a Intersection of two sets.
override int GetHashCode()
Calculates a hash code of the element.
IntersectionSet(ISet Set1, ISet Set2)
Represents a Intersection of two sets.
override? int Size
Size of set, if finite and known, otherwise null is returned.
override bool Equals(object obj)
Compares the element to another.
override bool Contains(IElement Element)
Checks if the set contains an element.
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
override object AssociatedObjectValue
Associated object value.
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for all types of sets.
Definition: ISet.cs:10