1996-06-12 06:54:53 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml *)
|
|
|
|
(* *)
|
|
|
|
(* Francois Rouaix, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1996-05-15 07:18:46 -07:00
|
|
|
type t
|
|
|
|
|
1996-05-30 04:11:07 -07:00
|
|
|
type open_flag =
|
|
|
|
Dbm_rdonly | Dbm_wronly | Dbm_rdwr | Dbm_create
|
|
|
|
|
1996-05-15 07:18:46 -07:00
|
|
|
type dbm_flag =
|
|
|
|
DBM_INSERT
|
|
|
|
| DBM_REPLACE
|
|
|
|
|
|
|
|
exception Dbm_error of string
|
|
|
|
|
|
|
|
external install_exn : exn -> unit
|
|
|
|
= "caml_dbm_install_exn"
|
|
|
|
external opendbm : string -> open_flag list -> int -> t
|
|
|
|
= "caml_dbm_open"
|
|
|
|
external close : t -> unit = "caml_dbm_close"
|
1996-06-10 05:09:41 -07:00
|
|
|
external find : t -> string -> string = "caml_dbm_fetch"
|
|
|
|
external add : t -> string -> string -> unit = "caml_dbm_insert"
|
|
|
|
external replace : t -> string -> string -> unit = "caml_dbm_replace"
|
|
|
|
external remove : t -> string -> unit = "caml_dbm_delete"
|
1996-05-15 07:18:46 -07:00
|
|
|
external firstkey : t -> string = "caml_dbm_firstkey"
|
|
|
|
external nextkey : t -> string = "caml_dbm_nextkey"
|
|
|
|
|
|
|
|
let _ = install_exn (Dbm_error "")
|
|
|
|
|
1996-06-10 05:09:41 -07:00
|
|
|
(* Usual iterator *)
|
1996-05-15 07:18:46 -07:00
|
|
|
let iter f t =
|
|
|
|
let rec walk k =
|
1996-06-10 05:09:41 -07:00
|
|
|
f k (find t k);
|
1996-05-15 07:18:46 -07:00
|
|
|
match try Some(nextkey t) with Not_found -> None
|
|
|
|
with
|
|
|
|
None -> ()
|
|
|
|
| Some k -> walk k
|
|
|
|
in
|
|
|
|
walk (firstkey t)
|
|
|
|
|