Network monitoring: aggregation of packets with timestamps
Rust
Hard
structs
Task «Network monitoring: aggregation of packets with timestamps»
Develop a Packet structure for storing network packet data: identifier (u32), size (u32), timestamp (u64, milliseconds). Implement an aggregate function that takes a vector of packets and returns a vector of AggregatedInfo structures: time interval (start_ts, end_ts, where the difference <= 1000 ms), packet count, total size, average size (rounded to an integer). Intervals must not overlap and must cover all packets. If there are no packets, return an empty vector. It is guaranteed that the packets are already sorted by timestamp in ascending order.
Input Format
First line: integer n (0 <= n <= 10000) — the number of packets. Then n lines, each: id size timestamp (integers separated by a space).
Output Format
For each interval, output a line: start_ts end_ts count total_size avg_size. If there are no packets, output 'No data'.
Examples
Example 1
INPUT
1 10
OUTPUT
30
main.rs