This is a simple immutable deque based on binary trees. What do you think about it? Does this kind of data structure, or possibly an improvement thereof, seem useful? How could I improve it, preferably without getting rid of its strengths? (Not in the sense of more operations, in the sense of different design) Does this sort of thing have a name?Red nodes are newly instantiated; blue ones are reused. Nodes aren't actually red or anything, it's just for emphasis.Note that right deques do not take O(n). Any access to an element in the deque depends on how long ago it was inserted. You can perform any enqueue or concat operation at O(1).You can also use the 'weight' of each non-leaf node to change the orientation of the tree, such as to make all right access costly and left access cheap, or to provide O(logn) access to either end. This process takes O(n) worst case, depending on the initial orientation of the tree.Alternatively, I could 'search' for the lightest node into which to insert a given node, turning all operations into O(logn) operations.
A deque based on binary trees
functional programming;data structures