1 """@namespace IMP.pmi1.io.utilities
2 Utility classes and functions for IO.
6 from collections.abc
import MutableSet
8 from collections
import MutableSet
11 def get_db_from_csv(csvfilename):
13 csvr = csv.DictReader(open(csvfilename))
18 class OrderedSet(MutableSet):
19 def __init__(self, iterable=None):
21 end += [
None, end, end]
23 if iterable
is not None:
29 def __contains__(self, key):
30 return key
in self.map
33 if key
not in self.map:
36 curr[2] = end[1] = self.map[key] = [key, curr, end]
38 def discard(self, key):
40 key, prev, next = self.map.pop(key)
47 while curr
is not end:
51 def __reversed__(self):
54 while curr
is not end:
58 def pop(self, last=True):
60 raise KeyError(
'set is empty')
61 key = self.end[1][0]
if last
else self.end[2][0]
67 return '%s()' % (self.__class__.__name__,)
68 return '%s(%r)' % (self.__class__.__name__, list(self))
70 def __eq__(self, other):
71 if isinstance(other, OrderedSet):
72 return len(self) == len(other)
and list(self) == list(other)
73 return set(self) == set(other)