Data Containers

FlowGenerator.DataContainers.IndexedMapType

IndexedMap{K,V} is a (partial) implementation of AbstractDict{K,V}. It provides fast index-based access and allows a default value to be specified. It supports efficient addition and removal of key-value pairs.

source
FlowGenerator.DataContainers.LinkedListMapType
struct LinkedListMap{T}

A data structure that implements a map of integers to linked lists, with each list containing elements of type T. It is designed to manage multiple linked lists efficiently by using a shared array of nodes (nodes) to store all elements of all lists, which improves memory allocation efficiency.

Fields

  • list_head_index::Vector{Int}: An array where each element is an integer representing the index of the first node of a linked list in the nodes array. If the value is -1, it indicates that the linked list is empty.
  • nodes::Vector{LinkedListNode{T}}: An array of LinkedListNode{T} that stores the nodes of all linked lists. Each node contains a value of type T and an integer pointing to the next node in its list.

Constructor

LinkedListMap{T}(num_lists::Int) where {T}

Creates an instance of LinkedListMap with a specified number of lists (given by num_lists). Each list is initialized as empty.

Usage

  • To add a value to a specific list, use add_value!(list_map::LinkedListMap{T}, list_index::Int, value::T).
  • To iterate over the elements of a list, obtain an iterator using get_list_iter(list_map::LinkedListMap{T}, list_index::Int).
  • To access a list iterator directly, use the indexing syntax with list_map[index].

Example

list_map = LinkedListMap{Int}(3)  # Create a map for 3 linked lists of integers
add_value!(list_map, 1, 10)       # Add the value 10 to the first list
add_value!(list_map, 1, 20)       # Add the value 20 to the first list
add_value!(list_map, 2, 30)       # Add the value 30 to the second list
for value in list_map[1]          # Iterate over the first list
    println(value)
end

This will output 10 and 20.

Note that this struct does not provide direct methods to remove nodes or to insert nodes at arbitrary positions. All nodes are added at the end (tail) of their respective lists.

source