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
|
// Test program to demonstrate InterpolateLength vs SegregateLength sorting
use meta_affine::{Sequence, Value};
use meta_affine::sequence::{sort_sequences, SequenceOptions, LengthSorting, SortingMethod};
fn print_sequences(label: &str, sequences: &[Sequence]) {
println!("\n{}:", label);
for (i, seq) in sequences.iter().enumerate() {
print!(" {}: [", i);
for (j, v) in seq.values().iter().enumerate() {
if j > 0 { print!(", "); }
print!("({},{})", v.outer, v.inner);
}
println!("] (length {})", seq.length());
}
}
fn main() {
// Create sequences of different lengths
let sequences = vec![
// Length 3
Sequence::new(vec![Value::new(1, 0), Value::new(0, 1), Value::new(0, 0)]),
// Length 1
Sequence::new(vec![Value::new(0, 0)]),
// Length 2
Sequence::new(vec![Value::new(1, 0), Value::new(0, 0)]),
// Length 3
Sequence::new(vec![Value::new(0, 1), Value::new(1, 0), Value::new(0, 0)]),
// Length 2
Sequence::new(vec![Value::new(0, 1), Value::new(0, 0)]),
// Length 4
Sequence::new(vec![Value::new(1, 0), Value::new(0, 1), Value::new(1, 0), Value::new(0, 0)]),
];
print_sequences("Original sequences", &sequences);
// Test InterpolateLength (explicitly set) - sequences sorted by content, length mixed in
let mut interpolate = sequences.clone();
let opts = SequenceOptions::new()
.length_sorting(LengthSorting::InterpolateLength)
.sorting_method(SortingMethod::DepthFirst);
sort_sequences(&mut interpolate, opts);
print_sequences("InterpolateLength (sorted by content, lengths mixed)", &interpolate);
println!(" Explanation: Sequences are sorted by their content values");
println!(" Length is only considered when content is equal");
// Test SegregateLength - sequences grouped by length, then sorted by content within each group
let mut segregate = sequences.clone();
let opts = SequenceOptions::new()
.length_sorting(LengthSorting::SegregateLength)
.sorting_method(SortingMethod::DepthFirst);
sort_sequences(&mut segregate, opts);
print_sequences("SegregateLength (grouped by length, then by content)", &segregate);
println!(" Explanation: All length-1 sequences come first (sorted by content)");
println!(" Then all length-2 sequences (sorted by content)");
println!(" Then all length-3 sequences (sorted by content)");
println!(" Then all length-4 sequences (sorted by content)");
println!("\n=== Summary ===");
println!("InterpolateLength: Length is only a tiebreaker when content is equal");
println!("SegregateLength: Sequences are grouped by length first, shorter always before longer");
}
|