orx_v/dim/index_card/
idx_card_d1.rs

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
use super::CardIdx;
use crate::{dim::*, NVec, NVecCore};
use index_card::{CardEquality, Equality};
use index_sums::IdxLeqD0;

impl CardIdx<D1> for IdxLeqD0 {
    fn is_d0(&self) -> bool {
        true
    }

    fn card<T>(self, vec: &impl NVecCore<D1, T>) -> usize {
        match self {
            Self::IdxD0(_) => vec.core_num_children(),
        }
    }

    fn card_equality<T>(a: &impl NVecCore<D1, T>, b: &impl NVecCore<D1, T>) -> CardEquality<D1> {
        match (a.core_num_children(), b.core_num_children()) {
            (x, y) if x == y => CardEquality::Equal,
            (x, y) => CardEquality::Unequal(Self::IdxD0([]), x, y),
        }
    }

    fn equality<T: PartialEq>(a: &impl NVec<D1, T>, b: &impl NVec<D1, T>) -> Equality<D1> {
        match (a.core_num_children(), b.core_num_children()) {
            (x, y) if x == y => {
                for i in 0..a.core_num_children() {
                    if a.at(i) != b.at(i) {
                        return Equality::UnequalValue([i]);
                    }
                }
                Equality::Equal
            }
            (x, y) => Equality::UnequalCard(Self::IdxD0([]), x, y),
        }
    }
}