MCPcopy Create free account
hub / github.com/KLayout/klayout / selection

Method selection

src/laybasic/laybasic/layParsedLayerSource.cc:156–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154 }
155
156 bool selection (std::set<db::properties_id_type> &ids) const
157 {
158 // this algorithm computes the "or" of two sets by using this relationship: a or b or c or .. = !((!a) and (!b) and (!c) and ..)
159
160 // get the selection of the first operand into ids
161 std::vector<const PropertySelectorBase *>::const_iterator b = m_args.begin ();
162 bool inv = (*b)->selection (ids);
163 if (m_op == Or) {
164 inv = !inv;
165 }
166
167 for (++b; b != m_args.end () && !(ids.empty () && !inv); ++b) {
168
169 // get the selection of the next operand into ids2
170 std::set<db::properties_id_type> ids2;
171 bool inv2 = (*b)->selection (ids2);
172 if (m_op == Or) {
173 inv2 = !inv2;
174 }
175
176 // compute the intersection of ids and ids2 in place int ids
177 if (ids2.empty () && !inv2) {
178 // shortcut: if the second operand is empty, just clear and terminate the loop then
179 ids.clear ();
180 inv = false;
181 } else if (!inv && !inv2) {
182 for (std::set<db::properties_id_type>::iterator id = ids.begin (); id != ids.end (); ) {
183 std::set<db::properties_id_type>::iterator i = id;
184 ++id;
185 if (ids2.find (*i) == ids2.end ()) {
186 ids.erase (i);
187 }
188 }
189 } else if (inv && inv2) {
190 for (std::set<db::properties_id_type>::iterator id = ids2.begin (); id != ids2.end (); ++id) {
191 ids.insert (*id);
192 }
193 } else {
194 // swap current and new ids such that inv==false
195 if (inv) {
196 std::swap (inv, inv2);
197 ids.swap (ids2);
198 }
199 // from ids subtract all ids that are in ids2 (inv2==true!)
200 for (std::set<db::properties_id_type>::iterator id = ids.begin (); id != ids.end (); ) {
201 std::set<db::properties_id_type>::iterator i = id;
202 ++id;
203 if (ids2.find (*i) != ids2.end ()) {
204 ids.erase (i);
205 }
206 }
207 }
208
209 }
210
211 return m_op == Or ? !inv : inv;
212 }
213

Callers 9

SelectionIteratorMethod · 0.45
nextMethod · 0.45
initMethod · 0.45
nextMethod · 0.45
gsiDeclAnt.ccFile · 0.45
selectionMethod · 0.45
matchingMethod · 0.45
create_from_geometryMethod · 0.45
collect_cell_signaturesFunction · 0.45

Calls 9

swapFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45
findMethod · 0.45
eraseMethod · 0.45
insertMethod · 0.45
swapMethod · 0.45

Tested by

no test coverage detected