Closed Thraka closed 1 year ago
Quick thought on this; there is a significant asymptotic notation difference in the algorithms required to insert an element at an an appropriate position to keep an already-sorted list sorted, vs sorting an unsorted list. Specifically, finding the position of an item and inserting it, is worst-case O(n)
, whereas sorting an unsorted list is O(n*log(n))
.
Therefore, if the API only supports the user inserting an item then calling a sort function as the method to change the order, this could limit a user from being able to write the most efficient code.
Perhaps the API could also support inserting an item at a specified index in the children list? That would allow a user to implement the "find the proper index and insert" method of maintaining sorting.
Sort would have to be a manual operation. Automatic sort shouldn't be supported, as it may change the entire behavior of a collection of objects. The user has full control to either keep the order as they added the children, or invoke a sort.