diff --git a/src/io/owx/reader.rs b/src/io/owx/reader.rs index 9c1ee13..063315e 100644 --- a/src/io/owx/reader.rs +++ b/src/io/owx/reader.rs @@ -1436,7 +1436,10 @@ pub mod test { assert_eq!(ont.i().annotation_assertion().count(), 2); - let aa = ont.i().annotation_assertion().next().unwrap(); + let mut v: Vec<_> = ont.i().annotation_assertion().collect(); + v.sort(); + let aa = v[0]; + assert_eq!(*(aa.subject), *"http://www.example.com/iri#C"); assert_eq!( diff --git a/src/ontology/component_mapped.rs b/src/ontology/component_mapped.rs index a7b2e9a..4bab950 100644 --- a/src/ontology/component_mapped.rs +++ b/src/ontology/component_mapped.rs @@ -15,7 +15,7 @@ use super::set::SetOntology; use crate::model::*; use std::{ cell::RefCell, - collections::{BTreeMap, BTreeSet, VecDeque}, + collections::{HashMap, HashSet, VecDeque}, iter::FromIterator, ops::Deref, rc::Rc, @@ -57,16 +57,15 @@ macro_rules! onimpl { } #[derive(Clone, Debug, Eq, PartialEq)] -pub struct ComponentMappedIndex { - component: RefCell>>, +pub struct ComponentMappedIndex> { + component: RefCell>>, pd: PhantomData, } impl> ComponentMappedIndex { pub fn new() -> ComponentMappedIndex { ComponentMappedIndex { - component: RefCell::new(BTreeMap::new()), - pd: Default::default(), + ..Default::default() } } @@ -76,18 +75,18 @@ impl> ComponentMappedIndex { /// instantiated, which means that it effects equality of the /// ontology. It should only be used where the intention is to /// update the ontology. - fn component_as_ptr(&self, cmk: ComponentKind) -> *mut BTreeMap> { + fn component_as_ptr(&self, cmk: ComponentKind) -> *mut HashMap> { self.component.borrow_mut().entry(cmk).or_default(); self.component.as_ptr() } /// Fetch the components for the given kind. - fn set_for_kind(&self, cmk: ComponentKind) -> Option<&BTreeSet> { + fn set_for_kind(&self, cmk: ComponentKind) -> Option<&HashSet> { unsafe { (*self.component.as_ptr()).get(&cmk) } } /// Fetch the components for given kind as a mutable ref. - fn mut_set_for_kind(&mut self, cmk: ComponentKind) -> &mut BTreeSet { + fn mut_set_for_kind(&mut self, cmk: ComponentKind) -> &mut HashSet { unsafe { (*self.component_as_ptr(cmk)).get_mut(&cmk).unwrap() } } @@ -203,7 +202,7 @@ onimpl! {AnnotationPropertyDomain, annotation_property_domain} onimpl! {AnnotationPropertyRange, annotation_property_range} onimpl! {Rule, rule} -impl Default for ComponentMappedIndex { +impl> Default for ComponentMappedIndex { fn default() -> Self { Self { component: Default::default(), @@ -222,7 +221,7 @@ impl> IntoIterator for ComponentMappedIndex { // The collect switches the type which shows up in the API. Blegh. let v: Vec> = btreemap .into_values() - .flat_map(BTreeSet::into_iter) + .flat_map(HashSet::into_iter) .map(|fi| fi.unwrap()) .collect(); @@ -234,7 +233,7 @@ impl> IntoIterator for ComponentMappedIndex { pub struct ComponentMappedIter<'a, A: ForIRI, AA: ForIndex> { ont: &'a ComponentMappedIndex, kinds: VecDeque<&'a ComponentKind>, - inner: Option<<&'a BTreeSet as IntoIterator>::IntoIter>, + inner: Option<<&'a HashSet as IntoIterator>::IntoIter>, } impl<'a, A: ForIRI, AA: ForIndex> Iterator for ComponentMappedIter<'a, A, AA> { @@ -249,7 +248,7 @@ impl<'a, A: ForIRI, AA: ForIndex> Iterator for ComponentMappedIter<'a, A, AA> // Attempt to consume the iterator for the next component kind if !self.kinds.is_empty() { let kind = self.kinds.pop_front().unwrap(); - self.inner = self.ont.set_for_kind(*kind).map(BTreeSet::iter); + self.inner = self.ont.set_for_kind(*kind).map(HashSet::iter); self.next() } else { None @@ -280,7 +279,9 @@ impl> OntologyIndex for ComponentMappedIndex(OneIndexedOntology>); +pub struct ComponentMappedOntology>( + OneIndexedOntology>, +); pub type RcComponentMappedOntology = ComponentMappedOntology>>; pub type ArcComponentMappedOntology = @@ -481,7 +482,10 @@ mod test { o.insert(decl3.clone()); // Iteration is based on ascending order of axiom kinds. - let mut it = o.into_iter(); + // Iteration is set based so undefined in order. So, sort first. + let mut v: Vec<_> = o.into_iter().collect(); + v.sort(); + let mut it = v.into_iter(); assert_eq!( it.next(), Some(AnnotatedComponent::from(Component::DeclareClass(decl1))) @@ -538,7 +542,9 @@ mod test { o.insert(decl3.clone()); // Iteration is based on ascending order of axiom kinds. - let mut it = (&o).i().iter(); + let mut v: Vec<_> = (&o).i().iter().collect(); + v.sort(); + let mut it = v.into_iter(); assert_eq!( it.next(), Some(&AnnotatedComponent::from(Component::DeclareClass(decl1))) diff --git a/src/visitor/mutable.rs b/src/visitor/mutable.rs index 03a99df..903ff39 100644 --- a/src/visitor/mutable.rs +++ b/src/visitor/mutable.rs @@ -859,6 +859,7 @@ mod test { let mut walk = super::WalkMut::new(LabeltoFred); let mut vec = ont.into_iter().collect(); walk.ontology_vec(&mut vec); + vec.sort(); match &vec[2] { AnnotatedComponent {