improve doc comments
This commit is contained in:
parent
845582a14d
commit
ee8d0cde34
@ -59,4 +59,13 @@ pub fn build(b: *std.Build) void {
|
||||
|
||||
const test_step = b.step("test", "Run unit tests");
|
||||
test_step.dependOn(&run_lib_unit_tests.step);
|
||||
|
||||
// ---- document generation
|
||||
const install_docs = b.addInstallDirectory(.{
|
||||
.source_dir = lib.getEmittedDocs(),
|
||||
.install_dir = .prefix,
|
||||
.install_subdir = "docs",
|
||||
});
|
||||
const docs_step = b.step("docs", "Install docs into zig-out/docs");
|
||||
docs_step.dependOn(&install_docs.step);
|
||||
}
|
||||
|
@ -3,14 +3,23 @@ const std = @import("std");
|
||||
/// A data type to store connections of nodes in directional-graph.
|
||||
pub fn Digraph(comptime T: type, comptime lessThanFn: LessThanFunc(T)) type {
|
||||
return struct {
|
||||
const Node = T;
|
||||
const Conn = struct { from: T, to: T, };
|
||||
///
|
||||
const Node = T;
|
||||
|
||||
/// A connection between 2 nodes.
|
||||
/// e.g.) `Conn { .from = X, .to = Y }` => "X is connected to Y"
|
||||
const Conn = struct { from: T, to: T, };
|
||||
|
||||
///
|
||||
const ConnList = std.ArrayList(Conn);
|
||||
const Error = error {
|
||||
|
||||
///
|
||||
const Error = error {
|
||||
AlreadyConnected,
|
||||
NotConnected,
|
||||
};
|
||||
|
||||
///
|
||||
map: ConnList,
|
||||
|
||||
///
|
||||
@ -31,7 +40,8 @@ pub fn Digraph(comptime T: type, comptime lessThanFn: LessThanFunc(T)) type {
|
||||
self.map.deinit();
|
||||
}
|
||||
|
||||
///
|
||||
/// Makes new connection between `from` to `to`.
|
||||
/// Returns false if they are already connected otherwise true.
|
||||
pub fn connectIf(self: *@This(), from: T, to: T) !bool {
|
||||
const begin, const end = self.findSegment(from);
|
||||
if (self.findConnectionInSegment(from, to, begin, end)) |_| {
|
||||
@ -48,7 +58,8 @@ pub fn Digraph(comptime T: type, comptime lessThanFn: LessThanFunc(T)) type {
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Removes an existing connection between `from` to `to`.
|
||||
/// Returns false if they are not connected otherwise true.
|
||||
pub fn disconnectIf(self: *@This(), from: T, to: T) bool {
|
||||
const begin, const end = self.findSegment(from);
|
||||
if (self.findConnectionInSegment(from, to, begin, end)) |idx| {
|
||||
|
@ -1,7 +1,11 @@
|
||||
const std = @import("std");
|
||||
|
||||
///
|
||||
pub const Node = struct {
|
||||
id : usize,
|
||||
/// unique and immutable integer
|
||||
id: usize,
|
||||
|
||||
/// summary text of this node
|
||||
summary: []const u8,
|
||||
|
||||
///
|
||||
|
@ -8,7 +8,10 @@ pub fn Store(comptime T: type) type {
|
||||
deinitItem: ?*fn (?*anyopaque, *T) void = null,
|
||||
};
|
||||
return struct {
|
||||
///
|
||||
const Item = T;
|
||||
|
||||
/// A struct which holds an item and its reference count.
|
||||
const Slot = struct {
|
||||
item : Item,
|
||||
refcnt: usize,
|
||||
@ -20,21 +23,27 @@ pub fn Store(comptime T: type) type {
|
||||
self.refcnt -= 1;
|
||||
}
|
||||
};
|
||||
const Slots = std.ArrayList(*Slot);
|
||||
|
||||
///
|
||||
const Error = error {
|
||||
DetectedItemLeak,
|
||||
};
|
||||
|
||||
///
|
||||
alloc : std.mem.Allocator,
|
||||
|
||||
///
|
||||
vtable: VTable,
|
||||
slots : Slots,
|
||||
|
||||
///
|
||||
slots : std.ArrayList(Slot),
|
||||
|
||||
///
|
||||
pub fn init(alloc: std.mem.Allocator, vtable: VTable) @This() {
|
||||
return .{
|
||||
.alloc = alloc,
|
||||
.vtable = vtable,
|
||||
.slots = Slots.init(alloc),
|
||||
.slots = std.ArrayList(Slot).init(alloc),
|
||||
};
|
||||
}
|
||||
///
|
||||
@ -48,7 +57,7 @@ pub fn Store(comptime T: type) type {
|
||||
}
|
||||
|
||||
/// Returns a slot which contains newly-allocated item.
|
||||
/// - A reference count of the returned slot must be 1
|
||||
/// - A reference count of the returned slot is 1
|
||||
/// - The returned slot and its contents are alive till the reference count becomes 0
|
||||
pub fn add(self: *@This(), item: Item) !*Slot {
|
||||
for (self.slots.items) |slot| {
|
||||
@ -68,7 +77,7 @@ pub fn Store(comptime T: type) type {
|
||||
}
|
||||
|
||||
/// Releases memory of slots whose reference count is 0.
|
||||
/// Usually no need to call this function because such slots are reused.
|
||||
/// Usually no need to call this function because such slots will be reused.
|
||||
pub fn collectGarbage(self: *@This()) !void {
|
||||
var slots = self.slots.items;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user