-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathstring_labels.py
31 lines (24 loc) · 998 Bytes
/
string_labels.py
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
# ----------------------------------------------------------------------
# Copyleft (K), Jose M. Rodriguez-Rosa (a.k.a. Boriel)
#
# This program is Free Software and is released under the terms of
# the GNU General License
# ----------------------------------------------------------------------
__doc__ = """This module is a singleton instance that contains
a mapping of constant Strings to Labels.
"""
from collections import defaultdict
from typing import Final
from src.api import tmp_labels
STRING_LABELS: Final[dict[str, str]] = defaultdict(tmp_labels.tmp_label)
def reset():
"""Initializes this module"""
STRING_LABELS.clear()
def add_string_label(string: str) -> str:
"""Maps ("folds") the given string, returning a unique label ID.
This allows several constant labels to be initialized to the same address
thus saving memory space.
:param string: the string to map
:return: the unique label ID
"""
return STRING_LABELS[string]