Expand description
Dictionary — string interning (§85 Phase 1).
Implements xmlDict, libxml2’s string interning mechanism for efficient
string comparison and memory sharing.
§UPSTREAM-PARITY
libxml2’s xmlDict is a hash-table-backed string interning dictionary.
Key properties:
- Strings are interned (stored once, reused by reference)
- Interned strings are reference-counted
- Sub-dictionaries share the parent’s string table but have their own reference counting
- Dictionary limits prevent denial-of-service via excessive unique strings
xmlDictSetLimitcontrols the maximum number of stringsxmlDictGetUsagereturns the current number of strings
§Thread safety
xmlDict is NOT thread-safe for concurrent modification. However, concurrent reads are safe once the dictionary is populated. This matches upstream behavior.
§Phase 1 status
Complete — all dictionary functions are implemented.
Uses hashbrown::HashTable for the underlying hash table.
Structs§
- Dict
- The dictionary struct (opaque in the C ABI).
Functions§
- dict_
create - Create a new dictionary.
- dict_
create_ ⚠sub - Create a sub-dictionary that shares strings with its parent.
- dict_
exists ⚠ - Check if a string exists in the dictionary without adding it.
- dict_
free ⚠ - Free a dictionary and all its interned strings.
- dict_
get_ usage - Get the current number of entries in the dictionary.
- dict_
lookup ⚠ - Look up a string in the dictionary, adding it if not found.
- dict_
set_ limit - Set the maximum number of entries allowed in the dictionary.
- dict_
size - Get the number of entries in the dictionary.