Page
Library
Module
Module type
Parameter
Class
Class type
Source
Lmdb.Cursor
SourceIterators over maps.
A cursor allows to iterate manually on the map. Every cursor implicitely uses a transaction.
type ('key, 'value, -'perm, -'dup) t constraint 'perm = [< `Read | `Write ] constraint 'dup = [< `Dup | `Uni ]
A cursor inherits two phantom types: the [< `Read | `Write ]
permissions from the transaction and the [< `Dup | `Uni ]
support from the map.
val go :
'perm perm ->
?txn:'perm Txn.t ->
('key, 'value, 'dup) Map.t ->
(('key, 'value, 'perm, 'dup) t -> 'a) ->
'a
go perm map ?txn f
makes a cursor in the transaction txn
using the function f cursor
.
The function f
will receive the cursor
. A cursor can only be created and used inside a transaction. The cursor inherits the permissions of the transaction. The cursor should not be leaked outside of f
.
Here is an example that returns the first 5 elements of a map
:
go ro map begin fun c ->
let h = first c in
let rec aux i =
if i < 5 then next c :: aux (i+1)
else []
in
h :: aux 1
end
val add :
('key, 'value, [> `Read | `Write ], _) t ->
?flags:Flags.t ->
'key ->
'value ->
unit
add cursor key value
adds value
to key
and moves the cursor to its position.
For a map not supporting duplicates an existing value is overwritten. For a map supporting duplicates the value is added to the key. This is the same as overwrite
for duplicate maps, but overwrite ~flags:Flags.no_overwrite
for non-duplicate maps.
set cursor key value
sets binding of key
to value
. and moves the cursor to its position.
Values of an already existing key are silently overwritten.
replace cursor value
replace the current value by value
.
remove cursor
removes the current binding.
current cursor
returns key and value at the position of the cursor.
current_all cursor
moves the cursor to the last value of the current key. Returns key and all values of the current key.
count cursor
returns the number of values bound to the current key.
get cursor key
moves the cursor to the first value of key
.
get_all cursor key
moves the cursor to the last value of key
. Returns all values of key
.
seek cursor key
moves the cursor to the first value of key
.
seek_all cursor key
moves the cursor to the last value of key
. Returns all values of key
.
seek_range cursor key
moves the cursor to the first value of the first key greater than or equal to key
.
seek_range_all cursor key
moves the cursor to the last value of the first key greater than or equal to key
. Returns all values of this key.
seek_dup cursor key value
moves the cursor to value
of key
.
val seek_range_dup :
('key, 'value, [> `Read ], [> `Dup ]) t ->
'key ->
'value ->
'key * 'value
seek_range_dup cursor key value
moves the cursor to the first value greater than or equal to value
of the first key greater than or equal to key
.
first cursor
moves the cursor to the first value of the first key.
last cursor
moves the cursor to the last value of the last key.
next cursor
moves the cursor to the next key-value pair. This may be the next value of the current key or the first value of the next key.
prev cursor
moves the cursor to the previous key-value pair. This may be the previous value of the current key or the last value of the previous key.
next_nodup cursor
moves the cursor to the first value of the next key.
prev_nodup cursor
moves the cursor to the last value of the previous key.
first_dup cursor
moves the cursor to the first value of the current key.
last_dup cursor
moves the cursor to the last value of the current key.
next_dup cursor
moves the cursor to the next value of the current key.
prev_dup cursor
moves the cursor to the previous value of the current key.
first_all cursor
moves the cursor to the last value of the first key. Returns all values of the first key.
last_all cursor
moves the cursor to the first value of the last key. Returns all values of the last key.
next_all cursor
moves the cursor to the last value of the next key. Returns all values of the next key.
prev_all cursor
moves the cursor to the first value of the previous key. Returns all values of the previous key.
Call f
once for each key-value pair. Will call f
multiple times with the same key for duplicates
Call f
once for each key passing the key and all associated values.