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
//! Ordering and range filtering for dialogue event collections.
//!
//! Provides stable time-based sorting and temporal range filtering over
//! slices of [`DialogueInfo`], using centisecond timing for comparisons.
use crateDialogueInfo;
use Vec;
use Ordering;
/// Sort events by timing with stable ordering
///
/// Sorts events by start time first, then by end time for events that
/// start simultaneously. Uses stable sort to preserve relative order
/// of equal elements.
///
/// # Arguments
///
/// * `events` - Mutable slice of `DialogueInfo` to sort in-place
///
/// # Performance
///
/// O(n log n) time complexity with minimal allocations.
/// Comparison operations are optimized for centisecond timing.
///
/// # Example
///
/// ```rust
/// # use ass_core::analysis::events::utils::sort_events_by_time;
/// # use ass_core::analysis::events::dialogue_info::DialogueInfo;
/// # use ass_core::parser::Event;
/// let event1 = Event {
/// start: "0:00:05.00",
/// end: "0:00:10.00",
/// ..Default::default()
/// };
/// let event2 = Event {
/// start: "0:00:01.00",
/// end: "0:00:06.00",
/// ..Default::default()
/// };
/// let dialogue_info1 = DialogueInfo::analyze(&event1)?;
/// let dialogue_info2 = DialogueInfo::analyze(&event2)?;
/// let mut events = vec![dialogue_info1, dialogue_info2];
/// sort_events_by_time(&mut events);
/// // Events are now sorted by start time, then end time
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Find events within a specific time range
///
/// Returns indices of events that overlap with the given time range.
/// Useful for temporal filtering and range-based analysis.
///
/// # Arguments
///
/// * `events` - Slice of `DialogueInfo` to search
/// * `start_cs` - Range start time in centiseconds
/// * `end_cs` - Range end time in centiseconds
///
/// # Returns
///
/// Vector of indices for events overlapping the time range.