zoukankan      html  css  js  c++  java
  • rope(转载)

    谈c++ pb_ds库(一)rope大法好

     (转载)原文链接 https://www.cnblogs.com/keshuqi/p/6257642.html

    参考资料

    1)官方说明

    支持

    sorry,cena不支持rope

    声明

    1)头文件

    #include<ext/rope>

    2)调用命名空间

    using namespace __gnu_cxx;

    底层原理

    查了资料,大概可以称作可持久化平衡树,因为rope适用于大量、冗长的串操作,而不适合单个字符操作官方说明如下:

    Though ropes can be treated as Containers of characters, and are almost Sequences, this is rarely the most efficient way to accomplish a task. Replacing an individual character in a rope is slow: each character replacement essentially consists of two substring operations followed by two concatenation operations. Ropes primarily target a more functional programming style.Inserting a character in the middle of a 10 megabyte rope should take on the order of 10s of microseconds, even if a copy of the original is kept, e.g. as part of an edit history.It is possible to view a function producing characters as a rope. Thus a piece of a rope may be a 100MByte file, which is read only when that section of the string is examined. Concatenating a string to the end of such a file does not involve reading the file. (Currently the implementation of this facility is incomplete.)

    另,根据网上资料,rope本质是封装好的类似块状链表的东东,有人说是logn的,但也有说是n^0.5的。rope不支持一切数值操作,如第k大

    小知识

    先介绍几个可能使用到的函数

    1)append()

    string &append(const string &s,int pos,int n);//把字符串s中从pos开始的n个字符连接到当前字符串的结尾

    a.append(b);
    2)substr()

    s.substr(0,5);//获得字符串s中从第零位开始长度为5的字符串(默认时长度为刚好开始位置到结尾)

    定义/声明

    rope<char> str;


    also

    <crope>r="abcdefg"

    具体内容

    总的来说,

    1)运算符:rope支持operator += -= + - < ==

    2)输入输出:可以用<<运算符由输入输出流读入或输出。

    3)长度/大小:调用length(),size()都可以哦

    4)插入/添加等:

    push_back(x);//在末尾添加x

    insert(pos,x);//在pos插入x,自然支持整个char数组的一次插入

    erase(pos,x);//从pos开始删除x个

    copy(pos,len,x);//从pos开始到pos+len为止用x代替

    replace(pos,x);//从pos开始换成x

    substr(pos,x);//提取pos开始x个

    at(x)/[x];//访问第x个元素

    访问

    1)迭代器:不说,在竞赛是超时大忌

    2)单点访问,直接用数组形式调用下标即可

     

  • 相关阅读:
    网站设计分析:模块化——高效重构
    linux 优化git操作速度
    cool
    跨域解决方案
    vue 登录验证引擎
    scss学习笔记
    配置动态加载模块和js分模块打包,生产环境和开发环境公共常量配置
    降低版本安装flashPlayer
    python 学习日志
    centos atomic host第一次启动
  • 原文地址:https://www.cnblogs.com/-xiangyang/p/9376014.html
Copyright © 2011-2022 走看看