Skip to content

Commit 74a6743

Browse files
committed
docs (wip): add doc comment for string
1 parent 5ea72a6 commit 74a6743

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

src/string.zig

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! String algorithms.
2+
13
const std = @import("std");
24
const Allocator = std.mem.Allocator;
35
const assert = std.debug.assert;
@@ -382,6 +384,20 @@ pub fn suffixArray(allocator: Allocator, s: []const u8) Allocator.Error![]usize
382384
return saIs(.default, allocator, s2, 255);
383385
}
384386

387+
/// Given a `T` slice `s` of length `n`, it returns the LCP array of `s`.
388+
/// Here, the LCP array of `s` is the array of length `n - 1`,
389+
/// such that the `i`-th element is the length of the LCP (Longest Common Prefix) of `s[sa[i]..n)` and `s[sa[i+1]..n)`.
390+
///
391+
/// # Constraints
392+
///
393+
/// - `sa` is the suffix array of `s`.
394+
/// - $1 \leq n \leq 10^8$
395+
/// - `T` is integer type
396+
///
397+
/// # Complexity
398+
///
399+
/// - $O(n)$
400+
///
385401
// Reference:
386402
// T. Kasai, G. Lee, H. Arimura, S. Arikawa, and K. Park,
387403
// Linear-Time Longest-Common-Prefix Computation in Suffix Arrays and Its
@@ -415,6 +431,18 @@ pub fn lcpArrayArbitrary(comptime T: type, allocator: Allocator, s: []const T, s
415431
return lcp;
416432
}
417433

434+
/// Given a string `s` of length `n`, it returns the LCP array of `s`.
435+
/// Here, the LCP array of `s` is the array of length `n - 1`,
436+
/// such that the `i`-th element is the length of the LCP (Longest Common Prefix) of `s[sa[i]..n)` and `s[sa[i+1]..n)`.
437+
///
438+
/// # Constraints
439+
///
440+
/// - `sa` is the suffix array of `s`.
441+
/// - $1 \leq n \leq 10^8$
442+
///
443+
/// # Complexity
444+
///
445+
/// - $O(n)$
418446
pub fn lcpArray(allocator: Allocator, s: []const u8, sa: []const usize) Allocator.Error![]usize {
419447
return lcpArrayArbitrary(u8, allocator, s, sa);
420448
}
@@ -444,10 +472,22 @@ test lcpArray {
444472
}
445473
}
446474

475+
// Computational Biology
476+
/// Given a `T` slice of length `n`, it returns the slice of length `n`,
477+
/// such that the `i`-th element is the length of the LCP (Longest Common Prefix) of `s[0..n)` and `s[i..n)`.
478+
///
479+
/// # Constraints
480+
///
481+
/// - $0 \leq n \leq 10^8$
482+
/// - `T` is integer type
483+
///
484+
/// # Complexity
485+
///
486+
/// - $O(n)$
487+
///
447488
// Reference:
448489
// D. Gusfield,
449490
// Algorithms on Strings, Trees, and Sequences: Computer Science and
450-
// Computational Biology
451491
pub fn zAlgorithmArbitrary(comptime T: type, allocator: Allocator, s: []const T) Allocator.Error![]usize {
452492
const n = s.len;
453493
var z = try allocator.alloc(usize, n);
@@ -471,6 +511,16 @@ pub fn zAlgorithmArbitrary(comptime T: type, allocator: Allocator, s: []const T)
471511
return z;
472512
}
473513

514+
/// Given a string of length `n`, it returns the slice of length `n`,
515+
/// such that the `i`-th element is the length of the LCP (Longest Common Prefix) of `s[0..n)` and `s[i..n)`.
516+
///
517+
/// # Constraints
518+
///
519+
/// - $0 \leq n \leq 10^8$
520+
///
521+
/// # Complexity
522+
///
523+
/// - $O(n)$
474524
pub fn zAlgorithm(allocator: Allocator, s: []const u8) Allocator.Error![]usize {
475525
return zAlgorithmArbitrary(u8, allocator, s);
476526
}

0 commit comments

Comments
 (0)