davidtran999 commited on
Commit
dcc3925
·
verified ·
1 Parent(s): 2e388b6

Upload backend/venv/lib/python3.10/site-packages/marshmallow/orderedset.py with huggingface_hub

Browse files
backend/venv/lib/python3.10/site-packages/marshmallow/orderedset.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # OrderedSet
2
+ # Copyright (c) 2009 Raymond Hettinger
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ # OTHER DEALINGS IN THE SOFTWARE.
23
+ from collections.abc import MutableSet
24
+
25
+
26
+ class OrderedSet(MutableSet):
27
+ def __init__(self, iterable=None):
28
+ self.end = end = []
29
+ end += [None, end, end] # sentinel node for doubly linked list
30
+ self.map = {} # key --> [key, prev, next]
31
+ if iterable is not None:
32
+ self |= iterable
33
+
34
+ def __len__(self):
35
+ return len(self.map)
36
+
37
+ def __contains__(self, key):
38
+ return key in self.map
39
+
40
+ def add(self, key):
41
+ if key not in self.map:
42
+ end = self.end
43
+ curr = end[1]
44
+ curr[2] = end[1] = self.map[key] = [key, curr, end]
45
+
46
+ def discard(self, key):
47
+ if key in self.map:
48
+ key, prev, next = self.map.pop(key) # noqa: A001
49
+ prev[2] = next
50
+ next[1] = prev
51
+
52
+ def __iter__(self):
53
+ end = self.end
54
+ curr = end[2]
55
+ while curr is not end:
56
+ yield curr[0]
57
+ curr = curr[2]
58
+
59
+ def __reversed__(self):
60
+ end = self.end
61
+ curr = end[1]
62
+ while curr is not end:
63
+ yield curr[0]
64
+ curr = curr[1]
65
+
66
+ def pop(self, last=True):
67
+ if not self:
68
+ raise KeyError("set is empty")
69
+ key = self.end[1][0] if last else self.end[2][0]
70
+ self.discard(key)
71
+ return key
72
+
73
+ def __repr__(self):
74
+ if not self:
75
+ return f"{self.__class__.__name__}()"
76
+ return f"{self.__class__.__name__}({list(self)!r})"
77
+
78
+ def __eq__(self, other):
79
+ if isinstance(other, OrderedSet):
80
+ return len(self) == len(other) and list(self) == list(other)
81
+ return set(self) == set(other)
82
+
83
+
84
+ if __name__ == "__main__":
85
+ s = OrderedSet("abracadaba")
86
+ t = OrderedSet("simsalabim")
87
+ print(s | t)
88
+ print(s & t)
89
+ print(s - t)