Skip to main content

A Python implementation of the Rope data structure

Project description

Early implementation of a Rope data structure in Python.

About ropes

Ropes are an mutable alternative to strings. The string is represented as a binary tree, and modifications to the string are achieved by either replacing existing substring branches or by inserting new substrings into the tree structure.

This is a preliminary version which supports the basic operations, such as concatentation, indexing, slices, and strides.

Implementation of some features is currently poor, particularly the slicing operations. No effort is made to balance the tree or otherwise optimise the data structure.

Usage

To convert a string into a rope, use the Rope class constructor.

r = Rope('abcdefg')

A pre-defined Rope tree can be constructed using a list of strings.

r = Rope(['abc', 'def', 'g'])

Printing the rope returns a string.

>>> r = Rope(['abc', 'defg'])
>>> r
(Rope('abcd') + Rope('efg'))
>>> print(r)
abcdefg

Strings can be inserted between existing ropes.

>>> r, s = Rope('abc'), Rope('def')
>>> u = '123'
>>> r + u + s
((Rope('abc') + Rope('123')) + Rope('def'))
>>> print(r + u + s)
abc123def
>>>

Current usage is very basic, but will hopefully improve in the future.

Project details


Release history Release notifications

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ropes, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size ropes-0.1.tar.gz (5.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page