ThreadSafeDicts.jl

A thread-safe Dict type for Julia programming

Description

Struct and Constructors

ThreadSafeDict

struct ThreadSafeDict{K,V} <: AbstractDict{K,V}
    dlock::ReentrantLock
    d::Dict{K,V}
    ThreadSafeDict{K,V}() where {K,V} = new(ReentrantLock(), Dict{K,V}())
    ThreadSafeDict{K,V}(d::Dict{K,V}) where {K,V} =
        new(ReentrantLock(), copy(d))
    ThreadSafeDict{K,V}(itr) where {K,V} =
        new(ReentrantLock(), Dict{K,V}(itr))
end

ThreadSafeDict()
ThreadSafeDict(d::Dict{K,V}) where {K,V}
ThreadSafeDict(itr)

Struct and constructors for ThreadSafeDict. There is one private ReentrantLock per Dict struct. All functions lock this lock, pass arguments to the d member Dict, unlock the ReentrantLock, and then return what is returned by the Dict.

Installation

using Pkg
Pkg.add("ThreadSafeDicts")

Functions Reference

ThreadSafeDicts.ThreadSafeDict — Type
ThreadSafeDict(pairs::Vector{Pair{K,V}})

Struct and constructor for ThreadSafeDict. There is one ReentrantLock per Dict struct. All functions lock this lock, pass arguments to the d member Dict, unlock the lock, and then return what is returned by the Dict.

source
Base.delete! — Method
delete!(dic::ThreadSafeDict, k)

delete key k and its value from the dict

source
Base.empty! — Method
empty!(dic::ThreadSafeDict)

Remove all keys and values from the Dict

source
Base.get! — Method
get!(f::Function, dic::ThreadSafeDict, k)

Get value at key k if exists, otherwise set value at k to f() and return that value.

source
Base.get! — Method
get!(dic::ThreadSafeDict, k, v)

Get value at key k if exists, otherwise set value at k to v and return v.

source
Base.get — Method
get(f::Function, dic::ThreadSafeDict, k)

Get value at key k if exists, otherwise return f()

source
Base.get — Method
get(dic::ThreadSafeDict, k, v)

Get value at key k if exists, otherwise return v

source
Base.haskey — Method
haskey(dic::ThreadSafeDict, k)

Return true if key k is in the dict, else return false.

source
Base.iterate — Method
iterate(dic::ThreadSafeDict, i)

Iterate through the Dict returning its key-value pairs.

source
Base.iterate — Method
iterate(dic::ThreadSafeDict)

Iterate through the Dict returning its key-value pairs.

source
Base.length — Method
length(dic::ThreadSafeDict)

Return the length of the Dict, considered as a vector of key-value pairs

source
Base.pop! — Method
pop!(dic::ThreadSafeDict)

remove and return a key-value pair from the Dict

source
Base.print — Method
print(io::IO, dic::ThreadSafeDict)

Print the ThreadSafeDict, including the state of its lock and contents of the undelying Dict.

source
Base.setindex! — Method
setindex!(dic::ThreadSafeDict, k, v)

Set the value at key index k to v.

source