Recent

Author Topic: Ropes - An alternative to strings  (Read 2660 times)

A3aan

  • Newbie
  • Posts: 3
Ropes - An alternative to strings
« on: October 23, 2018, 10:22:49 am »
Hi Everyone ;D,

When searching for an efficient way to handle long texts I stumbled on this Wikipedia article:
https://en.wikipedia.org/wiki/Rope_(data_structure)

After reading I decided to implement the Rope data type as a unit so Ropes could be used as an alternative to Strings. Ropes have an advantage over Strings when texts grow large since they reduce the amount of data movement when inserting or deleting parts of the text. Also the implementation uses a reference counting scheme to avoid unnecessary duplication of text fragments. This behavior is often desired in word processing when multiple versions of the text must be held in memory to allow for recovering from erroneous changes.

The Ropes unit, documentation, and a demo in the form of a small text editor program can be found here:
http://home.hccnet.nl/fam.rappard/adriaan/fpc/ropes.zip

Hope you like it  :D

Adriaan Rappard
« Last Edit: October 23, 2018, 10:35:54 am by A3aan »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: Ropes - An alternative to strings
« Reply #1 on: October 23, 2018, 10:34:34 am »
Can't load the link. The correct link should be http://home.hccnet.nl/fam.rappard/adriaan/fpc/Ropes.zip

Afaik many better programming oriented texteditors use a similar structure, but in general will be more line oriented. (since they don't display endless continuous text, but texts broken up in lines).

At least that is what Martin tried to explain to me about the lazarus editor implementation once :_)
« Last Edit: October 23, 2018, 11:57:15 am by marcov »

A3aan

  • Newbie
  • Posts: 3
Re: Ropes - An alternative to strings
« Reply #2 on: October 23, 2018, 10:42:04 am »
Hi marcov,

Thanx! I corrected the link  :D.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Ropes - An alternative to strings
« Reply #3 on: October 23, 2018, 11:50:21 am »
I learned it as "cord". It is based on a Trie, not tree, and not very memory efficient on long texts, so it needs a windowing scheme too.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

sash

  • Sr. Member
  • ****
  • Posts: 366
Re: Ropes - An alternative to strings
« Reply #4 on: October 23, 2018, 01:44:31 pm »
> when multiple versions of the text must be held in memory to allow for recovering from erroneous changes

IMO you should not hold multiple versions (as a full snapshot copies). It is enough to keep some base version, current version and set of replayable/undoable changes between them.
Lazarus 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Ropes - An alternative to strings
« Reply #5 on: October 23, 2018, 03:06:47 pm »
Yes, sash. That's exactly what this does. Speed efficient at the cost of space.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

A3aan

  • Newbie
  • Posts: 3
Re: Ropes - An alternative to strings
« Reply #6 on: October 23, 2018, 04:29:20 pm »
Yes, you're right. If you want to see how much faster at what memory cost download the zip file and read page 16 and 17 of the reference guide (Ropes.pdf)  :D.

 

TinyPortal © 2005-2018