Releases: alexbishop/zig-rbtree
v1.2.0
Changes
Now supports Zig version 0.16.0 as a minimum version.
How to Use
To use this package, add it as a dependency by running the following command.
zig fetch --save https://github.com/alexbishop/zig-rbtree/archive/refs/tags/v1.2.0.zip
This will update your build.zig.zon file with the correct url and hash for the package.
You can then import this package as a module by adding the following to the main function of you build.zig file
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");For each dependency, you may then ads this module as follows:
dep.root_module.addImport("rbtree", rbtree_module);Example
(Note: the following code has changed from the previous release so that it matches Zig v0.15.1)
Add the module to the appropriate libraries and executables in build.zig. For example:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// get the module for red-black trees
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");
const exe = b.addExecutable(.{
.name = "example-exe",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
// add the module
exe.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(exe);
}You can now import it as rbtree: For example, the contents of src/main.zig could be
const std = @import("std");
const rbtreelib = @import("rbtree");
pub const DefaultRBTree = rbtreelib.DefaultRBTree;
pub fn main(init: std.process.Init) !void {
const allocator = init.gpa;
const Tree = DefaultRBTree(i32, f32);
var tree = Tree.init(allocator, void{});
defer tree.deinit();
// insert some stuff into the tree
var index: i32 = -19;
while (index < 20) : (index += 1) {
const value = std.math.pow(
f32,
0.5,
@floatFromInt(index),
);
try tree.put(index, value);
}
// print the contents of the tree
{
std.debug.print("First print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
// remove some entries from the tree
_ = tree.remove(7);
_ = tree.remove(3);
_ = tree.remove(5);
// print it again
{
std.debug.print("\nSecond print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
}v1.1.1
Changes
Now supports Zig version 0.15.1 as a minimum version.
How to Use
To use this package, add it as a dependency by running the following command.
zig fetch --save https://github.com/alexbishop/zig-rbtree/archive/refs/tags/v1.1.1.zip
This will update your build.zig.zon file with the correct url and hash for the package.
You can then import this package as a module by adding the following to the main function of you build.zig file
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");For each dependency, you may then ads this module as follows:
dep.root_module.addImport("rbtree", rbtree_module);Example
(Note: the following code has changed from the previous release so that it matches Zig v0.15.1)
Add the module to the appropriate libraries and executables in build.zig. For example:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// get the module for red-black trees
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");
const exe = b.addExecutable(.{
.name = "example-exe",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
// add the module
exe.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(exe);
}You can now import it as rbtree: For example, the contents of src/main.zig could be
const std = @import("std");
const rbtreelib = @import("rbtree");
pub const DefaultRBTree = rbtreelib.DefaultRBTree;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const Tree = DefaultRBTree(i32, f32);
var tree = Tree.init(allocator, void{});
defer tree.deinit();
// insert some stuff into the tree
var index: i32 = -19;
while (index < 20) : (index += 1) {
const value = std.math.pow(
f32,
0.5,
@floatFromInt(index),
);
try tree.put(index, value);
}
// print the contents of the tree
{
std.debug.print("First print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
// remove some entries from the tree
_ = tree.remove(7);
_ = tree.remove(3);
_ = tree.remove(5);
// print it again
{
std.debug.print("\nSecond print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
}v1.1.0
Changes
Adds the functions advanceNext and advancePrev to the index_functions namespace. These functions are also tested.
How to Use
To use this package, add it as a dependency by running the following command.
zig fetch --save https://github.com/alexbishop/zig-rbtree/archive/refs/tags/v1.1.0.zip
This will update your build.zig.zon file with the correct url and hash for the package.
You can then import this package as a module by adding the following to the main function of you build.zig file
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");For each dependency, you may then ads this module as follows:
dep.root_module.addImport("rbtree", rbtree_module);Example
Add the module to the appropriate libraries and executables in build.zig. For example:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// get the module for red-black trees
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");
const exe = b.addExecutable(.{
.name = "example-exe",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// add the module
exe.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(exe);
}You can now import it as rbtree: For example, the contents of src/main.zig could be
const std = @import("std");
const rbtreelib = @import("rbtree");
pub const DefaultRBTree = rbtreelib.DefaultRBTree;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const Tree = DefaultRBTree(i32, f32);
var tree = Tree.init(allocator, void{});
defer tree.deinit();
// insert some stuff into the tree
var index: i32 = -19;
while (index < 20) : (index += 1) {
const value = std.math.pow(
f32,
0.5,
@floatFromInt(index),
);
try tree.put(index, value);
}
// print the contents of the tree
{
std.debug.print("First print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
// remove some entries from the tree
_ = tree.remove(7);
_ = tree.remove(3);
_ = tree.remove(5);
// print it again
{
std.debug.print("\nSecond print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
}v1.0.2
Changes
Fixes issues with clone methods and adds tests to ensure that they work.
How to Use
To use this package, add it as a dependency by running the following command.
zig fetch --save https://github.com/alexbishop/zig-rbtree/archive/refs/tags/v1.0.2.zip
This will update your build.zig.zon file with the correct url and hash for the package.
You can then import this package as a module by adding the following to the main function of you build.zig file
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");For each dependency, you may then ads this module as follows:
dep.root_module.addImport("rbtree", rbtree_module);Example
Add the module to the appropriate libraries and executables in build.zig. For example:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// get the module for red-black trees
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");
const exe = b.addExecutable(.{
.name = "example-exe",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// add the module
exe.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(exe);
}You can now import it as rbtree: For example, the contents of src/main.zig could be
const std = @import("std");
const rbtreelib = @import("rbtree");
pub const DefaultRBTree = rbtreelib.DefaultRBTree;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const Tree = DefaultRBTree(i32, f32);
var tree = Tree.init(allocator, void{});
defer tree.deinit();
// insert some stuff into the tree
var index: i32 = -19;
while (index < 20) : (index += 1) {
const value = std.math.pow(
f32,
0.5,
@floatFromInt(index),
);
try tree.put(index, value);
}
// print the contents of the tree
{
std.debug.print("First print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
// remove some entries from the tree
_ = tree.remove(7);
_ = tree.remove(3);
_ = tree.remove(5);
// print it again
{
std.debug.print("\nSecond print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
}v1.0.1
Warning
You should use version 1.0.2 instead of this version.
Changes
This release fixes issues with the functions postfixPrev, prefixNext, and prefixPrev; and issues with cached nodes.
This version all adds new tests to confirm that these new versions of the functions are correctly implemented.
How to Use
To use this package, add it as a dependency by running the following command.
zig fetch --save https://github.com/alexbishop/zig-rbtree/archive/refs/tags/v1.0.1.zip
This will update your build.zig.zon file with the correct url and hash for the package.
You can then import this package as a module by adding the following to the main function of you build.zig file
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");For each dependency, you may then ads this module as follows:
dep.root_module.addImport("rbtree", rbtree_module);Example
Add the module to the appropriate libraries and executables in build.zig. For example:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// get the module for red-black trees
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");
const exe = b.addExecutable(.{
.name = "example-exe",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// add the module
exe.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(exe);
}You can now import it as rbtree: For example, the contents of src/main.zig could be
const std = @import("std");
const rbtreelib = @import("rbtree");
pub const DefaultRBTree = rbtreelib.DefaultRBTree;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const Tree = DefaultRBTree(i32, f32);
var tree = Tree.init(allocator, void{});
defer tree.deinit();
// insert some stuff into the tree
var index: i32 = -19;
while (index < 20) : (index += 1) {
const value = std.math.pow(
f32,
0.5,
@floatFromInt(index),
);
try tree.put(index, value);
}
// print the contents of the tree
{
std.debug.print("First print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
// remove some entries from the tree
_ = tree.remove(7);
_ = tree.remove(3);
_ = tree.remove(5);
// print it again
{
std.debug.print("\nSecond print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
}v1.0.0
Warning
You should use version 1.0.2 instead of this version.
How to Use
To use this package, add it as a dependency by running the following command.
zig fetch --save https://github.com/alexbishop/zig-rbtree/archive/refs/tags/v1.0.0.zip
This will update your build.zig.zon file with the correct url and hash for the package.
You can then import this package as a module by adding the following to the main function of you build.zig file
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");For each dependency, you may then ads this module as follows:
dep.root_module.addImport("rbtree", rbtree_module);Example
Add the module to the appropriate libraries and executables in build.zig. For example:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// get the module for red-black trees
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");
const exe = b.addExecutable(.{
.name = "example-exe",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// add the module
exe.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(exe);
}You can now import it as rbtree: For example, the contents of src/main.zig could be
const std = @import("std");
const rbtreelib = @import("rbtree");
pub const DefaultRBTree = rbtreelib.DefaultRBTree;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const Tree = DefaultRBTree(i32, f32);
var tree = Tree.init(allocator, void{});
defer tree.deinit();
// insert some stuff into the tree
var index: i32 = -19;
while (index < 20) : (index += 1) {
const value = std.math.pow(
f32,
0.5,
@floatFromInt(index),
);
try tree.put(index, value);
}
// print the contents of the tree
{
std.debug.print("First print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
// remove some entries from the tree
_ = tree.remove(7);
_ = tree.remove(3);
_ = tree.remove(5);
// print it again
{
std.debug.print("\nSecond print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
}v0.3.0
How to Use
To use this package, add it as a dependency by running the following command.
zig fetch --save https://github.com/alexbishop/zig-rbtree/archive/refs/tags/v0.3.0.zip
This will update your build.zig.zon file with the correct url and hash for the package.
You can then import this package as a module by adding the following to the main function of you build.zig file
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");For each dependency, you may then ads this module as follows:
dep.root_module.addImport("rbtree", rbtree_module);Example
Add the module to the appropriate libraries and executables in build.zig. For example:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// get the module for red-black trees
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");
const exe = b.addExecutable(.{
.name = "example-exe",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// add the module
exe.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(exe);
}You can now import it as rbtree: For example, the contents of src/main.zig could be
const std = @import("std");
const rbtreelib = @import("rbtree");
pub const DefaultRBTree = rbtreelib.DefaultRBTree;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const Tree = DefaultRBTree(i32, f32);
var tree = Tree.init(allocator, void{});
defer tree.deinit();
// insert some stuff into the tree
var index: i32 = -19;
while (index < 20) : (index += 1) {
const value = std.math.pow(
f32,
0.5,
@floatFromInt(index),
);
try tree.put(index, value);
}
// print the contents of the tree
{
std.debug.print("First print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
// remove some entries from the tree
_ = tree.remove(7);
_ = tree.remove(3);
_ = tree.remove(5);
// print it again
{
std.debug.print("\nSecond print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
}v0.2.0
How to Use
To use this package, add it as a dependency by running the following command.
zig fetch --save https://github.com/alexbishop/zig-rbtree/archive/refs/tags/v0.2.0.zip
This will update your build.zig.zon file with the correct url and hash for the package.
You can then import this package as a module by adding the following to the main function of you build.zig file
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");For each dependency, you may then ads this module as follows:
dep.root_module.addImport("rbtree", rbtree_module);Example
Add the module to the appropriate libraries and executables in build.zig. For example:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// get the module for red-black trees
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");
const exe = b.addExecutable(.{
.name = "example-exe",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// add the module
exe.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(exe);
}You can now import it as rbtree: For example, the contents of src/main.zig could be
const std = @import("std");
const rbtreelib = @import("rbtree");
pub const DefaultRBTree = rbtreelib.DefaultRBTree;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const Tree = DefaultRBTree(i32, f32);
var tree = Tree.init(allocator, void{});
defer tree.deinit();
// insert some stuff into the tree
var index: i32 = -19;
while (index < 20) : (index += 1) {
const value = std.math.pow(
f32,
0.5,
@floatFromInt(index),
);
try tree.put(index, value);
}
// print the contents of the tree
{
std.debug.print("First print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
// remove some entries from the tree
_ = tree.remove(7);
_ = tree.remove(3);
_ = tree.remove(5);
// print it again
{
std.debug.print("\nSecond print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
}v0.1.0
How to Use
To use this package, add it as a dependency by running the following command.
zig fetch --save https://github.com/alexbishop/zig-rbtree/archive/refs/tags/v0.1.0.zip
This will update your build.zig.zon file with the correct url and hash for the package.
You can then import this package as a module by adding the following to the main function of you build.zig file
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");For each dependency, you may then ads this module as follows:
dep.root_module.addImport("rbtree", rbtree_module);Example
Add the module to the appropriate libraries and executables in build.zig. For example:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// get the module for red-black trees
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");
const lib = b.addStaticLibrary(.{
.name = "example-lib",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
// add the module
lib.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(lib);
const exe = b.addExecutable(.{
.name = "example-exe",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// add the module
exe.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(exe);
}You can now import it as rbtree: For example, the contents of main.zig could be
const std = @import("std");
const rbtreelib = @import("rbtree");
pub const DefaultRBTree = rbtreelib.DefaultRBTree;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const Tree = DefaultRBTree(i32, f32);
var tree = Tree.init(allocator, void{});
defer tree.deinit();
// insert some stuff into the tree
var index: i32 = -19;
while (index < 20) : (index += 1) {
const value = std.math.pow(
f32,
0.5,
@floatFromInt(index),
);
try tree.put(index, value);
}
// print the contents of the tree
{
std.debug.print("First print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
// remove some entries from the tree
_ = tree.remove(7);
_ = tree.remove(3);
_ = tree.remove(5);
// print it again
{
std.debug.print("\nSecond print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
}
v0.0.5
How to Use
To use this package, add it as a dependency by running the following command.
zig fetch --save https://github.com/alexbishop/zig-rbtree/archive/refs/tags/v0.0.5.zip
This will update your build.zig.zon file with the correct url and hash for the package.
You can then import this package as a module by adding the following to the main function of you build.zig file
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");For each dependency, you may then ads this module as follows:
dep.root_module.addImport("rbtree", rbtree_module);Example
Add the module to the appropriate libraries and executables in build.zig. For example:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// get the module for red-black trees
const rbtree = b.dependency("rbtree", .{
.target = target,
.optimize = optimize,
});
const rbtree_module = rbtree.module("rbtree");
const lib = b.addStaticLibrary(.{
.name = "example-lib",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
// add the module
lib.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(lib);
const exe = b.addExecutable(.{
.name = "example-exe",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// add the module
exe.root_module.addImport("rbtree", rbtree_module);
b.installArtifact(exe);
}You can now import it as rbtree: For example, the contents of main.zig could be
const std = @import("std");
const rbtreelib = @import("rbtree");
pub const DefaultRBTree = rbtreelib.DefaultRBTree;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const Tree = DefaultRBTree(i32, f32);
var tree = Tree.init(allocator, void{});
defer tree.deinit();
// insert some stuff into the tree
var index: i32 = -19;
while (index < 20) : (index += 1) {
const value = std.math.pow(
f32,
0.5,
@floatFromInt(index),
);
try tree.put(index, value);
}
// print the contents of the tree
{
std.debug.print("First print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
// remove some entries from the tree
_ = tree.remove(7);
_ = tree.remove(3);
_ = tree.remove(5);
// print it again
{
std.debug.print("\nSecond print\n", .{});
var current: ?*Tree.Node = tree.findMin();
while (current) |c| : (current = c.next()) {
std.debug.print("Node {} -> {}\n", .{ c.key, c.value });
}
}
}