CMS 3D CMS Logo

OrderedSet.py
Go to the documentation of this file.
1 # The MIT License (MIT)
2 #
3 # Copyright (c) 19 March 2009 Created by Raymond Hettinger (MIT)
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 # DEALINGS IN THE SOFTWARE.
22 #
23 # Copied from URL http://code.activestate.com/recipes/576694-orderedset/
24 # on 15 November 2016
25 
26 import collections
27 
28 class OrderedSet(collections.MutableSet):
29 
30  def __init__(self, iterable=None):
31  self.end = end = []
32  end += [None, end, end] # sentinel node for doubly linked list
33  self.map = {} # key --> [key, prev, next]
34  if iterable is not None:
35  self |= iterable
36 
37  def __len__(self):
38  return len(self.map)
39 
40  def __contains__(self, key):
41  return key in self.map
42 
43  def add(self, key):
44  if key not in self.map:
45  end = self.end
46  curr = end[1]
47  curr[2] = end[1] = self.map[key] = [key, curr, end]
48 
49  def discard(self, key):
50  if key in self.map:
51  key, prev, next = self.map.pop(key)
52  prev[2] = next
53  next[1] = prev
54 
55  def __iter__(self):
56  end = self.end
57  curr = end[2]
58  while curr is not end:
59  yield curr[0]
60  curr = curr[2]
61 
62  def __reversed__(self):
63  end = self.end
64  curr = end[1]
65  while curr is not end:
66  yield curr[0]
67  curr = curr[1]
68 
69  def pop(self, last=True):
70  if not self:
71  raise KeyError('set is empty')
72  key = self.end[1][0] if last else self.end[2][0]
73  self.discard(key)
74  return key
75 
76  def __repr__(self):
77  if not self:
78  return '%s()' % (self.__class__.__name__,)
79  return '%s(%r)' % (self.__class__.__name__, list(self))
80 
81  def __eq__(self, other):
82  if isinstance(other, OrderedSet):
83  return len(self) == len(other) and list(self) == list(other)
84  return set(self) == set(other)
85 
86 
87 if __name__ == '__main__':
88  s = OrderedSet('abracadaba')
89  t = OrderedSet('simsalabim')
90  print(s | t)
91  print(s & t)
92  print(s - t)
def __init__(self, iterable=None)
Definition: OrderedSet.py:30
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:10
def __eq__(self, other)
Definition: OrderedSet.py:81
def add(self, key)
Definition: OrderedSet.py:43
def discard(self, key)
Definition: OrderedSet.py:49
def __contains__(self, key)
Definition: OrderedSet.py:40
def __reversed__(self)
Definition: OrderedSet.py:62
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def pop(self, last=True)
Definition: OrderedSet.py:69