pub fn merge_partitions(p1: &CharPartition, p2: &CharPartition) -> CharPartitionExpand description
Merge two partitions p1 and p2
The result is the coarsest partition p that is a refinement of both p1 and p2. This means that every interval of p1 and every interval of p2 is the union of one or more successive intervals of p.
More precisely:
- let p1 = [a0, b0], …, [an, bn]
- let p2 = [c0, d0], …, [cm, dm]
- let D1 = complement(Union [ai, bi])
- let D2 = complement(Union [cj, dj])
Then every interval of p is of one of the following forms
- [ai, bi] inter D2
- D1 inter [cj, dj]
- [ai, bj] inter [cj, dj]
where 0 <= i <= n and 0 <= j <= m.
§Example
use aws_smt_strings::character_sets::*;
// partition p with intervals ['0', '9'] and ['a', 'g']
let mut p = CharPartition::new();
p.push('0' as u32, '9' as u32);
p.push('a' as u32, 'g' as u32);
// partition q with intervals ['5', '5'] and ['c', 'z']
let mut q = CharPartition::new();
q.push('5' as u32, '5' as u32);
q.push('c' as u32, 'z' as u32);
// r = merge(p, q) contains six intervals
// r = ['0', '4'] ['5', '5'] ['6', '9'] ['a', 'b'] ['c', 'g'] ['h', 'z']
let r = merge_partitions(&p, &q);
assert_eq!(r.len(), 6);
assert_eq!(r.get(0), ('0' as u32, '4' as u32));
assert_eq!(r.get(1), ('5' as u32, '5' as u32));
assert_eq!(r.get(2), ('6' as u32, '9' as u32));
assert_eq!(r.get(3), ('a' as u32, 'b' as u32));
assert_eq!(r.get(4), ('c' as u32, 'g' as u32));
assert_eq!(r.get(5), ('h' as u32, 'z' as u32));