algebraeon_sets/structure/
finite_set.rs1use super::{EqSignature, OrdSignature, SetSignature, Signature};
2use crate::structure::{CountableSetSignature, FiniteSetSignature, orderings::PartialOrdSignature};
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 PartialOrdSignature for EnumeratedFiniteSetStructure {
36 fn partial_cmp(&self, x: &Self::Set, y: &Self::Set) -> Option<std::cmp::Ordering> {
37 Some(self.cmp(x, y))
38 }
39}
40
41impl OrdSignature for EnumeratedFiniteSetStructure {
42 fn cmp(&self, x: &Self::Set, y: &Self::Set) -> std::cmp::Ordering {
43 x.cmp(y)
44 }
45}
46
47impl CountableSetSignature for EnumeratedFiniteSetStructure {
48 fn generate_all_elements(&self) -> impl Iterator<Item = Self::Set> + Clone {
49 0..self.n
50 }
51}
52
53impl FiniteSetSignature for EnumeratedFiniteSetStructure {
54 fn size(&self) -> usize {
55 self.n
56 }
57}