资 源 简 介
Gap buffers are efficient mutable sequences. They are most often used to store text in text editors. They utilize locality of modification to avoid copying large amounts of data and allocate extra elements to avoid memory allocation dominating performance. The extra allocated items provide a movable gap between the two parts that contain data. Insertions and deletions occur at the gap.
For a description of gap buffers see Data Structures in a Bit-Mapped Text Editor, Wilfred J. Hanson, Byte January 1987
The item type for the gap buffer may be character, Unicode character, or integer and is determined from the type of the constructor argument with a list interpreted as integer:
>>> from gapbuffer import GapBuffer>>> print GapBuffer("The life of Brian")The life of Brian>>> print GapBuffer(u"Mr Creosote")Mr Creosote>>> print GapBuffer([1,2,3])GapBuffer("i") [1, 2, 3]