diff options
| author | Andrew Guschin <guschin.drew@gmail.com> | 2023-08-13 01:27:00 +0400 |
|---|---|---|
| committer | Andrew Guschin <guschin.drew@gmail.com> | 2023-08-13 06:00:02 -0500 |
| commit | 58acff54b1cd64cb23b9d0b1a304eb9db768e3eb (patch) | |
| tree | 87281f776e0015f218aadb5cbfdad43c66406342 /src/main.rs | |
Initial commit
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..9e695a6 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,56 @@ +use std::iter::Iterator; +use std::ptr; + +#[allow(non_camel_case_types)] +enum geng_iterator {} + +extern "C" { + fn geng_iterator_init(iter: *const geng_iterator, n: i32); + fn geng_iterator_next(iter: *const geng_iterator, g: *mut i32) -> bool; + fn printgraph(g: *const i32, n: i32); +} + +fn print_graph(g: Vec<i32>, n: usize) { + unsafe { + printgraph(g.as_ptr(), n as i32); + } +} + +struct GengIterator { + pub size: usize, +} + +impl GengIterator { + fn new(n: usize) -> GengIterator { + unsafe { + geng_iterator_init(ptr::null(), n as i32); + } + GengIterator { size: n } + } +} + +impl Iterator for &GengIterator { + type Item = Vec<i32>; + + fn next(&mut self) -> Option<Self::Item> { + let mut g = vec![0; self.size]; + let res; + unsafe { res = geng_iterator_next(ptr::null(), g.as_mut_ptr()) } + if res { + Some(g) + } else { + None + } + } +} + +fn main() { + let gi = GengIterator::new(12); + + let q = gi.skip(1000).next(); + println!("{:?}", q); + print_graph(q.unwrap(), gi.size); + // for i in &gi { + // print_graph(i, gi.size); + // } +} |