I am trying to implement some kind of algorithm for my research paper(programming is not my major field of research) and I need some help. Consider following kind of data structure (e.g a and b) where we have a linear time line and objects placed on this time axis at certain distance from each other (actually these objects represent data packets whose width is equal to time needed to transmit the packet). I want to align them on right side, making it our reference point (time t=0) and then merge these two lists (a and b), if i may call them a list, and get a resulting list as shown in c. The overlapping objects are shifted to make single list and gap between these objects changes accordingly. Any idea how should I proceed? Linked lists? (if they exist in python). there can be more than two lists to be merged in a single list. Thanks in advance
____ _____ ____
__| a3 |________| a2 |__________| a1 | (a)
____ _____ ____
__| b3 |___________| b2 |_______| b1 | (b)
____ ____ ______ _____ ____ ____
_______| a3 || b3 |___| a2 || b2 |_| a1 || b1 | (c)
For example, dict for data items and lists for data sequences:
data 1:
[{‘start’:0, ‘t’: 10, ‘dtype’: ‘a’}, {‘start’: 30, ‘t’:20, ‘dtype’: ‘a’}, {‘start’: 50, ‘t’:30, ‘dtype’: ‘a’}]
data 2:
[{‘start’:15, ‘t’: 10, ‘dtype’: ‘b’}, {‘start’: 40, ‘t’:20, ‘dtype’: ‘b’}, {‘start’: 50, ‘t’:30, ‘dtype’: ‘b’}]
and merged list (sorted by start time):
result:
[{‘start’: 0, ‘t’: 10, ‘dtype’: ‘a’}, {‘start’: 15, ‘t’: 10, ‘dtype’: ‘b’}, {‘start’: 30, ‘t’: 20, ‘dtype’: ‘a’}, {‘start’: 40, ‘t’: 20, ‘dtype’: ‘b’}, {‘start’: 50, ‘t’: 30, ‘dtype’: ‘a’}, {‘start’: 50, ‘t’: 30, ‘dtype’: ‘b’}]
For backorder use parameter ‘reverse=True’ in sorted function. To find overlapped elements you just check during list iteration if item[‘start’] + item[‘t’] > nextitem[‘start’] ===> items overlapping, and you must adjust nextitem start position according your algorithm.