Library
Module
Module type
Parameter
Class
Class type
Iterators 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
module Flags : sig ... end
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.
val replace : ('key, 'value, [> `Read | `Write ], _) t -> 'value -> unit
replace cursor value
replace the current value by value
.
val remove : ?all:bool -> ('key, 'value, [> `Read | `Write ], _) t -> unit
remove cursor
removes the current binding.
val current : ('key, 'value, [> `Read ], _) t -> 'key * 'value
current cursor
returns key and value at the position of the cursor.
val current_all :
('key, 'value, [> `Read ], [> `Dup ]) t ->
'key * 'value array
current_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 -> int
count cursor
returns the number of values bound to the current key.
val get : ('key, 'value, [> `Read ], _) t -> 'key -> 'value
get cursor key
moves the cursor to the first value of key
.
val get_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key -> 'value array
get_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 * 'value
seek cursor key
moves the cursor to the first value of key
.
val seek_all :
('key, 'value, [> `Read ], [> `Dup ]) t ->
'key ->
'key * 'value array
seek_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 * 'value
seek_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 array
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.
val seek_dup :
('key, 'value, [> `Read ], [> `Dup ]) t ->
'key ->
'value ->
unit
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
.
val first : ('key, 'value, [> `Read ], _) t -> 'key * 'value
first cursor
moves the cursor to the first value of the first key.
val last : ('key, 'value, [> `Read ], _) t -> 'key * 'value
last cursor
moves the cursor to the last value of the last key.
val next : ('key, 'value, [> `Read ], _) t -> 'key * 'value
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.
val prev : ('key, 'value, [> `Read ], _) t -> 'key * 'value
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.
val next_nodup : ('key, 'value, [> `Read ], _) t -> 'key * 'value
next_nodup cursor
moves the cursor to the first value of the next key.
val prev_nodup : ('key, 'value, [> `Read ], _) t -> 'key * 'value
prev_nodup cursor
moves the cursor to the last value of the previous key.
val first_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'value
first_dup cursor
moves the cursor to the first value of the current key.
val last_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'value
last_dup cursor
moves the cursor to the last value of the current key.
val next_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'value
next_dup cursor
moves the cursor to the next value of the current key.
val prev_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'value
prev_dup cursor
moves the cursor to the previous value of the current key.
val first_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key * 'value array
first_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 array
last_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 array
next_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 array
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.