Module Lmdb.Cursor
Iterators over maps.
type ('key, 'value, -'perm, -'dup) tconstraint '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 fmakes a cursor in the transactiontxnusing the functionf cursor.The function
fwill receive thecursor. 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 off.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- parameter txn
if omitted a transient transaction will implicitely be created before calling
fand be committed afterfreturns.
Modification
module Flags = Lmdb__.Lmdb_bindings.PutFlagsval add : ('key, 'value, [> `Read | `Write ], _) t -> ?flags:Flags.t -> 'key -> 'value -> unitadd cursor key valueaddsvaluetokeyand 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
overwritefor duplicate maps, butoverwrite ~flags:Flags.no_overwritefor non-duplicate maps.- parameter flags
- raises Exists
on maps not supporting duplicates if the key already exists.
- raises Exists
if
keyis already bound tovalueandCursor.Flags.no_dup_datawas passed.
val set : ('key, 'value, _, _) t -> ?flags:Flags.t -> 'key -> 'value -> unitset cursor key valuesets binding ofkeytovalue. and moves the cursor to its position.Values of an already existing key are silently overwritten.
- parameter flags
val replace : ('key, 'value, [> `Read | `Write ], _) t -> 'value -> unitreplace cursor valuereplace the current value byvalue.
val remove : ?all:bool -> ('key, 'value, [> `Read | `Write ], _) t -> unitremove cursorremoves the current binding.- parameter all
If
trueremoves all values associated to the current key. Default isfalse.
Reading
val current : ('key, 'value, [> `Read ], _) t -> 'key * 'valuecurrent cursorreturns key and value at the position of the cursor.
val current_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key * 'value arraycurrent_all cursormoves 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 cursorreturns the number of values bound to the current key.
Seeking
val get : ('key, 'value, [> `Read ], _) t -> 'key -> 'valueget cursor keymoves the cursor to the first value ofkey.
val get_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key -> 'value arrayget_all cursor keymoves the cursor to the last value ofkey. Returns all values ofkey.
val seek : ('key, 'value, [> `Read ], _) t -> 'key -> 'key * 'valueseek cursor keymoves the cursor to the first value ofkey.
val seek_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key -> 'key * 'value arrayseek_all cursor keymoves the cursor to the last value ofkey. Returns all values ofkey.
val seek_range : ('key, 'value, [> `Read ], _) t -> 'key -> 'key * 'valueseek_range cursor keymoves the cursor to the first value of the first key greater than or equal tokey.
val seek_range_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key -> 'key * 'value arrayseek_range_all cursor keymoves the cursor to the last value of the first key greater than or equal tokey. Returns all values of this key.
val seek_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key -> 'value -> unitseek_dup cursor key valuemoves the cursor tovalueofkey.
val seek_range_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key -> 'value -> 'key * 'valueseek_range_dup cursor key valuemoves the cursor to the first value greater than or equal tovalueof the first key greater than or equal tokey.
Moving
Moving over all key-value pairs
val first : ('key, 'value, [> `Read ], _) t -> 'key * 'valuefirst cursormoves the cursor to the first value of the first key.
val last : ('key, 'value, [> `Read ], _) t -> 'key * 'valuelast cursormoves the cursor to the last value of the last key.
val next : ('key, 'value, [> `Read ], _) t -> 'key * 'valuenext cursormoves 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 cursormoves 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.
Moving to neighboring keys
val next_nodup : ('key, 'value, [> `Read ], _) t -> 'key * 'valuenext_nodup cursormoves the cursor to the first value of the next key.
val prev_nodup : ('key, 'value, [> `Read ], _) t -> 'key * 'valueprev_nodup cursormoves the cursor to the last value of the previous key.
Moving over duplicates of a single key
val first_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'valuefirst_dup cursormoves the cursor to the first value of the current key.
val last_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'valuelast_dup cursormoves the cursor to the last value of the current key.
val next_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'valuenext_dup cursormoves the cursor to the next value of the current key.- raises Not_found
if the cursor is already on the last value of the current key.
val prev_dup : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'valueprev_dup cursormoves the cursor to the previous value of the current key.- raises Not_found
if the cursor is already on the first value of the current key.
Moving over keys getting all duplicates
val first_all : ('key, 'value, [> `Read ], [> `Dup ]) t -> 'key * 'value arrayfirst_all cursormoves 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 cursormoves 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 cursormoves 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 cursormoves the cursor to the first value of the previous key. Returns all values of the previous key.
Convenient Iterators
val iter : ?cursor:('key, 'value, [> `Read ], 'dup) t -> f:('key -> 'value -> unit) -> ('key, 'value, 'dup) Map.t -> unitval iter_rev : ?cursor:('key, 'value, [> `Read ] as 'perm, 'dup) t -> f:('key -> 'value -> unit) -> ('key, 'value, 'dup) Map.t -> unitval fold_left : ?cursor:('key, 'value, [> `Read ], 'dup) t -> f:('a -> 'key -> 'value -> 'a) -> 'a -> ('key, 'value, 'dup) Map.t -> 'aval fold_right : ?cursor:('key, 'value, [> `Read ], 'dup) t -> f:('key -> 'value -> 'a -> 'a) -> ('key, 'value, 'dup) Map.t -> 'a -> 'a
val iter_all : ?cursor:('key, 'value, [> `Read ], 'dup) t -> f:('key -> 'value array -> unit) -> ('key, 'value, [> `Dup ] as 'dup) Map.t -> unitval iter_rev_all : ?cursor:('key, 'value, [> `Read ] as 'perm, 'dup) t -> f:('key -> 'value array -> unit) -> ('key, 'value, [> `Dup ] as 'dup) Map.t -> unitval fold_left_all : ?cursor:('key, 'value, [> `Read ], 'dup) t -> f:('a -> 'key -> 'value array -> 'a) -> 'a -> ('key, 'value, [> `Dup ] as 'dup) Map.t -> 'aval fold_right_all : ?cursor:('key, 'value, [> `Read ], 'dup) t -> f:('key -> 'value array -> 'a -> 'a) -> ('key, 'value, [> `Dup ] as 'dup) Map.t -> 'a -> 'a