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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use std::{cmp::Ordering, fmt};

use necsim_core_bond::PositiveF64;
use serde::{Deserialize, Serialize};

pub mod recorder;
pub mod replay;

#[derive(Serialize, Deserialize, PartialEq)]
#[allow(clippy::module_name_repetitions)]
pub struct EventLogHeader {
    min_time: PositiveF64,
    max_time: PositiveF64,

    length: usize,

    with_speciation: bool,
    with_dispersal: bool,
}

impl fmt::Debug for EventLogHeader {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.debug_struct(stringify!(EventLogHeader))
            .field("min_time", &self.min_time)
            .field("max_time", &self.max_time)
            .field("length", &self.length)
            .finish_non_exhaustive()
    }
}

impl EventLogHeader {
    #[must_use]
    pub fn new(
        min_time: PositiveF64,
        max_time: PositiveF64,
        length: usize,
        with_speciation: bool,
        with_dispersal: bool,
    ) -> Self {
        Self {
            min_time,
            max_time,
            length,
            with_speciation,
            with_dispersal,
        }
    }

    #[must_use]
    pub fn min_time(&self) -> PositiveF64 {
        self.min_time
    }

    #[must_use]
    pub fn max_time(&self) -> PositiveF64 {
        self.max_time
    }

    #[must_use]
    pub fn length(&self) -> usize {
        self.length
    }

    #[must_use]
    pub fn with_speciation(&self) -> bool {
        self.with_speciation
    }

    #[must_use]
    pub fn with_dispersal(&self) -> bool {
        self.with_dispersal
    }
}

impl Eq for EventLogHeader {}

impl PartialOrd for EventLogHeader {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        if self.max_time < other.min_time {
            Some(Ordering::Less)
        } else if self.min_time > other.max_time {
            Some(Ordering::Greater)
        } else {
            None
        }
    }
}