P7OMU7PBSC76C6FLDU3TT6ZRSKMNRTYAA4IM65ICVIHSMNUQWRBAC test "Pugh" {const KeyType = usize;const SL = Pugh(KeyType, void, {}, comptime std.sort.asc(KeyType));var sl = try SL.init(std.testing.allocator, 4, 16);defer sl.deinit();try sl.insert(3, {});try sl.insert(6, {});try sl.insert(7, {});try sl.insert(9, {});try sl.insert(0, {});try sl.insert(std.math.minInt(KeyType), {});try sl.insert(12, {});try sl.insert(12, {}); // does nothingtry sl.insert(12, {}); // does nothingtry sl.insert(19, {});try sl.insert(17, {});try sl.insert(26, {});try sl.insert(21, {});try sl.insert(25, {});sl.display();try std.testing.expectEqual(@as(KeyType, 12), sl.search(12).?.key.?);try std.testing.expectEqual(@as(KeyType, 26), sl.search(26).?.key.?);try std.testing.expectEqual(@as(?*SL.Node, null), sl.search(13));try std.testing.expectEqual(true, try sl.remove(12));try std.testing.expectEqual(false, try sl.remove(12));_ = try sl.remove(std.math.minInt(KeyType));}
test "Pugh" {const KeyType = usize;const SL = Pugh(KeyType, void, {}, comptime std.sort.asc(KeyType));var sl = try SL.init(std.testing.allocator, DEFAULT_SKIP_SIZE, 16);
const SkipList = struct {pub usingnamespace @import("pugh.zig");pub usingnamespace @import("lazy.zig");};const BENCH_ITEMS = 100_000;const BENCH_KEY = usize;const BENCH_VALUE = void;const BENCH_SKIP_SIZE = 4;pub fn main() !void {var gpa = std.heap.GeneralPurposeAllocator(.{}){};var arena = std.heap.ArenaAllocator.init(gpa.allocator());defer arena.deinit();var sl = try SkipList.Pugh(BENCH_KEY, BENCH_VALUE, {}, comptime std.sort.asc(BENCH_KEY)).init(arena.allocator(), BENCH_SKIP_SIZE, BENCH_ITEMS);
try sl.insert(3, {});try sl.insert(6, {});try sl.insert(7, {});try sl.insert(9, {});try sl.insert(0, {});try sl.insert(std.math.minInt(KeyType), {});try sl.insert(12, {});try sl.insert(12, {}); // does nothingtry sl.insert(12, {}); // does nothingtry sl.insert(19, {});try sl.insert(17, {});try sl.insert(26, {});try sl.insert(21, {});try sl.insert(25, {});
var rand = std.rand.DefaultPrng.init(@intCast(u64, std.time.milliTimestamp()));const rnd = rand.random();
try std.testing.expectEqual(@as(KeyType, 12), sl.search(12).?.key.?);try std.testing.expectEqual(@as(KeyType, 26), sl.search(26).?.key.?);try std.testing.expectEqual(@as(?*SL.Node, null), sl.search(13));try std.testing.expectEqual(true, try sl.remove(12));try std.testing.expectEqual(false, try sl.remove(12));
var i: usize = 0;while (i < BENCH_ITEMS) : (i += 1) {const key = rnd.intRangeAtMostBiased(BENCH_KEY, std.math.minInt(BENCH_KEY) + 1, std.math.maxInt(BENCH_KEY) - 1);try sl.insert(key, {});}
// Standard target options allows the person running `zig build` to choose// what target to build for. Here we do not override the defaults, which// means any target is allowed, and the default is native. Other options// for restricting supported target set are available.const target = b.standardTargetOptions(.{});
const test_step = b.step("test", "Run library tests");test_step.dependOn(&main_tests.step);
const run_step = b.step("run", "Run the app");run_step.dependOn(&run_cmd.step);const exe_tests = b.addTest("src/main.zig");exe_tests.setTarget(target);exe_tests.setBuildMode(mode);const test_step = b.step("test", "Run unit tests");test_step.dependOn(&exe_tests.step);
**/zig-out