linear_map.l0
Module: std.linear_map
Source: compiler/shared/l0/stdlib/std/linear_map.l0 Language: Dea/L0
Imports / Includes
std.vectorsys.hashstd.assertstd.stringsys.memorysys.rt
Symbols
- _lm_grow
- _lm_entry_by_index
- _lm_value_by_entry
- _lm_key_by_entry
- _lm_entry_by_hk_key
- _lm_entry_by_hv_value
- _lm_new_entry
- _lm_set_entry
- lm_create
- lm_free
- lm_len
- lm_contains_key
- lm_contains_value
- lm_remove
- lm_set
- lm_get
- _sslm_entry_by_index
- _sslm_find_by_key
- sslm_create
- sslm_free
- sslm_len
- sslm_set
- sslm_get
- sslm_contains
- sslm_remove
- sslm_key_at
- sslm_value_at
- _islm_entry_by_index
- _islm_find_by_key
- islm_create
- islm_free
- islm_len
- islm_set
- islm_get
- islm_contains
- islm_remove
- islm_key_at
- islm_value_at
- LinearMapEntryBase
- LinearMapBase
- StringStringLinearMapEntry
- StringStringLinearMap
- IntStringLinearMapEntry
- IntStringLinearMap
Function _lm_grow
1
func _lm_grow(self: LinearMapBase*)
Increases the capacity of the map if needed and grows the length by one.
Parameters:
self: The pointer to the LinearMapBase.
Function _lm_entry_by_index
1
func _lm_entry_by_index(self: LinearMapBase*, index: int) -> LinearMapEntryBase*
Returns a pointer to the entry at the specified index.
Parameters:
self: The pointer to the LinearMapBase.index: The index of the entry.
Returns: A pointer to the LinearMapEntryBase.
Function _lm_value_by_entry
1
func _lm_value_by_entry(self: LinearMapBase*, entry_ptr: LinearMapEntryBase*) -> void*
Returns a pointer to the value within an entry.
Parameters:
self: The pointer to the LinearMapBase.entry_ptr: The pointer to the LinearMapEntryBase.
Returns: A pointer to the value data.
Function _lm_key_by_entry
1
func _lm_key_by_entry(self: LinearMapBase*, entry_ptr: LinearMapEntryBase*) -> void*
Returns a pointer to the key within an entry.
Parameters:
self: The pointer to the LinearMapBase.entry_ptr: The pointer to the LinearMapEntryBase.
Returns: A pointer to the key data.
Function _lm_entry_by_hk_key
1
func _lm_entry_by_hk_key(self: LinearMapBase*, hkey: int, key_ptr: void*) -> LinearMapEntryBase*?
Finds an entry by its hash key and key pointer.
Parameters:
self: The pointer to the LinearMapBase.hkey: The hash of the key.key_ptr: The pointer to the key data to compare.
Returns: The found entry pointer, or null if not found.
Function _lm_entry_by_hv_value
1
func _lm_entry_by_hv_value(self: LinearMapBase*, hval: int, value_ptr: void*) -> LinearMapEntryBase*?
Finds an entry by its hash value and value pointer.
Parameters:
self: The pointer to the LinearMapBase.hval: The hash of the value.value_ptr: The pointer to the value data to compare.
Returns: The found entry pointer, or null if not found.
Function _lm_new_entry
1
func _lm_new_entry(self: LinearMapBase*) -> void*
Allocates space for a new entry in the map.
Parameters:
self: The pointer to the LinearMapBase.
Returns: A pointer to the new entry.
Function _lm_set_entry
1
func _lm_set_entry(self: LinearMapBase*, entry_ptr: LinearMapEntryBase*, hkey: int, key_ptr: void*, hval: int, value_ptr: void*)
Sets the key and value data for a given entry.
Parameters:
self: The pointer to the LinearMapBase.entry_ptr: The entry to modify.hkey: The hash of the key.key_ptr: The pointer to the source key data.hval: The hash of the value.value_ptr: The pointer to the source value data.
Function lm_create
1
func lm_create(key_size: int, value_size: int, initial_capacity: int) -> LinearMapBase*
Creates a new LinearMapBase with the specified sizes and capacity.
Parameters:
key_size: Size of the key in bytes.value_size: Size of the value in bytes.initial_capacity: Initial number of entries.
Returns: A pointer to the newly created map.
Function lm_free
1
func lm_free(self: LinearMapBase*)
Free a LinearMapBase and its entry storage.
Parameters:
self: Linear map to free.
Function lm_len
1
func lm_len(self: LinearMapBase*) -> int
Returns the number of entries currently in the map.
Parameters:
self: The pointer to the LinearMapBase.
Returns: The entry count.
Function lm_contains_key
1
func lm_contains_key(self: LinearMapBase*, key_ptr: void*) -> bool
Checks if the map contains the specified key.
Parameters:
self: The pointer to the LinearMapBase.key_ptr: The pointer to the key data.
Returns: True if the key is present, false otherwise.
Function lm_contains_value
1
func lm_contains_value(self: LinearMapBase*, value_ptr: void*) -> bool
Checks if the map contains the specified value.
Parameters:
self: The pointer to the LinearMapBase.value_ptr: The pointer to the value data.
Returns: True if the value is present, false otherwise.
Function lm_remove
1
func lm_remove(self: LinearMapBase*, key_ptr: void*) -> bool
Removes the entry with the specified key.
Parameters:
self: The pointer to the LinearMapBase.key_ptr: The pointer to the key data to remove.
Returns: True if the key was found and removed, false otherwise.
Function lm_set
1
func lm_set(self: LinearMapBase*, key_ptr: void*, value_ptr: void*)
Inserts or updates a key-value pair in the map.
Parameters:
self: The pointer to the LinearMapBase.key_ptr: The pointer to the key data.value_ptr: The pointer to the value data.
Function lm_get
1
func lm_get(self: LinearMapBase*, key_ptr: void*) -> void*?
Retrieves the value associated with the specified key.
Parameters:
self: The pointer to the LinearMapBase.key_ptr: The pointer to the key data to look up.
Returns: A pointer to the value data, or null if not found.
Function _sslm_entry_by_index
1
func _sslm_entry_by_index(self: StringStringLinearMap*, index: int) -> StringStringLinearMapEntry*
Returns a pointer to the string-string entry at the specified index.
Parameters:
self: The pointer to the StringStringLinearMap.index: The index of the entry.
Returns: A pointer to the StringStringLinearMapEntry.
Function _sslm_find_by_key
1
func _sslm_find_by_key(self: StringStringLinearMap*, key: string) -> int
Finds the index of an entry by its string key.
Parameters:
self: The pointer to the StringStringLinearMap.key: The key string to find.
Returns: The index of the entry, or -1 if not found.
Function sslm_create
1
func sslm_create(initial_capacity: int) -> StringStringLinearMap*
Creates a new string-to-string linear map.
Parameters:
initial_capacity: The initial capacity of the map.
Returns: A pointer to the newly created map.
Function sslm_free
1
func sslm_free(self: StringStringLinearMap*)
Free a string-to-string linear map and release stored keys and values.
Parameters:
self: Map to free.
Function sslm_len
1
func sslm_len(self: StringStringLinearMap*) -> int
Returns the number of entries in the string-to-string map.
Parameters:
self: The pointer to the map.
Returns: The entry count.
Function sslm_set
1
func sslm_set(self: StringStringLinearMap*, key: string, value: string)
Inserts or updates a key-value pair in the string-to-string map.
Parameters:
self: The pointer to the map.key: The key string.value: The value string.
Function sslm_get
1
func sslm_get(self: StringStringLinearMap*, key: string) -> string?
Retrieves the value associated with the specified key string.
Parameters:
self: The pointer to the map.key: The key string.
Returns: The associated value string, or null if not found.
Function sslm_contains
1
func sslm_contains(self: StringStringLinearMap*, key: string) -> bool
Checks if the map contains the specified key string.
Parameters:
self: The pointer to the map.key: The key string.
Returns: True if present, false otherwise.
Function sslm_remove
1
func sslm_remove(self: StringStringLinearMap*, key: string) -> bool
Removes the entry with the specified key string.
Parameters:
self: The pointer to the map.key: The key string to remove.
Returns: True if found and removed, false otherwise.
Function sslm_key_at
1
func sslm_key_at(self: StringStringLinearMap*, index: int) -> string
Returns the key string at the specified entry index.
Parameters:
self: The pointer to the map.index: The entry index.
Returns: The key string.
Function sslm_value_at
1
func sslm_value_at(self: StringStringLinearMap*, index: int) -> string
Returns the value string at the specified entry index.
Parameters:
self: The pointer to the map.index: The entry index.
Returns: The value string.
Function _islm_entry_by_index
1
func _islm_entry_by_index(self: IntStringLinearMap*, index: int) -> IntStringLinearMapEntry*
Returns a pointer to the int-string entry at the specified index.
Parameters:
self: The pointer to the IntStringLinearMap.index: The index of the entry.
Returns: A pointer to the IntStringLinearMapEntry.
Function _islm_find_by_key
1
func _islm_find_by_key(self: IntStringLinearMap*, key: int) -> int
Finds the index of an entry by its integer key.
Parameters:
self: The pointer to the IntStringLinearMap.key: The integer key to find.
Returns: The index of the entry, or -1 if not found.
Function islm_create
1
func islm_create(initial_capacity: int) -> IntStringLinearMap*
Creates a new integer-to-string linear map.
Parameters:
initial_capacity: The initial capacity of the map.
Returns: A pointer to the newly created map.
Function islm_free
1
func islm_free(self: IntStringLinearMap*)
Free an integer-to-string linear map and release stored values.
Parameters:
self: Map to free.
Function islm_len
1
func islm_len(self: IntStringLinearMap*) -> int
Returns the number of entries in the integer-to-string map.
Parameters:
self: The pointer to the map.
Returns: The entry count.
Function islm_set
1
func islm_set(self: IntStringLinearMap*, key: int, value: string)
Inserts or updates a key-value pair in the integer-to-string map.
Parameters:
self: The pointer to the map.key: The integer key.value: The value string.
Function islm_get
1
func islm_get(self: IntStringLinearMap*, key: int) -> string?
Retrieves the value associated with the specified integer key.
Parameters:
self: The pointer to the map.key: The integer key.
Returns: The associated value string, or null if not found.
Function islm_contains
1
func islm_contains(self: IntStringLinearMap*, key: int) -> bool
Checks if the map contains the specified integer key.
Parameters:
self: The pointer to the map.key: The integer key.
Returns: True if present, false otherwise.
Function islm_remove
1
func islm_remove(self: IntStringLinearMap*, key: int) -> bool
Removes the entry with the specified integer key.
Parameters:
self: The pointer to the map.key: The integer key to remove.
Returns: True if found and removed, false otherwise.
Function islm_key_at
1
func islm_key_at(self: IntStringLinearMap*, index: int) -> int
Returns the integer key at the specified entry index.
Parameters:
self: The pointer to the map.index: The entry index.
Returns: The integer key.
Function islm_value_at
1
func islm_value_at(self: IntStringLinearMap*, index: int) -> string
Returns the value string at the specified entry index.
Parameters:
self: The pointer to the map.index: The entry index.
Returns: The value string.
Struct LinearMapEntryBase
Linear map implementation using linear search.
Note: This is not a hash map. Elements are stored in a vector, and lookups are done via linear search. Lookup can be done by key or by value, in O(n) time. Only efficient for very small datasets.
LinearMapEntryBase Field hash_key
1
hash_key: int
LinearMapEntryBase Field hash_value
1
hash_value: int
Struct LinearMapBase
Base structure for a linear map.
LinearMapBase Field entries
1
entries: VectorBase*
LinearMapBase Field key_size
1
key_size : int
LinearMapBase Field value_size
1
value_size: int
Struct StringStringLinearMapEntry
Entry for a string-to-string linear map.
StringStringLinearMapEntry Field key
1
key: string
StringStringLinearMapEntry Field value
1
value: string
Struct StringStringLinearMap
A linear map specialized for string keys and string values.
StringStringLinearMap Field base
1
base: LinearMapBase*
Struct IntStringLinearMapEntry
Entry for an integer-to-string linear map.
IntStringLinearMapEntry Field key
1
key: int
IntStringLinearMapEntry Field value
1
value: string
Struct IntStringLinearMap
A linear map specialized for integer keys and string values.
IntStringLinearMap Field base
1
base: LinearMapBase*