NKL44S6YUCLZDH5EDDUJB5BHX2QWDP7SI5RROBVAUXKAU4ADKPAQC
VDX2MMS55XMEHH2TEMOOW225K6NGKB4QXPQFQ2WJLVXJK25BSXMQC
2HKNCI4IG65FEWNSRBJ5SESMN4STJ6WSCNODP3UK6LBQMDHYPNTAC
7G5Y53RBBKF4QDPTVC2MFG45XHDOLEFPHA4XQIPJNW4RXCULMRQQC
UAUV6SYV72FWMQVALN5YFTANLHIG6B5JHTZLJJUN5SN7SALYAC3AC
GJA75BA6ZNFQL6DG7YSRQKJWGX52YJKL3DZO3OWO6D4HVH6JS7NQC
LD2TP6CDUHET2ISQB3P4JOTQTIDDPRLSZJTIYWAO7JTHKUWOF7MQC
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
// var tsa = std.heap.ThreadSafeAllocator{ .child_allocator = std.heap.page_allocator };
var sl = try SL.init(arena.allocator());
defer sl.deinit(arena.allocator());
var sl = try SL.init(std.heap.page_allocator);
defer sl.deinit();
fn testIns(allocator: std.mem.Allocator, skiplist: *SL, key: BENCH_KEY, val: BENCH_VALUE) void {
_ = @call(std.builtin.CallModifier.auto, SL.insert, .{ skiplist, allocator, key, val }) catch unreachable;
fn testIns(skiplist: *SL, key: BENCH_KEY, val: BENCH_VALUE) void {
_ = @call(std.builtin.CallModifier.auto, SL.insert, .{ skiplist, key, val }) catch unreachable;
// XXX: these should be hidden!
rnd: std.rand.DefaultPrng,
/// Starting Node pointer of the SkipList.
head: *Node,
/// Allocator to use when creating SkipList and its Node items.
/// Make sure it is threadsafe if You want to use the SkipList from multiple threads!
allocator: std.mem.Allocator,
var rnd: std.rand.DefaultPrng = undefined;
var head: *Node = undefined;
sl.head = try Node.init(allocator, 0, max_level);
sl.head.key = null;
rnd = std.rand.DefaultPrng.init(@intCast(std.time.milliTimestamp()));
head = try Node.init(allocator, 0, max_level);
head.key = null;
pub fn insert(self: *@This(), allocator: std.mem.Allocator, insert_key: K, insert_value: V) !bool {
const rlevel = self.randomLevel();
pub fn insert(self: *@This(), insert_key: K, insert_value: V) !bool {
const rlevel = randomLevel();
// FIXME: hardcoded!
const bits = comptime blk: {
break :blk @as(usize, @intFromFloat(std.math.log(f32, 4, @as(f32, @floatFromInt(100_000)))));
};
var locks = std.StaticBitSet(bits + 1).initEmpty();
var locks = std.StaticBitSet(max_level + 1).initEmpty();
try std.testing.expect((try sl.insert(std.testing.allocator, 3, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 6, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 7, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 9, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 12, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 12, {})) == false);
try std.testing.expect((try sl.insert(std.testing.allocator, 12, {})) == false);
try std.testing.expect((try sl.insert(std.testing.allocator, 19, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 8, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 17, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 26, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 21, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 25, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 42, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 88, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 22, {})) == true);
try std.testing.expect((try sl.insert(std.testing.allocator, 66, {})) == true);
try std.testing.expect((try sl.insert(3, {})) == true);
try std.testing.expect((try sl.insert(6, {})) == true);
try std.testing.expect((try sl.insert(7, {})) == true);
try std.testing.expect((try sl.insert(9, {})) == true);
try std.testing.expect((try sl.insert(12, {})) == true);
try std.testing.expect((try sl.insert(12, {})) == false);
try std.testing.expect((try sl.insert(12, {})) == false);
try std.testing.expect((try sl.insert(19, {})) == true);
try std.testing.expect((try sl.insert(8, {})) == true);
try std.testing.expect((try sl.insert(17, {})) == true);
try std.testing.expect((try sl.insert(26, {})) == true);
try std.testing.expect((try sl.insert(21, {})) == true);
try std.testing.expect((try sl.insert(25, {})) == true);
try std.testing.expect((try sl.insert(42, {})) == true);
try std.testing.expect((try sl.insert(88, {})) == true);
try std.testing.expect((try sl.insert(22, {})) == true);
try std.testing.expect((try sl.insert(66, {})) == true);
try std.testing.expect((try sl.remove(std.testing.allocator, 13)) == false);
try std.testing.expect((try sl.remove(std.testing.allocator, 12)) == true);
try std.testing.expect((try sl.remove(std.testing.allocator, 12)) == false);
try std.testing.expect((try sl.remove(std.testing.allocator, std.math.minInt(KeyType))) == true);
try std.testing.expect((try sl.remove(13)) == false);
try std.testing.expect((try sl.remove(12)) == true);
try std.testing.expect((try sl.remove(12)) == false);
try std.testing.expect((try sl.remove(std.math.minInt(KeyType))) == true);