3 (* specialisation of oassocbdb that avoids some marshaling cost *)
9 (* !!take care!!: this class does side effect, not a pure oassoc
11 class ['b
] oassoc_btree_string db namedb transact
=
12 let namedb = if namedb = "" then "" else "(" ^
namedb ^
")" in
14 inherit [string,'b
] oassoc
21 method private addbis
(k
,v
) =
24 try Common.marshal__to_string
v []
26 pr2
("PBBBBBBB Out_of_memory in: " ^
namedb);
30 Db.put data
(transact
()) k'
v'
[];
33 Common.profile_code
("Btree.add" ^
namedb) (fun () -> o#addbis x
)
35 (* bugfix: if not tail call (because of a try for instance),
36 * then strange behaviour in native mode
38 method private iter2 f
=
39 let dbc = Cursor.db_cursor db
(transact
()) [] in
40 (* minsky wrapper? Cursor.create ~writecursor:false ~txn:(transact()) db *)
44 let a = Cursor.dbc_get
dbc [Cursor.DB_NEXT
] in
45 (* minsky ? Cursor.get dbc Cursor.NEXT [] *)
47 let valu = (Common.marshal__from_string
(snd
a) 0) in
50 with Failure
"ending" -> false
57 Cursor.dbc_close
dbc (* minsky Cursor.close dbc *)
60 Common.profile_code
("Btree.iter" ^
namedb) (fun () -> o#iter2 x
)
67 method private length2
=
68 let dbc = Cursor.db_cursor db
(transact
()) [] in
74 let _a = Cursor.dbc_get
dbc [Cursor.DB_NEXT
] in
77 with Failure
"ending" -> false
88 Common.profile_code
("Btree.length" ^
namedb) (fun () -> o#length2
)
91 method del
(k,v) = raise Todo
92 method mem e
= raise Todo
93 method null
= raise Todo
95 method private assoc2
k =
98 let vget = Db.get data
(transact
()) k'
[] in
99 (* minsky ? Db.get data ~txn:(transact() *)
100 (Common.marshal__from_string
vget 0)
102 log3
("pb assoc with k = " ^
(k));
105 Common.profile_code
("Btree.assoc" ^
namedb) (fun () -> o#assoc2 x
)
107 method private delkey2
k =
109 Db.del data
(transact
()) k'
[];
112 Common.profile_code
("Btree.delkey" ^
namedb) (fun () -> o#delkey2 x
)
117 let dbc = Cursor.db_cursor db
(transact
()) [] in
121 let a = Cursor.dbc_get
dbc [Cursor.DB_NEXT
] in
122 (* minsky ? Cursor.get dbc Cursor.NEXT [] *)
125 let valu = unv (Common.marshal__from_string (snd a) 0) in
128 Common.push2
key res;
130 with Failure
"ending" -> false
137 Cursor.dbc_close
dbc (* minsky Cursor.close dbc *);
142 let dbc = Cursor.db_cursor db
(transact
()) [] in
146 let a = Cursor.dbc_get
dbc [Cursor.DB_NEXT
] in
147 Db.del data
(transact
()) (fst
a) [];
149 with Failure
"ending" -> false
156 Cursor.dbc_close
dbc (* minsky Cursor.close dbc *);
162 let create_bdb metapath dbname env transact size_buffer_oassoc_buffer
=
163 let db = Bdb.Db.create env
[] in
164 Bdb.Db.db_open
db (transact
())
165 (spf
"%s/%s.db4" metapath dbname
)
166 (spf
"/%s.db4" dbname
)
167 Bdb.Db.DB_BTREE
[Bdb.Db.DB_CREATE
] 0;
169 new Oassoc_buffer.oassoc_buffer size_buffer_oassoc_buffer
170 (new oassoc_btree_string
db dbname transact
)