1 """@namespace IMP.pmi.io.utilities
2 Utility classes and functions for IO.
8 def get_db_from_csv(csvfilename):
10 csvr = csv.DictReader(open(csvfilename))
15 class OrderedSet(collections.MutableSet):
16 def __init__(self, iterable=None):
18 end += [
None, end, end]
20 if iterable
is not None:
26 def __contains__(self, key):
27 return key
in self.map
30 if key
not in self.map:
33 curr[2] = end[1] = self.map[key] = [key, curr, end]
35 def discard(self, key):
37 key, prev, next = self.map.pop(key)
44 while curr
is not end:
48 def __reversed__(self):
51 while curr
is not end:
55 def pop(self, last=True):
57 raise KeyError(
'set is empty')
58 key = self.end[1][0]
if last
else self.end[2][0]
64 return '%s()' % (self.__class__.__name__,)
65 return '%s(%r)' % (self.__class__.__name__, list(self))
67 def __eq__(self, other):
68 if isinstance(other, OrderedSet):
69 return len(self) == len(other)
and list(self) == list(other)
70 return set(self) == set(other)