A bytearray work-alike using a gap buffer for storage
A Python bytearray work alike which uses a gap buffer as underlying storage. It is a data structure optimised for locally coherent insertions and deletions. It is the usual data structure in text editors.
A utility class, codedstring, is provided which provides a string-like view on a bytegapbuffer transparently encodes and decodes Unicode strings. It provides efficient common-case indexing.
Installation is via pip. To install the latest release version:
$ pip install bytegapbuffer
To install the current development version from git:
$ pip install git+https://github.com/rjw57/bytegapbuffer
The bytegapbuffer collection aims to behave just like a bytearray. For example:
from bytegapbuffer import bytegapbuffer a = bytegapbuffer(b'hello') a.insert(3, 65) a.insert(4, 66) assert a == b'helABlo'
This project is used as part of a personal project of mine and, as such, implements just enough of the sequence, mutable sequence and bytearray interface for my needs. Pull requests adding missing functionality are welcome. Please also add a test for the functionality.
All of the above should work exactly as the bytearray object does. (This is tested in the test suite.) Additional non-bytearray features:
The test suite may be run via the tox utility. The Travis builds are set up to run the test suite on the latest released Python 2 and Python 3 versions.
Copyright (C) 2015 Rich Wareham
This code is licensed under a BSD-style licence. See the LICENSE file for details.