1use crate::type_id::*;
2use crate::term::*;
3use crate::term_pointer::*;
4use crate::func_impl::*;
5use rand::Rng;
6use std::collections::HashMap;
7use crate::term_index::*;
8use crate::nonprimitive_term_pointer::*;
9
10pub struct TypeSpace {
13 my_type : TypeId,
14 terms : Vec<PartiallyAppliedTerm>,
15 term_to_index_map : HashMap::<PartiallyAppliedTerm, usize>
16}
17
18impl TypeSpace {
19 pub fn new(id : TypeId) -> TypeSpace {
22 TypeSpace {
23 my_type : id,
24 terms : Vec::new(),
25 term_to_index_map : HashMap::new()
26 }
27 }
28
29 pub fn get_num_terms(&self) -> usize {
31 self.terms.len()
32 }
33
34 pub fn get(&self, term_index : usize) -> &PartiallyAppliedTerm {
36 &self.terms[term_index]
37 }
38
39 pub fn add(&mut self, term : PartiallyAppliedTerm) -> NonPrimitiveTermPointer {
43 if (self.term_to_index_map.contains_key(&term)) {
44 let index : usize = *(self.term_to_index_map.get(&term).unwrap());
45 NonPrimitiveTermPointer {
46 type_id : self.my_type.clone(),
47 index
48 }
49 } else {
50 let new_ind : usize = self.terms.len();
51 self.terms.push(term.clone());
52 self.term_to_index_map.insert(term, new_ind);
53 NonPrimitiveTermPointer {
54 type_id : self.my_type,
55 index : new_ind
56 }
57 }
58 }
59}