Tiny associative array (alist-like)

I’m not aware of an existing implementation, but I think you could implement your own in a pretty efficient way. If you’re willing to pay the O(N) lookup cost, it could be as simple as:

struct SmallMap{K, V} <: AbstractDict{K, V}
  keys::Vector{K}
  vals::Vector{V}
  
  SmallMap{K, V}() where {K, V} = new{K, V}(K[], V[])
end

function Base.getindex(m::SmallMap, key)
  for (i, k) in enumerate(m.keys)
    if k == key
      return m.vals[i]
    end
  end
  throw(KeyError(key))
end

function Base.setindex!(m::SmallMap, value, key)
  for (i, k) in enumerate(m.keys)
    if k == key
      m.vals[i] = value
      return m
    end
  end
  push!(m.keys, key)
  push!(m.vals, value)
  return m
end

function Base.iterate(m::SmallMap, i=1)
  if i > length(m.keys)
    return nothing
  else
    return (m.keys[i] => m.vals[i], i + 1)
  end
end

Base.length(m::SmallMap) = length(m.keys)

Usage:

julia> m = SmallMap{String, Int}()
SmallMap{String, Int64}()

julia> m["hello"] = 1
1

julia> m["world"] = 2
2

julia> m
SmallMap{String, Int64} with 2 entries:
  "hello" => 1
  "world" => 2
3 Likes