divsufsort-rs 0.3.0

Pure Rust port of libdivsufsort suffix array construction library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/// FFI bindings to the vendored C libdivsufsort (32-bit index variant).
use std::os::raw::{c_int, c_uchar};

#[link(name = "divsufsort_c", kind = "static")]
unsafe extern "C" {
    /// Constructs the suffix array of T[0..n-1].
    /// Returns 0 on success, negative on error.
    pub fn divsufsort(t: *const c_uchar, sa: *mut c_int, n: c_int) -> c_int;
}

/// Safe wrapper that mirrors the Rust `divsufsort` API.
pub fn divsufsort_c(t: &[u8], sa: &mut [i32]) -> i32 {
    assert_eq!(t.len(), sa.len());
    unsafe { divsufsort(t.as_ptr(), sa.as_mut_ptr(), t.len() as c_int) }
}