Can it use SortedDict from the SortedCollection for children's order?
Can it use SortedDict from the SortedCollection for children's order?
Use SortedDict from the SortedCollection.
A SortedDict provides the same methods as a dict. Additionally, a SortedDict efficiently maintains its keys in sorted order. Consequently, the keys method will return the keys in sorted order, the popitem method will remove the item with the highest key, etc.
Related to:
- https://github.com/caesar0301/treelib/issues/65 - How to order by data?
Issue #65 addressed a more general ordering of nodes by ANY attribute. SortedDict may replace the inner node dict, but it may introduce more performance concerns (see SO http://stackoverflow.com/questions/8176513/ordereddict-performance-compared-to-deque).
I see that Ordered dict is implemented in Python (slower), while the current structure is written right on C (faster). So could we create a new type of node called OrderedNode, based on OrderedDict, and use these nodes instead of the current nodes, if it is wanted ordered nodes. If somehow the performance for this new Node type would be bad, an alternative could be looked into, improving the new node type OrderedNode.
Note that regular python dictionaries started preserving insertion order as an implementation detail in cpython 3.6, and from 3.7 it's now guaranteed by Guido's decree: 'Make it so. "Dict keeps insertion order" is the ruling.' https://mail.python.org/pipermail/python-dev/2017-December/151283.html