Skip to main content

Module dictionary

Module dictionary 

Source
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
  • xmlDictSetLimit controls the maximum number of strings
  • xmlDictGetUsage returns 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.