idx: ?Index = null,
const Self = @This();
+ pub const Key = K;
pub const Index = u64;
pub const View = SetView(K);
try self.dbi.del(self.item_idx(k));
}
+ pub fn clear(self: *Self) !void {
+ var it = self.iterator();
+ while (it.next()) |i| {
+ try self.del(i.key);
+ }
+ }
pub fn has(self: Self, k: K) !bool {
return self.dbi.has(self.item_idx(k));
}
idx: ?K,
dir: enum { Forward, Backward },
- pub fn next(self: *Iterator) ?K {
+ pub fn next(self: *Iterator) ?struct { key: K } {
if (self.idx != null) {
const k = self.idx.?;
const item = self.sv.item_get(k) catch return null;
.Forward => item.next,
.Backward => item.prev,
};
- return k;
+ return .{ .key = k };
} else {
return null;
}
const Self = @This();
pub const Index = u64;
+ pub const Key = u64;
+ pub const Val = V;
pub const View = ListView(V);
fn open_dbi(txn: lmdb.Txn) !lmdb.Dbi {
try self.dbi.del(self.item_idx(k));
}
+ pub fn clear(self: *Self) !void {
+ var it = self.iterator();
+ while (it.next()) |kv| {
+ try self.del(kv.key);
+ }
+ }
pub fn len(self: Self) usize {
return self.head.len;
}
pub fn SetList(comptime K: type, comptime V: type) type {
return struct {
- idx: ?Index = null,
-
const Self = @This();
pub const Index = u64;
+ pub const Key = K;
+ pub const Val = V;
pub const View = SetListView(K, V);
+ idx: ?Index = null,
+
fn open_dbi(txn: lmdb.Txn) !lmdb.Dbi {
return try txn.dbi("SetList");
}
try self.dbi.del(self.item_idx(k));
}
+ pub fn clear(self: *Self) !void {
+ var it = self.iterator();
+ while (it.next()) |kv| {
+ try self.del(kv.key);
+ }
+ }
pub fn has(self: Self, k: K) !bool {
return self.dbi.has(self.item_idx(k));
}
// const db = List.init(txn, "b", u32);
// }
-test "maplist" {
+test "set" {
var env = try lmdb.Env.open("db", 1024 * 1024 * 1);
// env.sync();
defer env.close();
var dbi = try txn.dbi("abc");
+ const A = struct {
+ ml: Set(usize),
+ };
+
+ var a: A = undefined;
+ const a_idx: u64 = 27;
+ if (try dbi.has(a_idx)) {
+ a = try dbi.get(a_idx, A);
+ } else {
+ a = A{ .ml = try Set(usize).init(txn) };
+ try dbi.put(a_idx, a);
+ }
+
+ var ml = try a.ml.open(txn);
+
+ const len = ml.len();
+ std.debug.print("{}\n", .{len});
+ try ml.append(len);
+ std.debug.print("{}\n", .{try ml.has(len)});
+ var it = ml.iterator();
+ while (it.next()) |i| {
+ std.debug.print("{}\n", .{i});
+ }
+}
+
+test "list" {
+ var env = try lmdb.Env.open("db", 1024 * 1024 * 1);
+ // env.sync();
+ defer env.close();
+
+ var txn = try env.txn();
+ defer txn.commit() catch {};
+
+ var dbi = try txn.dbi("def");
+
+ const A = struct {
+ ml: List(usize),
+ };
+
+ var a: A = undefined;
+ const a_idx: u64 = 27;
+ if (try dbi.has(a_idx)) {
+ a = try dbi.get(a_idx, A);
+ } else {
+ a = A{ .ml = try List(usize).init(txn) };
+ try dbi.put(a_idx, a);
+ }
+
+ var ml = try a.ml.open(txn);
+
+ const len = ml.len();
+ std.debug.print("{}\n", .{len});
+ const newest = try ml.append(len * 10);
+ std.debug.print("{}: {}\n", .{ newest, try ml.get(newest) });
+ var it = ml.iterator();
+ while (it.next()) |i| {
+ std.debug.print("{}: {}\n", .{ i.key, i.val });
+ }
+}
+
+test "setlist" {
+ var env = try lmdb.Env.open("db", 1024 * 1024 * 1);
+ // env.sync();
+ defer env.close();
+
+ var txn = try env.txn();
+ defer txn.commit() catch {};
+
+ var dbi = try txn.dbi("ghi");
+
const A = struct {
ml: SetList(usize, usize),
};