Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Pure Ruby implementation of a Rope data structure

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.textile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 benchmark.rb
Octocat-spinner-32 rope.gemspec
README.textile

rope is still under early development. Check it out if you wish to follow my progress or help, but do not use it in your applications (yet!).

rope is a pure Ruby implementation of the Rope data structure.

For many applications, the Rope class can be a drop-in replacement for String that is optimized for certain use cases.

Using a Rope instance over a String may be desirable in applications that manipulate large amounts of text.

rope currently offers:

  • Fast string concatenation and substring operations involving large strings
  • Immutability, which is desirable for functional programming techniques or multithreaded applications

Planned features for rope:

  • Ability to view a function producing characters as a Rope (including I/O operations). For instance, a piece of a Rope may be a 100MB file, but is only read when that section of the string is examined. Concatenating to the end of that Rope does not involve reading the entire file.
  • Implement a Rope counterpart to every immutable method available on the String class.

Disadvantages of rope:

  • Single character replacements are expensive
  • Iterating character-by-character is slightly more expensive than in a String (TODO: how much? .. haven’t implemented iterators yet)

Installation

rope is hosted on rubygems

gem install rope

… or in your Gemfile

gem 'rope'

rope is tested against MRI 1.8.7 and 1.9.2.

Usage

Creating a Rope

rope = "123456789".to_rope # Rope::Rope.new("123456789") also works

puts rope # "123456789"

Concatenation

A Rope instance can be concatenated with another Rope or String instance.

rope = "12345"
string = "6789"

rope += string
puts rope # "123456789"

Slices/Substrings

A Rope instance offers efficient substring operations. The slice and [] methods are synonymous with their String counterparts.

rope = "123456789".to_rope

puts rope.slice(3, 4) # 4567
puts rope.slice(-6, 4) # 4567
# TODO: More examples when they are implemented
Something went wrong with that request. Please try again.