Creating a new kind of set
Creating a whole new collection requires some preliminary work. We need to have new algorithms or new internal data structures that offer significant improvements over the built-in collections. It's important to do thorough "Big-O" complexity calculations before designing a new collection. It's also important to use timeit
after an implementation to be sure that the new collection really is an improvement on the built-in class.
We might, for example, want to create a binary search tree structure that will keep the elements in a proper order. As we want this to be a mutable structure, we'll have to perform the following kinds of design activities:
Design the essential binary tree structure
Decide which structure is the basis:
MutableSequence
,MutableMapping
, orMutableSet
Look at the special methods for the collection in the
collections.abc
section of the Python Standard Library documentation, section 8.4.1.
A binary search tree has nodes with two branches: a "less...