rain_lang/value/
cons.rs

1/*!
2Hash-consing of `rain` values
3*/
4
5use rand::{self, Rng};
6use lazy_static::lazy_static;
7use super::ValueData;
8use crate::graph::cons::{GlobalCache, NodeCache};
9
10/// A cache for `rain` values, for hash-consing
11pub type ValueCache<C = GlobalCache> = NodeCache<ValueData, C>;
12
13lazy_static! {
14    /// A lazily-initialized global cache for `rain` values, for hash-consing
15    pub static ref VALUE_CACHE: ValueCache = {
16        let mut rng = rand::thread_rng();
17        ValueCache::with_keys(rng.gen())
18    };
19}
20
21#[cfg(test)]
22mod tests {
23    use crate::value::ValId;
24
25    #[test]
26    fn boolean_values_are_hash_consed() {
27        let vt = ValId::from(true);
28        let vf = ValId::from(false);
29        let vt2 = ValId::from(true);
30        let vf2 = ValId::from(false);
31        assert_eq!(vt, vt2);
32        assert_eq!(vf, vf2);
33        assert_ne!(vt, vf);
34    }
35}