Module type Weak.S
Contents
Instructions: Use this module in your project
In the IDE (CLion, Visual Studio Code, Xcode, etc.) you use for your DkSDK project:
Add the following to your project's
dependencies/CMakeLists.txt
:DkSDKProject_DeclareAvailable(ocaml CONSTRAINT "= 4.14.0" FINDLIBS str unix runtime_events threads dynlink) DkSDKProject_MakeAvailable(ocaml)
Add the
Findlib::ocaml
library to any desired targets insrc/*/CMakeLists.txt
:target_link_libraries(YourPackage_YourLibraryName # ... existing libraries, if any ... Findlib::ocaml)
Click your IDE's
Build
button
Not using DkSDK?
FIRST, do one or all of the following:
Run:
opam install ocaml.4.14.0
Edit your
dune-project
and add:(package (name YourExistingPackage) (depends ; ... existing dependenices ... (ocaml (>= 4.14.0))))
Then run:
dune build *.opam # if this fails, run: dune build
Edit your
<package>.opam
file and add:depends: [ # ... existing dependencies ... "ocaml" {>= "4.14.0"} ]
Then run:
opam install . --deps-only
FINALLY, add the library to any desired
(library)
and/or (executable)
targets in your **/dune
files:
(library
(name YourLibrary)
; ... existing library options ...
(libraries
; ... existing libraries ...
))
(executable
(name YourExecutable)
; ... existing executable options ...
(libraries
; ... existing libraries ...
))
type
data
The type of the elements stored in the table.
type
t
The type of tables that contain elements of type data
. Note that weak
hash sets cannot be marshaled using
Stdlib.output_value
or the functions
of the Marshal
module.
val
create : ``int
->
t
create n
creates a new empty weak hash set, of initial size n
. The
table will grow as needed.
val
clear :
t
->
unit
Remove all elements from the table.
merge t x
returns an instance of x
found in t
if any, or else adds
x
to t
and return x
.
add t x
adds x
to t
. If there is already an instance of x
in
t
, it is unspecified which one will be returned by subsequent calls to
find
and merge
.
remove t x
removes from t
one instance of x
. Does nothing if there
is no instance of x
in t
.
find t x
returns an instance of x
found in t
.
-
raises Not_found
if there is no such element.
find_opt t x
returns an instance of x
found in t
or None
if
there is no such element.
- since 4.05
find_all t x
returns a list of all the instances of x
found in t
.
mem t x
returns true
if there is at least one instance of x
in
t
, false otherwise.
iter f t
calls f
on each element of t
, in some unspecified order.
It is not specified what happens if f
tries to change t
itself.
fold f t init
computes (f d1 (... (f dN init)))
where d1 ... dN
are the elements of t
in some unspecified order. It is not specified
what happens if f
tries to change t
itself.
val
count :
t
->
int
Count the number of elements in the table. count t
gives the same
result as fold (fun _ n -> n+1) t 0
but does not delay the
deallocation of the dead elements.
val
stats :
t
->
int * int * int * int * int * int
Return statistics on the table. The numbers are, in order: table length, number of entries, sum of bucket lengths, smallest bucket length, median bucket length, biggest bucket length.