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
use core::marker::PhantomData;

use necsim_core::{
    cogs::{
        coalescence_sampler::CoalescenceRngSample, Backup, CoalescenceSampler, Habitat,
        LocallyCoherentLineageStore, MathsCore,
    },
    landscape::{IndexedLocation, Location},
    lineage::LineageInteraction,
};

use super::optional_coalescence;

#[allow(clippy::module_name_repetitions)]
#[derive(Debug)]
pub struct UnconditionalCoalescenceSampler<
    M: MathsCore,
    H: Habitat<M>,
    S: LocallyCoherentLineageStore<M, H>,
>(PhantomData<(M, H, S)>);

impl<M: MathsCore, H: Habitat<M>, S: LocallyCoherentLineageStore<M, H>> Default
    for UnconditionalCoalescenceSampler<M, H, S>
{
    fn default() -> Self {
        Self(PhantomData::<(M, H, S)>)
    }
}

#[contract_trait]
impl<M: MathsCore, H: Habitat<M>, S: LocallyCoherentLineageStore<M, H>> Backup
    for UnconditionalCoalescenceSampler<M, H, S>
{
    unsafe fn backup_unchecked(&self) -> Self {
        Self(PhantomData::<(M, H, S)>)
    }
}

#[contract_trait]
impl<M: MathsCore, H: Habitat<M>, S: LocallyCoherentLineageStore<M, H>> CoalescenceSampler<M, H, S>
    for UnconditionalCoalescenceSampler<M, H, S>
{
    #[must_use]
    fn sample_interaction_at_location(
        &self,
        location: Location,
        habitat: &H,
        lineage_store: &S,
        coalescence_rng_sample: CoalescenceRngSample,
    ) -> (IndexedLocation, LineageInteraction) {
        optional_coalescence::sample_interaction_at_location(
            location,
            habitat,
            lineage_store,
            coalescence_rng_sample,
        )
    }
}