Commit 6a073f7f authored by Jeff Smits's avatar Jeff Smits

Read lists the right way around

parent 17e1832c
......@@ -15,7 +15,6 @@ use std::hash::Hasher;
use std::fmt;
use std::rc::Rc;
use std::borrow::{Cow, Borrow};
use std::iter::FromIterator;
pub type HashTable<'s> = LinkedHashMap<ATermRef<'s>, ATermRef<'s>, ::fnv::FnvBuildHasher>;
#[derive(Debug, Eq, Clone, Default)]
......@@ -142,6 +141,14 @@ impl<'s> TermList<'s> {
pub fn iter(&self) -> TermListIterator<'s> {
self.clone().into_iter()
}
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item=ATermRef<'s>>,
<T as IntoIterator>::IntoIter: DoubleEndedIterator,
{
iter.into_iter().rev().fold(TermList::Nil, |list, item| TermList::Cons(item, Rc::new(list)))
}
}
impl<'s> IntoIterator for TermList<'s> {
......@@ -183,12 +190,6 @@ impl<'s> Iterator for TermListIterator<'s> {
}
}
impl<'s> FromIterator<ATermRef<'s>> for TermList<'s> {
fn from_iter<T: IntoIterator<Item=ATermRef<'s>>>(iter: T) -> Self {
iter.into_iter().fold(TermList::Nil, |list, item| TermList::Cons(item, Rc::new(list)))
}
}
#[derive(Debug, Eq, Clone, Hash)]
pub enum Term<'s, B> {
Int(i32),
......@@ -547,8 +548,9 @@ impl<'s> aterm::ATermFactory<'s> for ATermFactory {
where
I: IntoIterator<Item = Self::ATermRef>,
{
let vec: Vec<_> = value.into_iter().collect();
Rc::new(ATerm::no_annos(Term::List(
Rc::new(value.into_iter().collect::<TermList<'s>>()),
Rc::new(TermList::from_iter(vec.into_iter())),
)))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment