Vector-based dictionary
ElemCo.VecDicts — Module
VecDictsA 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)Exported types and functions
ElemCo.VecDicts.VecDict — Type
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.
ElemCo.VecDicts.getat — Method
getat(dict::VecDict, index::Int)::Tuple{K, V}Get the key-value pair at the specified index in the VecDict.
ElemCo.VecDicts.getkeyat — Method
getkeyat(dict::VecDict, index::Int)Get the key at the specified index in the VecDict.
ElemCo.VecDicts.getvalueat — Method
getvalueat(dict::VecDict, index::Int)Get the value at the specified index in the VecDict.
ElemCo.VecDicts.setat! — Method
setat!(dict::VecDict, index::Int, key, value)Set the key-value pair at the specified index in the VecDict.
ElemCo.VecDicts.setkeyat! — Method
setkeyat!(dict::VecDict, index::Int, key)Set the key at the specified index in the VecDict.
ElemCo.VecDicts.setvalueat! — Method
setvalueat!(dict::VecDict, index::Int, value)Set the value at the specified index in the VecDict.