| Server IP : 121.121.20.254 / Your IP : 216.73.216.59 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Python315/Lib/profiling/sampling/ |
Upload File : |
"""String table implementation for memory-efficient string storage in profiling data."""
class StringTable:
"""A string table for interning strings and reducing memory usage."""
def __init__(self):
self._strings = []
self._string_to_index = {}
def intern(self, string):
"""Intern a string and return its index.
Args:
string: The string to intern
Returns:
int: The index of the string in the table
"""
if not isinstance(string, str):
string = str(string)
if string in self._string_to_index:
return self._string_to_index[string]
index = len(self._strings)
self._strings.append(string)
self._string_to_index[string] = index
return index
def get_string(self, index):
"""Get a string by its index.
Args:
index: The index of the string
Returns:
str: The string at the given index, or empty string if invalid
"""
if 0 <= index < len(self._strings):
return self._strings[index]
return ""
def get_strings(self):
"""Get the list of all strings in the table.
Returns:
list: A copy of the strings list
"""
return self._strings.copy()
def __len__(self):
"""Return the number of strings in the table."""
return len(self._strings)