forked from fasterthanlime/stringsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56065d5
commit f56039d
Showing
28 changed files
with
167 additions
and
669 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
[package] | ||
name = "divsufsort" | ||
version = "0.1.0" | ||
authors = ["Amos Wenger <[email protected]>"] | ||
edition = "2018" | ||
[workspace] | ||
members = [ | ||
"crates/divsufsort", | ||
"crates/cdivsufsort", | ||
"crates/divsuftest", | ||
] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
better-panic = "0.2.0" | ||
once_cell = "1.2.0" | ||
suffix_array = "0.4.0" | ||
|
||
[build-dependencies] | ||
cc = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "cdivsufsort" | ||
version = "0.1.0" | ||
authors = ["Amos Wenger <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
|
||
[build-dependencies] | ||
cc = "1.0.47" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
extern "C" { | ||
pub fn divsufsort(T: *const u8, SA: *mut i32, n: i32) -> i32; | ||
pub fn dss_flush(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "divsufsort" | ||
version = "0.1.0" | ||
authors = ["Amos Wenger <[email protected]>"] | ||
edition = "2018" | ||
|
||
[features] | ||
crosscheck = ["once_cell"] | ||
|
||
[dependencies] | ||
once_cell = { version = "1.2.0", optional = true } |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![allow(nonstandard_style)] | ||
#![allow(unused_variables)] | ||
#![allow(unused_parens)] | ||
#![allow(unused_mut)] | ||
#![allow(unused_imports)] | ||
#![allow(dead_code)] | ||
|
||
mod common; | ||
pub mod crosscheck; | ||
mod divsufsort; | ||
mod sssort; | ||
mod trsort; | ||
|
||
pub use common::Idx; | ||
pub use divsufsort::divsufsort; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "divsuftest" | ||
version = "0.1.0" | ||
authors = ["Amos Wenger <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
divsufsort = { path = "../divsufsort" } | ||
cdivsufsort = { path = "../cdivsufsort" } | ||
suffix_array = "0.4.0" | ||
better-panic = "0.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::time::Instant; | ||
|
||
fn main() { | ||
better_panic::install(); | ||
|
||
let first_arg = std::env::args().nth(1).unwrap_or_else(|| { | ||
std::path::PathBuf::from("testdata") | ||
.join("input.txt") | ||
.to_string_lossy() | ||
.into() | ||
}); | ||
let input = std::fs::read(first_arg).unwrap(); | ||
|
||
#[cfg(debug_assertions)] | ||
println!("{:>20} Running", "C"); | ||
|
||
let mut sa_c = vec![0 as divsufsort::Idx; input.len()]; | ||
let before_c = Instant::now(); | ||
let c_duration; | ||
|
||
unsafe { | ||
cdivsufsort::divsufsort(input.as_ptr(), sa_c.as_mut_ptr(), input.len() as i32); | ||
c_duration = before_c.elapsed(); | ||
cdivsufsort::dss_flush(); | ||
} | ||
|
||
for i in 0..(sa_c.len() - 1) { | ||
assert!( | ||
input[sa_c[i] as usize..] < input[sa_c[i + 1] as usize..], | ||
"suffixes should be ordered" | ||
); | ||
} | ||
|
||
#[cfg(debug_assertions)] | ||
println!("{:>20} Running...", "Rust"); | ||
|
||
{ | ||
let res = std::panic::catch_unwind(|| { | ||
let mut sa_rust = vec![0 as divsufsort::Idx; input.len()]; | ||
let before_rust = Instant::now(); | ||
|
||
std::thread::spawn(|| loop { | ||
std::thread::sleep(std::time::Duration::from_millis(500)); | ||
divsufsort::crosscheck::flush(); | ||
}); | ||
|
||
divsufsort::divsufsort(&input[..], &mut sa_rust[..]); | ||
let rust_duration = before_rust.elapsed(); | ||
assert!(sa_c == sa_rust, "c & rust divsufsort SAs should be equal"); | ||
|
||
#[cfg(debug_assertions)] | ||
println!("{:>20} Running...", "huc"); | ||
|
||
let huc_duration = { | ||
let before_huc = Instant::now(); | ||
let sa = suffix_array::SuffixArray::new(&input[..]); | ||
let (_, sa) = sa.into_parts(); | ||
let sa = &sa[1..]; | ||
|
||
for i in 0..sa_c.len() { | ||
assert_eq!(sa_c[i], sa[i] as i32); | ||
} | ||
before_huc.elapsed() | ||
}; | ||
|
||
let s1 = format!("c {:?}", c_duration); | ||
let s2 = format!("rust {:?}", rust_duration); | ||
let s3 = format!("rust-ref {:?}", huc_duration); | ||
println!("{:30} {:30} {:30}", s1, s2, s3); | ||
}); | ||
divsufsort::crosscheck::flush(); | ||
res.unwrap() | ||
}; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.