-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathutils.py
More file actions
38 lines (29 loc) · 796 Bytes
/
utils.py
File metadata and controls
38 lines (29 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class unique_list(object):
__slots__ = ["value_list", "value_set"]
def __init__(O):
O.value_list = []
O.value_set = set()
def __contains__(O, value):
return value in O.value_set
def append(O, value):
if (value not in O.value_set):
O.value_list.append(value)
O.value_set.add(value)
class keyed_lists(object):
__slots__ = ["indices_by_key", "keys", "lists"]
def __init__(O):
O.indices_by_key = {}
O.keys = []
O.lists = []
def get(O, key):
class undef(object): pass
i = O.indices_by_key.get(key, undef)
if (i is undef):
O.indices_by_key[key] = len(O.keys)
O.keys.append(key)
result = []
O.lists.append(result)
return result
return O.lists[i]
def items(O):
return zip(O.keys, O.lists)