GithubHelp home page GithubHelp logo

ivanbgd / rope-data-structure Goto Github PK

View Code? Open in Web Editor NEW
3.0 0.0 1.0 23 KB

Implementation of a data structure that can store a string and efficiently cut a part (a substring) of this string and insert it in a different position.

License: MIT License

Python 100.00%
rope rope-string

rope-data-structure's Introduction

Rope-Data-Structure

Implementation of a data structure that can store a string and efficiently cut a part (a substring) of this string and insert it in a different position. The current implementation only processes a given string. It doesn't support insertion of new characters in the string.

https://en.wikipedia.org/wiki/Rope_(data_structure)

Uses Splay tree to implement the Rope data structure.

Nodes don't have keys. They only have values. And the value is a character. That means that one node contains and represents a single character. This data structure is about strings. The string represents (is) contents of a text document. In a string, characters are in order, of course. The order is represented by their rank. That's why we use order statistics to locate a node when searching for it (performing a "find" operation). The rank can be seen as their index, and we'll use 0-based indexing. The size of a node doesn't have anything to do with its rank. Also, when a node is splayed, its rank doesn't change; only its size changes. One has to think in terms of node rank, and not in terms of node key, as usual! We could also add the field "rank" to Node objects. But, that's not needed. In-order traversal gives all characters in order.

Works in Python 2 & 3.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.