ANN: CardinalDicts.jl v0.1.0 (more api complete)



Fast fixed-size dicts wth eraseable entries for keys that are or that map to sequential indicies.


  • Provide dictionaries where the keys are indicies 1:n, and the values are any shared type.
  • The maximum number of entries is set at construction, but any/many/all may be unvalued.
  • Values may be entered, altered or cleared at any time.
  • Clearing a value may be interpreted as setting it to unavailable, unknown, or unused.
  • For immutably typed values, set/get/reset/clear times are very fast.


This small package that couples a BitVector with a preallocated Vector{T} for some T to allow faster get/set for sequentially available information (or naturally 1:n keyed values). Values may be set, changed or cleared (missing, like NA/Null). The semantics for unavailable values is up to you.


Each CardinalDict pairs a word indexed bitset encoding the presence of indexable values with preallocated, contiguous memory holding the values (directly, if immutable). Values are retrieved ionly if they are set (not clear/empty). Values are resettable with any valuesof the same type.


CardinalDict, keymax(dict::CardinalDict), clearindex!(dict:CardinalDict, key::Integer), isfull(dict:CardinalDict)

  • clearindex! is like delete! if delete! returned nothing
  • isfull is the dual of isempty
  • keymax is the largest key for a given CardinalDict (established at construction)


==, !=, length, isempty, endof, eltype, keys, values, getindex, setindex!, delete!, empty!,
get(dict::CardinalDict{K,V}, key::K, default::V), get!(dict::CardinalDict{K,V}, key::K, default::V),
start, next, done, in (and ∈, ∋, ∉, ∌), string, show

Your favorite Dict functions should work. If there is something missing, please add an issue.


lookup oft-used naturally sequenced values

  create an CardinalDict with indices 1:20 that holds Int64 values
  populate it
  use it
  unset an index
  check it
  check length, endof, keymax
using CardinalDicts

factorials = CardinalDict{Int64}(20);
for i in 1:18
    setindex!(factorials, factorial(i), i)
haskey(factorials, 10) == true
clearindex!(facorials, 10)
haskey(factorials, 10) == fakse

length(factorials) == 17
ehdof(factorials) == 18
keymax(factorials) == 20

construct from a vector

using CardinalDicts

vec = [1.0, 3.0, 2.0]
dict = CardinalDict(vec)
dict[2] == 3.0

Please let me know if you are using this package.