compiler/shared/l0/stdlib/std/linear_map.l0

Module std.linear_map

Overview Symbols grouped by source file: compiler/shared/l0/stdlib/std/linear_map.l0

Module: std.linear_map

Source: compiler/shared/l0/stdlib/std/linear_map.l0 Language: Dea/L0

Imports / Includes

  • std.vector
  • sys.hash
  • std.assert
  • std.string
  • sys.memory
  • sys.rt

Symbols

Function _lm_grow

func _lm_grow(self: LinearMapBase*)

Increases the capacity of the map if needed and grows the length by one.

Parameters:

Function _lm_entry_by_index

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

func _lm_value_by_entry(self: LinearMapBase*, entry_ptr: LinearMapEntryBase*) -> void*

Returns a pointer to the value within an entry.

Parameters:

Returns: A pointer to the value data.

Function _lm_key_by_entry

func _lm_key_by_entry(self: LinearMapBase*, entry_ptr: LinearMapEntryBase*) -> void*

Returns a pointer to the key within an entry.

Parameters:

Returns: A pointer to the key data.

Function _lm_entry_by_hk_key

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

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

func _lm_new_entry(self: LinearMapBase*) -> void*

Allocates space for a new entry in the map.

Parameters:

Returns: A pointer to the new entry.

Function _lm_set_entry

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

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

func lm_free(self: LinearMapBase*)

Free a LinearMapBase and its entry storage.

Parameters:

  • self: Linear map to free.

Function lm_len

func lm_len(self: LinearMapBase*) -> int

Returns the number of entries currently in the map.

Parameters:

Returns: The entry count.

Function lm_contains_key

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

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

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

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

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

func _sslm_entry_by_index(self: StringStringLinearMap*, index: int) -> StringStringLinearMapEntry*

Returns a pointer to the string-string entry at the specified index.

Parameters:

Returns: A pointer to the StringStringLinearMapEntry.

Function _sslm_find_by_key

func _sslm_find_by_key(self: StringStringLinearMap*, key: string) -> int

Finds the index of an entry by its string key.

Parameters:

Returns: The index of the entry, or -1 if not found.

Function sslm_create

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

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

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

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

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

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

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

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

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

func _islm_entry_by_index(self: IntStringLinearMap*, index: int) -> IntStringLinearMapEntry*

Returns a pointer to the int-string entry at the specified index.

Parameters:

Returns: A pointer to the IntStringLinearMapEntry.

Function _islm_find_by_key

func _islm_find_by_key(self: IntStringLinearMap*, key: int) -> int

Finds the index of an entry by its integer key.

Parameters:

Returns: The index of the entry, or -1 if not found.

Function islm_create

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

func islm_free(self: IntStringLinearMap*)

Free an integer-to-string linear map and release stored values.

Parameters:

  • self: Map to free.

Function islm_len

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

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

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

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

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

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

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

hash_key: int

LinearMapEntryBase Field hash_value

hash_value: int

Struct LinearMapBase

Base structure for a linear map.

LinearMapBase Field entries

entries: VectorBase*

LinearMapBase Field key_size

key_size : int

LinearMapBase Field value_size

value_size: int

Struct StringStringLinearMapEntry

Entry for a string-to-string linear map.

StringStringLinearMapEntry Field key

key: string

StringStringLinearMapEntry Field value

value: string

Struct StringStringLinearMap

A linear map specialized for string keys and string values.

StringStringLinearMap Field base

base: LinearMapBase*

Struct IntStringLinearMapEntry

Entry for an integer-to-string linear map.

IntStringLinearMapEntry Field key

key: int

IntStringLinearMapEntry Field value

value: string

Struct IntStringLinearMap

A linear map specialized for integer keys and string values.

IntStringLinearMap Field base

base: LinearMapBase*