我想建立一个数据结构来存储有限的撤消缓冲区,以存储 6 dict 数据为例,下面的伪代码:
rawdict1 = {1}
buffer = [{1}]
rawdict1 = {2}
buffer = [{2}{1}] # {1} stored on the postion
rawdict1 = {3}
buffer = [{3}{2}{1}]
...
rawdict1 = {5}
buffer = [{5}{4}{3}{2}{1}] # max length limited to 5
rawdict1 = {6}
buffer = [{6}{5}{4}{3}{2}] # {1} has been deleted because exceed the limit
when I want to restore the rawdict1 later, I can use something looks like:
rawdict1 = buffer[5] # restore the 5th dict.
我的问题是,现有的内置数据类型或标准库类型可以用于这样的目的吗?
并且这样的结构是否有可能在一个结构实例中存储多种类型,例如,如果我想一次性存储 dict 和自定义类?
谢谢!
Rgs,
KC