Skip to content

Commit 6b88433

Browse files
committed
gut
1 parent 7a83ed8 commit 6b88433

File tree

1 file changed

+2
-177
lines changed

1 file changed

+2
-177
lines changed

src/edge_differences.rs

Lines changed: 2 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,6 @@ use crate::NodeId;
22
use crate::Position;
33
use crate::TreeSequence;
44

5-
use crate::sys::bindings;
6-
7-
#[repr(transparent)]
8-
struct LLEdgeDifferenceIterator(bindings::tsk_diff_iter_t);
9-
10-
impl Drop for LLEdgeDifferenceIterator {
11-
fn drop(&mut self) {
12-
unsafe { bindings::tsk_diff_iter_free(&mut self.0) };
13-
}
14-
}
15-
16-
impl LLEdgeDifferenceIterator {
17-
pub fn new_from_treeseq(
18-
treeseq: &TreeSequence,
19-
flags: bindings::tsk_flags_t,
20-
) -> Result<Self, crate::TskitError> {
21-
todo!("we need to re-implement this entirely in safe rust w/lifetime bound and hopefully avoiding lending iterator");
22-
let mut inner = std::mem::MaybeUninit::<bindings::tsk_diff_iter_t>::uninit();
23-
let treeseq_ptr = treeseq.as_ptr();
24-
assert!(!treeseq_ptr.is_null());
25-
// SAFETY: treeseq_ptr is not null
26-
let tables_ptr =
27-
unsafe { (*treeseq_ptr).tables } as *const bindings::tsk_table_collection_t;
28-
assert!(!tables_ptr.is_null());
29-
// SAFETY: tables_ptr is not null,
30-
// init of inner will be handled by tsk_diff_iter_init
31-
let num_trees: i32 = treeseq.num_trees().try_into()?;
32-
let code = unsafe {
33-
bindings::tsk_diff_iter_init(inner.as_mut_ptr(), tables_ptr, num_trees, flags)
34-
};
35-
// SAFETY: tsk_diff_iter_init has initialized our object
36-
handle_tsk_return_value!(code, Self(unsafe { inner.assume_init() }))
37-
}
38-
}
39-
405
/// Marker type for edge insertion.
416
pub struct Insertion {}
427

@@ -50,49 +15,6 @@ mod private {
5015
impl EdgeDifferenceIteration for super::Removal {}
5116
}
5217

53-
struct LLEdgeList<T: private::EdgeDifferenceIteration> {
54-
inner: bindings::tsk_edge_list_t,
55-
marker: std::marker::PhantomData<T>,
56-
}
57-
58-
macro_rules! build_lledgelist {
59-
($name: ident, $generic: ty) => {
60-
type $name = LLEdgeList<$generic>;
61-
62-
impl Default for $name {
63-
fn default() -> Self {
64-
Self {
65-
inner: bindings::tsk_edge_list_t {
66-
head: std::ptr::null_mut(),
67-
tail: std::ptr::null_mut(),
68-
},
69-
marker: std::marker::PhantomData::<$generic> {},
70-
}
71-
}
72-
}
73-
};
74-
}
75-
76-
build_lledgelist!(LLEdgeInsertionList, Insertion);
77-
build_lledgelist!(LLEdgeRemovalList, Removal);
78-
79-
/// Concrete type implementing [`Iterator`] over [`EdgeInsertion`] or [`EdgeRemoval`].
80-
/// Created by [`EdgeDifferencesIterator::edge_insertions`] or
81-
/// [`EdgeDifferencesIterator::edge_removals`], respectively.
82-
pub struct EdgeDifferences<'a, T: private::EdgeDifferenceIteration> {
83-
inner: &'a LLEdgeList<T>,
84-
current: *mut bindings::tsk_edge_list_node_t,
85-
}
86-
87-
impl<'a, T: private::EdgeDifferenceIteration> EdgeDifferences<'a, T> {
88-
fn new(inner: &'a LLEdgeList<T>) -> Self {
89-
Self {
90-
inner,
91-
current: std::ptr::null_mut(),
92-
}
93-
}
94-
}
95-
9618
/// An edge difference. Edge insertions and removals are differentiated by
9719
/// marker types [`Insertion`] and [`Removal`], respectively.
9820
#[derive(Debug, Copy, Clone)]
@@ -150,105 +72,8 @@ pub type EdgeInsertion = EdgeDifference<Insertion>;
15072
/// Type alias for [`EdgeDifference<Removal>`]
15173
pub type EdgeRemoval = EdgeDifference<Removal>;
15274

153-
impl<T> Iterator for EdgeDifferences<'_, T>
154-
where
155-
T: private::EdgeDifferenceIteration,
156-
{
157-
type Item = EdgeDifference<T>;
158-
159-
fn next(&mut self) -> Option<Self::Item> {
160-
if self.current.is_null() {
161-
self.current = self.inner.inner.head;
162-
} else {
163-
self.current = unsafe { *self.current }.next;
164-
}
165-
if self.current.is_null() {
166-
None
167-
} else {
168-
let left = unsafe { (*self.current).edge.left };
169-
let right = unsafe { (*self.current).edge.right };
170-
let parent = unsafe { (*self.current).edge.parent };
171-
let child = unsafe { (*self.current).edge.child };
172-
Some(Self::Item::new(left, right, parent, child))
173-
}
174-
}
175-
}
176-
17775
/// Manages iteration over trees to obtain
17876
/// edge differences.
179-
pub struct EdgeDifferencesIterator {
180-
inner: LLEdgeDifferenceIterator,
181-
insertion: LLEdgeInsertionList,
182-
removal: LLEdgeRemovalList,
183-
left: f64,
184-
right: f64,
185-
advanced: i32,
186-
}
187-
188-
impl EdgeDifferencesIterator {
189-
// NOTE: will return None if tskit-c cannot
190-
// allocate memory for internal structures.
191-
pub(crate) fn new_from_treeseq(
192-
treeseq: &TreeSequence,
193-
flags: bindings::tsk_flags_t,
194-
) -> Result<Self, crate::TskitError> {
195-
LLEdgeDifferenceIterator::new_from_treeseq(treeseq, flags).map(|inner| Self {
196-
inner,
197-
insertion: LLEdgeInsertionList::default(),
198-
removal: LLEdgeRemovalList::default(),
199-
left: f64::default(),
200-
right: f64::default(),
201-
advanced: 0,
202-
})
203-
}
204-
205-
fn advance_tree(&mut self) {
206-
// SAFETY: our tree sequence is guaranteed
207-
// to be valid and own its tables.
208-
self.advanced = unsafe {
209-
bindings::tsk_diff_iter_next(
210-
&mut self.inner.0,
211-
&mut self.left,
212-
&mut self.right,
213-
&mut self.removal.inner,
214-
&mut self.insertion.inner,
215-
)
216-
};
217-
}
218-
219-
pub fn left(&self) -> Position {
220-
self.left.into()
221-
}
222-
223-
pub fn right(&self) -> Position {
224-
self.right.into()
225-
}
226-
227-
pub fn interval(&self) -> (Position, Position) {
228-
(self.left(), self.right())
229-
}
230-
231-
pub fn edge_removals(&self) -> impl Iterator<Item = EdgeRemoval> + '_ {
232-
EdgeDifferences::<Removal>::new(&self.removal)
233-
}
234-
235-
pub fn edge_insertions(&self) -> impl Iterator<Item = EdgeInsertion> + '_ {
236-
EdgeDifferences::<Insertion>::new(&self.insertion)
237-
}
238-
}
239-
240-
impl crate::StreamingIterator for EdgeDifferencesIterator {
241-
type Item = EdgeDifferencesIterator;
242-
243-
fn advance(&mut self) {
244-
self.advance_tree()
245-
}
77+
pub struct EdgeDifferencesIterator {}
24678

247-
fn get(&self) -> Option<&Self::Item> {
248-
if self.advanced > 0 {
249-
Some(self)
250-
} else {
251-
None
252-
}
253-
}
254-
}
79+
impl EdgeDifferencesIterator {}

0 commit comments

Comments
 (0)