Customizer: Parameters order as in the source code

There was an issue https://github.com/openscad/openscad/issues/1844 that says the order of parameters and group should be according the order of the parameters in the script which was a difficult task as we were saving all parameters in map which don’t keep order in which parameters were added instead arranges the object inside it according to the keys and in this case keys were strings that are name of assignment. On iteration, We were getting the parameter in Alphabetical order. To solve this problem we have using the following solutions:

  1. Make a list of pointers to object in the map. So, that it would be used to store the order of parameters but this had the problem that when the objects in the map were deleted, Pointers in the list were now pointing to invalid locations and it gives the segmentation fault. Although this problem could be solved using shared_ptrs but I was not knowing about them at that point. So, this method was discarded by me.
  2. The second method was to use line number of the parameter as the key but it suffered from the problem that there can be two parameters in the same line. So, this method was also discarded.
  3. The third method was to use the list instead of the map to store the objects and groups but this method would decrease the efficiency of the program as search operation on a list is O(n). So, it was sideline as plan B.
  4. The last solution that I came up was to store a location of an object using list i.e. to store objects in the map only and use another list with keys to the object on the map in order in which parameters appear in the script. This solution was a good solution as it didn’t increase the time complexity as for find operation we can use maps and for iterations, according to order, we could use list. Although this method increased space required but the space complexity was not increased nor the time complexity which is most important complexity in programs related to GUI.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s