1
use merc_collections::BlockIndex;
2
use merc_collections::IndexedPartition;
3
use merc_lts::StateIndex;
4

            
5
/// A trait for partition refinement algorithms that expose the block number for
6
/// every state. Can be used to compute the quotient labelled transition system.
7
///
8
/// The invariants are that the union of all blocks is the original set, and
9
/// that each block contains distinct elements
10
pub trait Partition {
11
    /// Returns the block number for the given state.
12
    fn block_number(&self, state_index: StateIndex) -> BlockIndex;
13

            
14
    /// Returns the number of blocks in the partition.
15
    fn num_of_blocks(&self) -> usize;
16

            
17
    /// Returns the number of elements in the partition.
18
    fn len(&self) -> usize;
19

            
20
    /// Returns whether the partition is empty.
21
    fn is_empty(&self) -> bool {
22
        self.len() == 0
23
    }
24
}
25

            
26
impl Partition for IndexedPartition {
27
1140380938
    fn block_number(&self, state_index: StateIndex) -> BlockIndex {
28
1140380938
        self.block(state_index.value())
29
1140380938
    }
30

            
31
2725989
    fn num_of_blocks(&self) -> usize {
32
2725989
        self.num_of_blocks()
33
2725989
    }
34

            
35
71020
    fn len(&self) -> usize {
36
71020
        self.len()
37
71020
    }
38
}