Page
Library
Module
Module type
Parameter
Class
Class type
Source
Lmdb.CursorIterators 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) ->
'ago 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
endval add :
('key, 'value, [> `Read | `Write ], _) t ->
?flags:Flags.t ->
'key ->
'value ->
unitadd cursor key value adds value to key and moves the cursor to its position.
Existing values are neither removed nor overwritten.
val set : ('key, 'value, _, _) t -> ?flags:Flags.t -> 'key -> 'value -> unitset 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.
val replace : ('key, 'value, [> `Read | `Write ], _) t -> 'value -> unitreplace cursor value replace the current value by value.
val remove : ?all:bool -> ('key, 'value, [> `Read | `Write ], _) t -> unitremove cursor removes the current binding.
val current : ('key, 'value, [> `Read ], _) t -> 'key * 'valuecurrent cursor returns key and value at the position of the cursor.
val current_all :
('key, 'value, [> `Read ], [> `Dup ]) t ->
'key * 'value arraycurrent_all cursor moves the cursor to the last value of the current key. Returns key and all values of the current key.
val count : ('key, 'value, [> `Read ], [> `Dup ]) t -> intcount cursor returns the number of values bound to the current key.
val get : ('key, 'value, [> `Read ], _) t -> 'key -> 'valueget cursor key moves the cursor to the first value of key.
val get_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key -> 'value arrayget_all cursor key moves the cursor to the last value of key. Returns all values of key.
val seek : ('key, 'value, [> `Read ], _) t -> 'key -> 'key * 'valueseek cursor key moves the cursor to the first value of key.
val seek_all :
('key, 'value, [> `Read ], [> `Dup ]) t ->
'key ->
'key * 'value arrayseek_all cursor key moves the cursor to the last value of key. Returns all values of key.
val seek_range : ('key, 'value, [> `Read ], _) t -> 'key -> 'key * 'valueseek_range cursor key moves the cursor to the first value of the first key greater than or equal to key.
val seek_range_all :
('key, 'value, [> `Read ], [> `Dup ]) t ->
'key ->
'key * 'value arrayseek_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.
val seek_dup :
('key, 'value, [> `Read ], [> `Dup ]) t ->
'key ->
'value ->
unitseek_dup cursor key value moves the cursor to value of key.
val seek_range_dup :
('key, 'value, [> `Read ], [> `Dup ]) t ->
'key ->
'value ->
'key * 'valueseek_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.
val first : ('key, 'value, [> `Read ], _) t -> 'key * 'valuefirst cursor moves the cursor to the first value of the first key.
val last : ('key, 'value, [> `Read ], _) t -> 'key * 'valuelast cursor moves the cursor to the last value of the last key.
val next : ('key, 'value, [> `Read ], _) t -> 'key * 'valuenext 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.
val prev : ('key, 'value, [> `Read ], _) t -> 'key * 'valueprev 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.
val next_nodup : ('key, 'value, [> `Read ], _) t -> 'key * 'valuenext_nodup cursor moves the cursor to the first value of the next key.
val prev_nodup : ('key, 'value, [> `Read ], _) t -> 'key * 'valueprev_nodup cursor moves the cursor to the last value of the previous key.
val first_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'valuefirst_dup cursor moves the cursor to the first value of the current key.
val last_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'valuelast_dup cursor moves the cursor to the last value of the current key.
val next_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'valuenext_dup cursor moves the cursor to the next value of the current key.
val prev_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'valueprev_dup cursor moves the cursor to the previous value of the current key.
val first_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key * 'value arrayfirst_all cursor moves the cursor to the last value of the first key. Returns all values of the first key.
val last_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key * 'value arraylast_all cursor moves the cursor to the first value of the last key. Returns all values of the last key.
val next_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key * 'value arraynext_all cursor moves the cursor to the last value of the next key. Returns all values of the next key.
val prev_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key * 'value arrayprev_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.