0

I am writing a Qt application to enable generation of signal files using a GUI. The GUI has a canvas that allows a user to draw a new signal. Id like a signal to be defined as a set of contiguous line segments where each segment can be shifted up or down to shift the signal up or down.

I am trying to figure out the best data structure to represent the signal that will allow dynamic change in number of line segments while keeping total signal length the same, i.e. a user can choose the granularity at which she can change the signal. This would mean there needs to be a dynamic data structure that can add/remove and more importantly split and merge line segments.

Need some pointers at what type of data structure might be best.

thanks

user1487551
  • 391
  • 2
  • 3
  • 8
  • 1
    What is a *signal*? Without context, e.g. a screenshot, its really hard to understand what the actual problem is here. Hence I've given a very generic answer. – Will Jun 28 '12 at 06:58
  • Think of the signal as a square wave where one or more pulses can be placed by simply raising the corresponding line segment. – user1487551 Jun 28 '12 at 07:00

1 Answers1

1

You typically don't need a complex recursive data-structure to store a path. Just use a normal dynamic array of points.

Rendering costs will completely dominate; the cost of walking an array to determine its length, and to validate if an insertion or deletion is legal etc is trivial in comparison.

Will
  • 73,905
  • 40
  • 169
  • 246
  • The reason I want something more complex than a normal dynamic array is for example to handle a case when the user changes the length of segments e.g. wants a shorter pulse signal. Now the long pulses that were defined would need to be split into two line segments etc. I'd like a clean way to handle this based on a well reasoned data structure. In computational geometry I see the use of trees and there the emphasis is on finding line segment intersections im more looking for handling merging and splitting. – user1487551 Jun 28 '12 at 07:21
  • 2
    Just deleting an item from the middle of an array is an O(n) thing and completely not a problem even if your n is in the thousands. Actually, trees are often slower because they have much worse data locality for cachelines. Avoid the complexity of trees unless you've got a dynamic array and you run into performance problems. – Will Jun 28 '12 at 07:24