algebraeon_sets/structure/
finite_set.rs1use super::{EqSignature, OrdSignature, SetSignature, Signature};
2use crate::structure::{CountableSetSignature, FiniteSetSignature};
3use std::fmt::Debug;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct EnumeratedFiniteSetStructure {
7 n: usize,
8}
9
10impl EnumeratedFiniteSetStructure {
11 pub fn new(n: usize) -> Self {
12 Self { n }
13 }
14}
15
16impl Signature for EnumeratedFiniteSetStructure {}
17
18impl SetSignature for EnumeratedFiniteSetStructure {
19 type Set = usize;
20
21 fn is_element(&self, x: &Self::Set) -> Result<(), String> {
22 if x >= &self.n {
23 return Err("Too big to be an element".to_string());
24 }
25 Ok(())
26 }
27}
28
29impl EqSignature for EnumeratedFiniteSetStructure {
30 fn equal(&self, x: &Self::Set, y: &Self::Set) -> bool {
31 x == y
32 }
33}
34
35impl OrdSignature for EnumeratedFiniteSetStructure {
36 fn cmp(&self, x: &Self::Set, y: &Self::Set) -> std::cmp::Ordering {
37 x.cmp(y)
38 }
39}
40
41impl CountableSetSignature for EnumeratedFiniteSetStructure {
42 fn generate_all_elements(&self) -> impl Iterator<Item = Self::Set> {
43 0..self.n
44 }
45}
46
47impl FiniteSetSignature for EnumeratedFiniteSetStructure {
48 fn size(&self) -> usize {
49 self.n
50 }
51}