-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathe6_cartesian_tree_map.zig
More file actions
33 lines (25 loc) · 1.12 KB
/
e6_cartesian_tree_map.zig
File metadata and controls
33 lines (25 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const std = @import("std");
const ordered = @import("ordered");
fn i32Compare(lhs: i32, rhs: i32) std.math.Order {
return std.math.order(lhs, rhs);
}
pub fn main() !void {
const allocator = std.heap.page_allocator;
std.debug.print("## CartesianTreeMap Example ##\n", .{});
var cartesian_tree = ordered.CartesianTreeMap(i32, []const u8, i32Compare).init(allocator);
defer cartesian_tree.deinit();
try cartesian_tree.put(50, "fifty");
try cartesian_tree.put(30, "thirty");
try cartesian_tree.put(70, "seventy");
std.debug.print("CartesianTreeMap size: {d}\n", .{cartesian_tree.count()});
const search_key = 30;
if (cartesian_tree.get(search_key)) |value| {
std.debug.print("Found key {d}: value is '{s}'\n", .{ search_key, value });
}
const removed = cartesian_tree.remove(30);
if (removed) |value| {
std.debug.print("Removed key {d} with value: '{s}'\n", .{ search_key, value });
}
std.debug.print("Size after deletion: {d}\n", .{cartesian_tree.count()});
std.debug.print("Contains {d}? {any}\n\n", .{ search_key, cartesian_tree.contains(search_key) });
}