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

**URL:** https://discourse.julialang.org/t/ann-cardinaldicts-jl-v0-1-0-more-api-complete/5274
**Category:** Community
**Tags:** package
**Created:** [August 8, 2017, 8:04am UTC](https://discourse.julialang.org/t/ann-cardinaldicts-jl-v0-1-0-more-api-complete/5274 "2017-08-08T08:04:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [August 8, 2017, 8:04am UTC](https://discourse.julialang.org/t/ann-cardinaldicts-jl-v0-1-0-more-api-complete/5274/1 "2017-08-08T08:04:35Z")

</div>

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

### Purpose

- 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.

### Overview

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.

### Design

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.

#### Exports

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)

#### Provides

==, !=, 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.

## Use

### lookup oft-used naturally sequenced values

```julia
#=
  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)
end
haskey(factorials, 10) == true
clearindex!(facorials, 10)
haskey(factorials, 10) == fakse

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

```

### construct from a vector

```julia
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](https://github.com/JeffreySarnoff/CardinalDicts.jl)**.
