Vector-based dictionary

ElemCo.VecDictsModule
VecDicts

A module for a vector-based dictionary.

The module provides the VecDict type, which is a vector-based dictionary that stores keys and values in vectors.

It supports standard dictionary operations such as indexing, setting values, checking for keys, deleting keys, and iterating over key-value pairs.

The VecDict type is designed for efficiency of adding new values, but is much slower for lookups compared to standard dictionaries, as it requires a linear search through the keys. It is useful in scenarios where the order and speed of insertion matters and lookups are infrequent, e.g., when collecting data before final processing or for merging to a standard dictionary.

Examples

using VecDicts
dict = VecDict{String, Int}("a" => 1, "b" => 2)
dict["c"] = 3
println(dict["a"])  # Output: 1
println(keys(dict)) # Output: ["a", "b", "c"]
println(values(dict)) # Output: [1, 2, 3]
delete!(dict, "b")
println(length(dict)) # Output: 2
standard_dict = Dict("a" => 2, "d" => 4)
mergewith!(+, standard_dict, dict) 
println(standard_dict) # Output: Dict("c" => 3, "a" => 3, "d" => 4)
source

Exported types and functions

ElemCo.VecDicts.VecDictType
VecDict{K, V}

A vector-based dictionary that maps keys of type K to values of type V. The values are stored in a vector, which means that the order of the key-value pairs is preserved.

source
ElemCo.VecDicts.getatMethod
getat(dict::VecDict, index::Int)::Tuple{K, V}

Get the key-value pair at the specified index in the VecDict.

source
ElemCo.VecDicts.setat!Method
setat!(dict::VecDict, index::Int, key, value)

Set the key-value pair at the specified index in the VecDict.

source

Internal functions