package picos
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=544804c0bde4b29764f82f04e7defed7c06bc43e5a6ce3f7fdc326cb54a7f066
sha512=4c93427e477fb52374a554a8b9c4c92836a9b5899161275d1473269ab526a1f59177209140631ed763a55be375855dea12f076e18bf4124522414986c0e257be
doc/picos.htbl/Picos_htbl/index.html
Module Picos_htbl
Source
Lock-free hash table.
Example:
# let t : (int, string) Picos_htbl.t =
Picos_htbl.create ~hashed_type:(module Int) ()
val t : (int, string) Picos_htbl.t = <abstr>
# Picos_htbl.try_add t 42 "The answer"
- : bool = true
# Picos_htbl.try_add t 101 "Basics"
- : bool = true
# Picos_htbl.find_exn t 42
- : string = "The answer"
# Picos_htbl.try_add t 101 "The basics"
- : bool = false
# Picos_htbl.remove_all t |> List.of_seq
- : (int * string) list = [(101, "Basics"); (42, "The answer")]
๐๏ธ Single key reads with this hash table are actually wait-free rather than just lock-free. Internal resizing automatically uses all the threads that are trying to write to the hash table.
Represents a lock-free hash table mapping keys of type 'k
to values of type 'v
.
First-class module type abbreviation.
create ~hashed_type:(module Key) ()
creates a new empty lock-free hash table.
The optional hashed_type
argument can be used to specify the equal
and hash
operations on keys. Slow polymorphic equality (=)
and slow polymorphic seeded_hash (Random.bits ())
is used by default.
find_exn htbl key
returns the current binding of key
in the hash table htbl
or raises Not_found
if no such binding exists.
mem htbl key
determines whether the hash table htbl
has a binding for the key
.
try_add htbl key value
tries to add a new binding of key
to value
to the hash table htbl
. Returns true
on success and false
in case the hash table already contained a binding for key
.
try_remove htbl key
tries to remove a binding of key
from the hash table htbl
. Returns true
on success and false
in case the hash table did not contain a binding for key
.
remove_exn htbl key
tries to remove a binding of key
from the hash table htbl
and return it or raise Not_found
if no such binding exists.
remove_all htbl
takes a snapshot of the bindings in the hash table, removes the bindings from the hash table, and returns the snapshot as an association sequence.
๐ This is a linear time operation.