Small dictionaries

SmallCollections.SmallDictType
SmallDict{N,K,V} <: AbstractSmallDict{N,K,V}

SmallDict{N,K,V}()
SmallDict{N,K,V}(itr; unique = itr isa AbstractDict)
SmallDict{N,K,V}(key1 => val1, key2 => val2, ...; unique = false)

An immutable dictionary with key type K and value type V that can store up to N entries. All entries come from the key-value iterator itr provided at construction time or from the explicitly given pairs.

If the key and value types are omitted, they will be inferred from the pairs or, if possible, from the iterator. If unique is set to true, then the elements of itr are assumed to have distinct keys.

See also AbstractSmallDict, MutableSmallDict.

Examples

julia> SmallDict{8}(Int16(1) => 2, Int32(3) => 4.0)
SmallDict{8, Int32, Float64} with 2 entries:
  1 => 2.0
  3 => 4.0

julia> SmallDict{8,Char,Int}('a'+k => k^2 for k in 0:2; unique = true)
SmallDict{8, Char, Int64} with 3 entries:
  'a' => 0
  'b' => 1
  'c' => 4
source
SmallCollections.MutableSmallDictType
MutableSmallDict{N,K,V} <: AbstractSmallDict{N,K,V}

MutableSmallDict{N,K,V}()
MutableSmallDict{N,K,V}(itr; unique = itr isa AbstractDict)
MutableSmallDict{N,K,V}(key1 => val1, key2 => val2, ...; unique = false)

An dictionary with key type K and value type V that can store up to N entries. The dictionary is mutable and implements Julia's dictionary interface.

If the key and value types are omitted, they will be inferred from the pairs or, if possible, from the iterator. If unique is set to true, then the elements of itr are assumed to have distinct keys.

See also AbstractSmallDict, SmallDict.

Examples

julia> d = MutableSmallDict{8}('a' => 0, 'b' => 1, 'c' => 4)
MutableSmallDict{8, Char, Int64} with 3 entries:
  'a' => 0
  'b' => 1
  'c' => 4


julia> delete!(d, 'b')
MutableSmallDict{8, Char, Int64} with 2 entries:
  'a' => 0
  'c' => 4
source
SmallCollections.capacityMethod
capacity(::Type{<:AbstractSmallDict}) -> Int
capacity(d::AbstractSmallDict) -> Int

Return the largest number of elements the given dictionary type can hold.

source
Base.emptyMethod
empty(d::AbstractSmallDict{N,K,V}) where {N,K,V,W} -> AbstractSmallVector{N,K,V}
empty(d::AbstractSmallDict{N,K,V}, W::Type) where {N,K,V,W} -> AbstractSmallVector{N,K,W}
empty(d::AbstractSmallDict{N,K,V}, L::Type, W::Type) where {N,K,V,L,W} -> AbstractSmallVector{N,L,W}

Return an empty AbstractSmallDictionary with the same capacity as d, and with valtype changed to W and keytype changed to L if so specified. The resulting dictionary is mutable if and only if d is so.

source
Base.setindexMethod
setindex(d::AbstractSmallDict{N,K,V}, val, key) where {N,K,V} -> Tuple{SmallDict{N,K,V}, V}

Return the dictionary that is obtained from d by adding the mapping key => val.

See also Base.setindex!, push.

source
SmallCollections.invgetFunction
invget(d::AbstractSmallDict{N,K}, val) where {N,K} -> K

Return a key in d whose value is equal to val (in the sense of isequal). If there is no such key, an error is raised.

This reverse lookup is as fast as "forward" lookup by keys. The key returned is the first matching one in keys(d).

source
invget(d::AbstractSmallDict{N,K}, val, default::T) where {N,K,T} -> Union{K,T}

Return a key in d whose value is equal to val (in the sense of isequal). If there is no such key, return default.

This reverse lookup is as fast as "forward" lookup by keys. The key returned is the first matching one in keys(d).

source
SmallCollections.getminFunction
getmin(d::AbstractSmallDict) -> Pair{<:K,<:V}
getmax(d::AbstractSmallDict) -> Pair{<:K,<:V}

Return a key-values pair that realizes the minimum (or maximum) among the values of the non-empty dictionary d.

See also popmin, popmin!.

source
SmallCollections.pushMethod
push(d::AbstractSmallDict{N,K,V}, key1 => val1, key2 => val2, ...) where {N,K,V} -> Tuple{SmallDict{N,K,V}, V}

Return the dictionary that is obtained from d by adding the mappings given as arguments.

See also Base.push!, setindex.

source
SmallCollections.popMethod
pop(d::AbstractSmallDict{N,K,V}) where {N,K,V} -> Tuple{SmallDict{N,K,V}, Pair{<:K,<:V}}

Remove a mapping key => val from d and return the new dictionary together with the mapping. The dictionary d must not be empty.

See also Base.pop!.

source
SmallCollections.popMethod
pop(d::AbstractSmallDict{N,K,V}, key) where {N,K,V} -> Tuple{SmallDict{N,K,V}, V}

Remove the mapping for key from d and return the new dictionary together with the value d[key].

See also Base.pop!, delete.

source
SmallCollections.popMethod
pop(d::AbstractSmallDict{N,K,V}, key, default::U) where {N,K,V,U} -> Tuple{SmallDict{N,K,V}, Union{V,U}}

If d has the key key, remove it and return the new dictionary together with d[key]. Otherwise return the tuple (SmallDict(d), default).

See also Base.pop!.

source
SmallCollections.deleteMethod
delete(d::AbstractSmallDict{N,K,V}, key) where {N,K,V} -> SmallDict{N,K,V}

Remove the mapping for key from d (if it exists) and return the new dictionary.

See also Base.delete!, pop.

source
SmallCollections.popminFunction
popmin(d::AbstractSmallDict) -> Tuple{SmallDict{N,K,V}, Pair{<:K,<:V}}
popmax(d::AbstractSmallDict) -> Tuple{SmallDict{N,K,V}, Pair{<:K,<:V}}

Find a key-values pair that realizes the minimum (or maximum) among the values of the non-empty dictionary d. Return the pair together with a dictionary obtained from d by removing that pair.

See also getmin, popmin!.

source
SmallCollections.popmin!Function
popmin!(d::AbstractSmallDict) -> Pair{<:K,<:V}
popmax!(d::AbstractSmallDict) -> Pair{<:K,<:V}

Find a key-values pair that realizes the minimum (or maximum) among the values of the non-empty dictionary d. Return that pair and delete it from d.

See also getmin, popmin.

source
Base.findallMethod
findall(f::Function, d::AbstractSmallDict{N,K}; [style::MapStyle]) where {N,K} -> SmallVector{N,K}

With an AbstractSmallDict d as second argument, this function accepts the keyword argument style. If it equals LazyStyle(), then the function f is only evaluated on the actual values of d. For any other value of style, f is evaluated on values(d) as well as on the default values used for padding this SmallVector. This is often faster for simple functions.

As discussed under MapStyle, the default value for style is based on a list of known functions.

See also SmallCollections.default, SmallCollections.MapStyle.

source