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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Generate a table of unique items.
The `UniqueTable` class collects items into an array, removing duplicates. Each
item is mapped to its offset in the final array.
This is a compression technique for compile-time generated tables.
"""
# noqa
pass
"""
Collect items into the `table` list, removing duplicates.
"""
# type: () -> None
# List of items added in order.
= # type: List[Any]
# Map item -> index.
= # type: Dict[Any, int]
# type: (Any) -> int
"""
Add a single item to the table if it isn't already there.
Return the offset into `self.table` of the item.
"""
return
=
=
return
"""
Collect sequences into the `table` list, removing duplicates.
Sequences don't have to be of the same length.
"""
# type: () -> None
= # type: List[Any]
# Map seq -> index.
= # type: Dict[Tuple[Any, ...], int]
# type: (Sequence[Any]) -> int
"""
Add a sequence of items to the table. If the table already contains the
items in `seq` in the same order, use those instead.
Return the offset into `self.table` of the beginning of `seq`.
"""
return 0
=
return
=
# Add seq and all sub-sequences to `index`.
= # type: Dict[Tuple[Any, ...], int]
assert is not None
=
= +
return