Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SetDifference.cs
1using System;
2using System.Collections.Generic;
5
7{
11 public sealed class SetDifference : Set
12 {
13 private readonly ISet set1;
14 private readonly ISet set2;
15
21 public SetDifference(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 SetDifference 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 Dictionary<IElement, bool> Elements = new Dictionary<IElement, bool>();
76
77 foreach (IElement E in E1)
78 {
79 if (!this.set2.Contains(E))
80 Elements[E] = true;
81 }
82
83 this.elements = Elements;
84 return Elements.Keys;
85 }
86 }
87
88 private Dictionary<IElement, bool> elements = null;
89
91 public override string ToString()
92 {
93 return this.set1.ToString() + "\\" + this.set2.ToString();
94 }
95
99 public override object AssociatedObjectValue
100 {
101 get
102 {
103 ICollection<IElement> Elements = this.ChildElements;
104 if (Elements is null)
105 return this;
106
107 object[] Elements2 = new object[Elements.Count];
108 int i = 0;
109
110 foreach (IElement E in Elements)
111 Elements2[i++] = E.AssociatedObjectValue;
112
113 return Elements2;
114 }
115 }
116
120 public override int? Size
121 {
122 get
123 {
124 ICollection<IElement> ChildElements = this.ChildElements;
125 if (ChildElements is null)
126 return null;
127 else
128 return ChildElements.Count;
129 }
130 }
131 }
132}
Base class for all types of elements.
Definition: Element.cs:13
Base class for all types of sets.
Definition: Set.cs:14
Represents a set difference A\B.
override bool Equals(object obj)
Compares the element to another.
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
override bool Contains(IElement Element)
Checks if the set contains an element.
SetDifference(ISet Set1, ISet Set2)
Represents a Intersection of two sets.
override int GetHashCode()
Calculates a hash code of the element.
override object AssociatedObjectValue
Associated object value.
override? int Size
Size of set, if finite and known, otherwise null is returned.
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