Streams Documentation

If an abstract data type can be implemented with nodes, then it can be implemented via streams.

Before reading further, one needs to understand that the streams in this package also serve the purpose of individual nodes. That is, a stream is a node and a node is a stream. This decision was made for the sake of efficiency and simplicity. When discussing this package, care shall be taken to use the most conceptually proper term to deter confusion.

The most powerful feature of streams is the ability to use lazy evaluation. For example, consider a stream of natural numbers. The value of the first node could be provided explicitly, the next property on that node could be provided as the previous node’s value incremented by one, and so on and so forth. Admittedly, this is a trivial example, but the point is to express that streams can be self-referential.

One of the things that makes streams so capable is that one can traverse them multiple times without changing their internal structure. This is unlike iterators which discard data as one iterates through them.

If you’re unsure of which class to use, then you probably want SinglyLinkedStream. For the sake of brevity, you might want to create an alias for the class (e.g. Stream = SinglyLinkedStream).

Caution

Be very careful to not mix stream node types within a stream. It is assumed that all nodes within the simulated data structure are compatible. For example, it is incorrect to assume that a singly linked stream node will behave like a doubly linked stream node.

Note

Note that this module has a few limitations due to Python’s lack of tail recursion elimination. With that said, care has been taken to avoid this issue where possible.

Indices and tables