Skip to content

Commit 0a71d5b

Browse files
sacabase 2.0.0, introduce sacapart
1 parent 6ee1b28 commit 0a71d5b

File tree

9 files changed

+240
-59
lines changed

9 files changed

+240
-59
lines changed

Cargo.lock

+28-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = [
33
"crates/sacabase",
4+
"crates/sacapart",
45
"crates/divsufsort",
56
"crates/cdivsufsort",
67
"crates/divsuftest",

crates/cdivsufsort/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cdivsufsort"
3-
version = "1.0.0"
3+
version = "2.0.0"
44
authors = ["Amos Wenger <[email protected]>"]
55
edition = "2018"
66

@@ -15,7 +15,7 @@ license = "MIT"
1515
crosscheck = []
1616

1717
[dependencies]
18-
sacabase = { path = "../sacabase", version = "1.0.0" }
18+
sacabase = { path = "../sacabase", version = "2.0.0" }
1919

2020
[build-dependencies]
2121
cc = "1.0.47"

crates/divsufsort/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "divsufsort"
3-
version = "1.0.2"
3+
version = "2.0.0"
44
authors = ["Amos Wenger <[email protected]>"]
55
edition = "2018"
66

@@ -16,4 +16,4 @@ crosscheck = ["once_cell"]
1616

1717
[dependencies]
1818
once_cell = { version = "1.2.0", optional = true }
19-
sacabase = { path = "../sacabase", version = "1.0.0" }
19+
sacabase = { path = "../sacabase", version = "2.0.0" }

crates/divsuftest/src/main.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use failure::Fallible;
22
use size_format::SizeFormatterBinary;
3-
use std::{env, io::Write, process, time::Instant};
3+
use std::{io::Write, process, time::Instant};
44

55
struct Args {
6-
partitions: u32,
76
free: Vec<String>,
87
}
98

@@ -27,11 +26,8 @@ impl Command {
2726
fn main() -> Fallible<()> {
2827
better_panic::install();
2928

30-
let mut args = pico_args::Arguments::from_env();
31-
let args = Args {
32-
partitions: args.opt_value_from_str("--partitions")?.unwrap_or(1),
33-
free: args.free()?,
34-
};
29+
let args = pico_args::Arguments::from_env();
30+
let args = Args { free: args.free()? };
3531

3632
if args.free.is_empty() {
3733
usage();

crates/sacabase/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sacabase"
3-
version = "1.0.0"
3+
version = "2.0.0"
44
authors = ["Amos Wenger <[email protected]>"]
55
edition = "2018"
66

crates/sacabase/src/lib.rs

+24-19
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use num_traits::ToPrimitive;
22
use std::{cmp::min, fmt};
33

44
pub struct LongestCommonSubstring<'a> {
5-
text: &'a [u8],
6-
start: usize,
7-
len: usize,
5+
pub text: &'a [u8],
6+
pub start: usize,
7+
pub len: usize,
88
}
99

1010
impl<'a> fmt::Debug for LongestCommonSubstring<'a> {
@@ -18,16 +18,6 @@ impl<'a> LongestCommonSubstring<'a> {
1818
pub fn as_bytes(&self) -> &[u8] {
1919
&self.text[self.start..self.start + self.len]
2020
}
21-
22-
#[inline(always)]
23-
pub fn start(&self) -> usize {
24-
self.start
25-
}
26-
27-
#[inline(always)]
28-
pub fn len(&self) -> usize {
29-
self.len
30-
}
3121
}
3222

3323
/// Returns the number of bytes `a` and `b` have in common.
@@ -52,7 +42,7 @@ pub fn longest_substring_match<'a, Index>(
5242
needle: &[u8],
5343
) -> LongestCommonSubstring<'a>
5444
where
55-
Index: num_traits::ToPrimitive,
45+
Index: ToPrimitive,
5646
{
5747
macro_rules! sa {
5848
($x: expr) => {
@@ -167,6 +157,11 @@ where
167157
text: &'a [u8],
168158
}
169159

160+
pub trait StringIndex<'a> {
161+
/// Returns the longest substring that matches `needle` in text
162+
fn longest_substring_match(&self, needle: &[u8]) -> LongestCommonSubstring<'a>;
163+
}
164+
170165
impl<'a, Index> SuffixArray<'a, Index>
171166
where
172167
Index: ToPrimitive,
@@ -176,19 +171,29 @@ where
176171
Self { sa, text }
177172
}
178173

179-
/// Returns the longest
180-
pub fn longest_substring_match(&self, needle: &[u8]) -> LongestCommonSubstring<'a> {
181-
longest_substring_match(self.text, &self.sa[..], needle)
182-
}
183-
184174
/// Return (text, sa), giving back ownership of `sa`
185175
pub fn into_parts(self) -> (&'a [u8], Vec<Index>) {
186176
(self.text, self.sa)
187177
}
188178

179+
/// Verifies that this suffix array is sorted.
189180
pub fn verify(&self) -> Result<(), NotSorted> {
190181
verify(self.text, &self.sa[..])
191182
}
183+
184+
/// Returns a reference to the text
185+
pub fn text(&self) -> &[u8] {
186+
return self.text;
187+
}
188+
}
189+
190+
impl<'a, Index> StringIndex<'a> for SuffixArray<'a, Index>
191+
where
192+
Index: ToPrimitive,
193+
{
194+
fn longest_substring_match(&self, needle: &[u8]) -> LongestCommonSubstring<'a> {
195+
longest_substring_match(self.text, &self.sa[..], needle)
196+
}
192197
}
193198

194199
#[cfg(test)]

crates/sacapart/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "sacapart"
3+
version = "2.0.0"
4+
authors = ["Amos Wenger <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
sacabase = { path = "../sacabase", version = "2.0.0" }
9+
num-traits = "0.2.9"
10+
rayon = "1.2.1"
11+
12+
[dev-dependencies]
13+
divsufsort = { path = "../divsufsort", version = "2.0.0" }

0 commit comments

Comments
 (0)