summaryrefslogtreecommitdiff
path: root/inc/TCollection_Set.gxx
blob: a30e6480fe8758ad2e2905f068d9e8c965d368f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// File:	TCollection_Set.gxx
// Created:	Tue Mar  2 16:02:48 1993
// Author:	Remi LEQUETTE
//		<rle@phylox>

//=======================================================================
//function : TCollection_Set
//purpose  : 
//=======================================================================

TCollection_Set::TCollection_Set()
{
}

//=======================================================================
//function : TCollection_Set
//purpose  : 
//=======================================================================

TCollection_Set::TCollection_Set(const TCollection_Set& )
{
}


//=======================================================================
//function : Add
//purpose  : 
//=======================================================================

Standard_Boolean TCollection_Set::Add(const Item& T)
{
  if (Contains(T)) 
    return Standard_False;
  else {
    myItems.Prepend(T);
    return Standard_True;
  }
}

//=======================================================================
//function : Remove
//purpose  : 
//=======================================================================

Standard_Boolean TCollection_Set::Remove(const Item& T)
{
  TCollection_ListIteratorOfSetList It(myItems);
  while (It.More()) {
    if (It.Value() == T) {
      myItems.Remove(It);
      return Standard_True;
    }
    It.Next();
  }
  return Standard_False;
}

//=======================================================================
//function : Union
//purpose  : 
//=======================================================================

void TCollection_Set::Union(const TCollection_Set& B)
{
  Standard_Integer N = Extent();
  Standard_Integer i;
  TCollection_ListIteratorOfSetList It1,It2;
  
  // for each item in B
  for (It1.Initialize(B.myItems); It1.More(); It1.Next()) {
    // test with the N first items of me
    // because the other ones are imported from B
    It2.Initialize(myItems);
    Standard_Boolean found = Standard_False;
    for (i = 1; i <= N; i++) {
      if (It1.Value() == It2.Value()) {
	found = Standard_True;
	break;
      }
      It2.Next();
    }
    if (!found)
      myItems.Append(It1.Value());
  }
}

//=======================================================================
//function : Intersection
//purpose  : 
//=======================================================================

void TCollection_Set::Intersection(const TCollection_Set& B)
{
  TCollection_ListIteratorOfSetList It(myItems);
  while (It.More()) {
    if (B.Contains(It.Value()))
      It.Next();
    else
      myItems.Remove(It);
  }
}

//=======================================================================
//function : Difference
//purpose  : 
//=======================================================================

void TCollection_Set::Difference(const TCollection_Set& B)
{
  TCollection_ListIteratorOfSetList It(myItems);
  while (It.More()) {
    if (B.Contains(It.Value()))
      myItems.Remove(It);
    else
      It.Next();
  }
}

//=======================================================================
//function : Contains
//purpose  : 
//=======================================================================

Standard_Boolean TCollection_Set::Contains(const Item& T) const
{
  TCollection_ListIteratorOfSetList It(myItems);
  while (It.More()) {
    if (It.Value() == T) return Standard_True;
    It.Next();
  }
  return Standard_False;
}

//=======================================================================
//function : IsASubset
//purpose  : 
//=======================================================================

Standard_Boolean TCollection_Set::IsASubset(const TCollection_Set& S) const
{
  if (S.Extent() > Extent()) return Standard_False;
  TCollection_ListIteratorOfSetList It(S.myItems);
  while (It.More()) {
    if (!Contains(It.Value())) return Standard_False;
    It.Next();
  }
  return Standard_True;
}


//=======================================================================
//function : IsAProperSubset
//purpose  : 
//=======================================================================

Standard_Boolean TCollection_Set::IsAProperSubset
  (const TCollection_Set& S) const
{
  if (S.Extent() >= Extent()) return Standard_False;
  return IsASubset(S);
}