##// END OF EJS Templates
rust: MissingAncestors.basesheads()...
Georges Racinet -
r41282:619ee403 default
parent child Browse files
Show More
@@ -10,6 +10,7 b''
10 use super::{Graph, GraphError, Revision, NULL_REVISION};
10 use super::{Graph, GraphError, Revision, NULL_REVISION};
11 use std::cmp::max;
11 use std::cmp::max;
12 use std::collections::{BinaryHeap, HashSet};
12 use std::collections::{BinaryHeap, HashSet};
13 use crate::dagops;
13
14
14 /// Iterator over the ancestors of a given list of revisions
15 /// Iterator over the ancestors of a given list of revisions
15 /// This is a generic type, defined and implemented for any Graph, so that
16 /// This is a generic type, defined and implemented for any Graph, so that
@@ -229,6 +230,19 b' impl<G: Graph> MissingAncestors<G> {'
229 &self.bases
230 &self.bases
230 }
231 }
231
232
233 /// Computes the relative heads of current bases.
234 ///
235 /// The object is still usable after this.
236 pub fn bases_heads(&self) -> Result<HashSet<Revision>, GraphError> {
237 dagops::heads(&self.graph, self.bases.iter())
238 }
239
240 /// Consumes the object and returns the relative heads of its bases.
241 pub fn into_bases_heads(mut self) -> Result<HashSet<Revision>, GraphError> {
242 dagops::retain_heads(&self.graph, &mut self.bases)?;
243 Ok(self.bases)
244 }
245
232 pub fn add_bases(
246 pub fn add_bases(
233 &mut self,
247 &mut self,
234 new_bases: impl IntoIterator<Item = Revision>,
248 new_bases: impl IntoIterator<Item = Revision>,
@@ -556,8 +570,8 b' mod tests {'
556 }
570 }
557
571
558 #[test]
572 #[test]
559 /// Test constructor, add/get bases
573 /// Test constructor, add/get bases and heads
560 fn test_missing_bases() {
574 fn test_missing_bases() -> Result<(), GraphError> {
561 let mut missing_ancestors =
575 let mut missing_ancestors =
562 MissingAncestors::new(SampleGraph, [5, 3, 1, 3].iter().cloned());
576 MissingAncestors::new(SampleGraph, [5, 3, 1, 3].iter().cloned());
563 let mut as_vec: Vec<Revision> =
577 let mut as_vec: Vec<Revision> =
@@ -569,6 +583,11 b' mod tests {'
569 as_vec = missing_ancestors.get_bases().iter().cloned().collect();
583 as_vec = missing_ancestors.get_bases().iter().cloned().collect();
570 as_vec.sort();
584 as_vec.sort();
571 assert_eq!(as_vec, [1, 3, 5, 7, 8]);
585 assert_eq!(as_vec, [1, 3, 5, 7, 8]);
586
587 as_vec = missing_ancestors.bases_heads()?.iter().cloned().collect();
588 as_vec.sort();
589 assert_eq!(as_vec, [3, 5, 7, 8]);
590 Ok(())
572 }
591 }
573
592
574 fn assert_missing_remove(
593 fn assert_missing_remove(
@@ -166,6 +166,11 b' py_class!(pub class MissingAncestors |py'
166 py_set(py, self.inner(py).borrow().get_bases())
166 py_set(py, self.inner(py).borrow().get_bases())
167 }
167 }
168
168
169 def basesheads(&self) -> PyResult<PyObject> {
170 let inner = self.inner(py).borrow();
171 py_set(py, &inner.bases_heads().map_err(|e| GraphError::pynew(py, e))?)
172 }
173
169 def removeancestorsfrom(&self, revs: PyObject) -> PyResult<PyObject> {
174 def removeancestorsfrom(&self, revs: PyObject) -> PyResult<PyObject> {
170 let mut inner = self.inner(py).borrow_mut();
175 let mut inner = self.inner(py).borrow_mut();
171 // this is very lame: we convert to a Rust set, update it in place
176 // this is very lame: we convert to a Rust set, update it in place
@@ -114,6 +114,7 b' class rustancestorstest(unittest.TestCas'
114 missanc.addbases({2})
114 missanc.addbases({2})
115 self.assertEqual(missanc.bases(), {1, 2})
115 self.assertEqual(missanc.bases(), {1, 2})
116 self.assertEqual(missanc.missingancestors([3]), [3])
116 self.assertEqual(missanc.missingancestors([3]), [3])
117 self.assertEqual(missanc.basesheads(), {2})
117
118
118 def testmissingancestorsremove(self):
119 def testmissingancestorsremove(self):
119 idx = self.parseindex()
120 idx = self.parseindex()
General Comments 0
You need to be logged in to leave comments. Login now