Question is really wider than the title allows me to specify. I have a big file representing unordered numbered packets in the order they were received and the timestamp that corresponds to it, such as (arrows included for clarity, not really in file):
seq_1 ----> timestamp
seq_2 ----> timestamp
seq_3 ----> timestamp
seq_2 ----> timestamp
seq_5 ----> timestamp
seq_4 ----> timestamp
...
Timestamps always increase, but I might duplicate packets, packets out of order, etc. I have parsed the file to a list of strings, and must now decide the appropriate data structure to save it, taking into account that I need to:
- Remove all duplicated sequence numbers, only keeping the first one which arrived.
- Obtain an ordered iterable structure sorted by the sequence number.
The idea is that I could plot (not really going to do it, though) a graph bar, x axis being the sequence numbers and y axis being the timestamp. I need to manually find local maxima and minima, so I should be able to access the adjacent entries of any entry.
I have thought of parsing the list of lines to a dictionary
of (sequence_number, timestamp)
, carefully not overwriting existing entries (condition 1), then turning it into a list
of tuple
s and finally sorting the list
by key. list
should allow me to access adjacent entries, thus fulfilling condition 2. The parsed file is quite big, so I was wondering if there is a solution which would scale better (not requiring conversion between two data structures + posterior sorting).