1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::nonprimitive_term_pointer::*;
use crate::type_id::*;
use crate::term::*;
use crate::term_application_result::*;
use crate::primitive_term_pointer::*;
use std::collections::HashMap;
pub struct NewlyEvaluatedTerms {
pub term_app_results : Vec<TermApplicationResult>,
pub terms : Vec<NonPrimitiveTermPointer>
}
impl NewlyEvaluatedTerms {
pub fn new() -> Self {
NewlyEvaluatedTerms {
term_app_results : Vec::new(),
terms : Vec::new()
}
}
pub fn get_count_map(&self) -> HashMap<TermApplicationResult, usize> {
let mut result = HashMap::new();
for term_app_result in self.term_app_results.iter() {
let the_clone = term_app_result.clone();
if (!result.contains_key(term_app_result)) {
result.insert(the_clone, 1);
} else {
let prev_count = *result.get(term_app_result).unwrap();
result.insert(the_clone, prev_count + 1);
}
}
result
}
pub fn add_term_app_result(&mut self, term_app_result : TermApplicationResult) {
self.term_app_results.push(term_app_result);
}
pub fn add_term(&mut self, term : NonPrimitiveTermPointer) {
self.terms.push(term);
}
pub fn merge(&mut self, mut other : NewlyEvaluatedTerms) {
for term in other.terms.drain(..) {
self.terms.push(term);
}
for term_app_result in other.term_app_results.drain(..) {
self.term_app_results.push(term_app_result);
}
}
}