STLPort Rope源码解析(一)

Rope是一个string的实现方式,最早详细论述这个实现的文章是hans-j. boehm, russ atkinson and michael plass等人在Xerox公司撰写的“Ropes: an Alternative to Strings”,在其中非常详尽的描述了传统string实现方式的弱点以及rope实现的算法和优点。StlPort的Rope也是按照文章所提到的方式实现。另外关于为什么要使用Rope,Petr Ovchenkov在2003年写的“Comparison of Strings Implementations in C++ language”是一个很好的回答。

(STL的源码都是借助了大量的宏和模板实现的,导致了库源码比较复杂,这也是因为为了兼容众多的C++编译器,以及C++语言为了效率和精简缺乏完善的动态信息的缘故,毕竟RTTI所能提供的太少太少。在以后的分析中,不会过多去分析宏和模板的使用,重点放在算法的实现上。)

在“Ropes: an Alternative to Strings”这样描述了Rope需要实现的要点:

Ropes can be viewed as search trees that are indexed by position. If each vertex contains the length of the string represented by the subtree, then minimal modifi-cations of the search tree algorithms yield the following operations on ropes:
1. Fetch ith character. A simple search tree look-up. Rather than examining the subtree containing the right key, we examine the tree containing the proper position, as determined by the length fields.
2. Concatenate two ropes. Search tree concatenation as defined in Reference 3.
3. Substring. Two search tree split operations, as defined in Reference 3.
4. Iterate over each character. Left-to-right tree traversal.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值