stl源码剖析 详细学习笔记deque(2)
//---------------------------15/3/13----------------------------
self&operator++()
{
++cur;
if(cur==last)
{
set_node(node+);
cur=first;
}
return *this;
}
self operator++(int) //这里不能返回引用,因为
tmp是临时变量,作用域结束tmp就消失了
{
self tmp=*this;
++*this;
return tmp;
}
self&operator--()
{
if(cur=first)
{
set_node(node-);
cur=last;
}
--cur;
return *this;
}
selfoperator--(int)
{
self tmp=*this;
--*this;
return temp;
}
/*
1.看能否在不改变node的情况下进行指针位置的移动
2.调整node
offset==(n+x) -->>
最后的位置==first + (n + x)
x代表cur
距离first的距离,也就是cur当前的下标
(offset>0): offset/diffenrence_type(buffer_size())
-->> y==(n + x)/(sz) -->>移动的node节点个数为y
(offset<0) -difference_type((-offset -1) / buffer_size()) - 1
-->> y==-(-n - x -1)/(sz) -1 -->> y==(n + x +1)/(sz) -1
不同于(offset<0)的情况,因为当前处于first位置,移动的距离在
-1到-(sz)是都应该移动一个node节点所以才取上式子;
3.调整cur
(offset>0) :offset==(n + x)
node_offset*difference_type(buffer_size())==(n + x -r)
(r代表余数)
-->>z(位移量)==r
(offset<0) :offset==(n + x)
node_offset*difference_type(buffer_size())==(n + x +r-sz)
-->>z(位移量)==-sz + r
cur =z
*/
self&operator+=(difference_type n)
{
difference_type offset =n+(cur - first);
if(offset >=
&& offset < difference_type(buffer_size()))
cur+=n;
else
{
difference_type node_offset=
offset > ? offset/difference_type(buffer_size())
: -difference_type((-offset -) / buffer_size()) - ;
set_node(node + node_offset);
cur = first +(offset - node_offset * difference_type(buffer_size()));
}
return *this;
}
selfoperator+(difference_type n)
const
{
self tmp=*this;
return tmp+=n;
}
self &operator -=(difference_type n){return *this +=-n;}
selfoperator-(difference_type n)
const
{
self tmp =*this;
return tmp-=n;
}
referenceoperator[](difference_type)const{return *(*this
+n);}
bool
operator==(const self& x)const{return cur==x.cur;}
bool
operator!=(const self& x)const {return !(*this==x);}
bool
operator<(const self& x)const
{
return (node==x.node)?(cur < x.cur) :(node < x.node);
}
>
class deque
{
public:
typedef T value_type;
typedef value_type* pointer;
typedef size_t size_type;
typedef __deque_iterator<T,T&,T*,BufSiz> iteratoer;
protected:
typedef pointer* map_pointer;
iteratoer start;
iteratoer finish;
map_pointer map;
size_type map_size;
public:
iteratoer begin(){return start;}
iteratoer end() {return finish;}
referenceoperator[](size_type n)
{
return start[difference_type(n)];
}
reference front(){return *start;}
reference back()
{
iteratoer tmp=finish;
--tmp;
return *tmp;
//上面三行不改为 return *(finish-1)是因为operator -(difference_type n)
//
的操作比--复杂很多
}
size_type size()const {return finish - start;;}//两个;是手误??
}
stl源码剖析 详细学习笔记deque(2)的更多相关文章
- stl源码剖析 详细学习笔记deque(3)
protected: typedef simple_alloc<value_type,Alloc> data_allocator; //用来配置元素的alloc typedef simpl ...
- stl源码剖析 详细学习笔记deque(1)
//--------------------------15/3/12---------------------------- deque { deque没有容量(capacity)观念,是动态分段的 ...
- stl源码剖析 详细学习笔记 hashtable
//---------------------------15/03/24---------------------------- //hashtable { /* 概述: sgi采用的是开链法完成h ...
- stl源码剖析 详细学习笔记 set map
// // set map.cpp // 笔记 // // Created by fam on 15/3/23. // // //---------------------------15/03 ...
- stl源码剖析 详细学习笔记 RB_tree (1)
// // RB_tree_STL.cpp // 笔记 // // Created by fam on 15/3/21. // // #include "RB_tree_STL.h&q ...
- stl源码剖析 详细学习笔记priority_queue slist
// // priority_queue.cpp // 笔记 // // Created by fam on 15/3/16. // // //------------------------- ...
- stl源码剖析 详细学习笔记heap
// // heap.cpp // 笔记 // // Created by fam on 15/3/15. // // //---------------------------15/03/15 ...
- stl源码剖析 详细学习笔记stack queue
// // stack.cpp // 笔记 // // Created by fam on 15/3/15. // // //---------------------------15/03/1 ...
- stl源码剖析 详细学习笔记 空间配置器
//---------------------------15/04/05---------------------------- /* 空间配置器概述: 1:new操作包含两个阶段操作 1>调 ...
随机推荐
- 如何使用 Azure PowerShell 在 Azure Marketplace 中查找 Windows VM 映像
本主题介绍如何使用 Azure PowerShell 在 Azure Marketplace 中查找 VM 映像. 创建 Windows VM 时使用此信息来指定 Marketplace 映像. 确保 ...
- Oracle EBS 查看双节点是否做了信任
perl $AD_TOP/patch/115/bin/txkRunSSHSetup.pl verifyssh -contextfile=$CONTEXT_FILE -hosts=erpapp1,erp ...
- JQUERY中find方法
[jquery]find()方法和each()方法 find()方法 jquery选择器非常强大,利用css的命名规约,可以更快更方便的找出想要的元素. 比如: $("#id") ...
- mysql 5.5 数据库 utf8改utf8mb4
由于需要用到utf8mb4,之前是utf8现在给改成utf8mb4 查看当前环境 SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_ ...
- orcl 如何快速删除表中百万或千万数据
orcl 数据库表中数据达到上千万时,已经变的特别慢了,所以时不时需要清掉一部分数据. bqh8表中目前有10000000条数据,需要保留19条数据,其余全部清除掉. 以下为个人方法: 1.首先把需要 ...
- 每年有20万人进军IT行业,为何还会人才短缺?
众所周知,IT行业是个高薪行业,也是很多人的梦想职业,在全球最缺人的十大行业中IT行业居首位. 但是现在很多人都有一个疑问: 几乎每所大学里都有计算机技术相关专业,再加上IT培训机构的输出,每年培养出 ...
- 在阿里云Windows Server 上部署ASP .NET CORE2.0项目
近期使用ASP.NET Core2.0对博客进行了重写,在部署到服务器时遇到了一些问题,来记录一下留用. 配置环境 安装 .Net Framework3.5 在IIS管理器上直接开启,这里总是失败,上 ...
- LINE学习
LINE Abstract LINE 是一种将大规模网络结点表征成低维向量的算法,可很方便用于网络可视化,结点分类,链路预测,推荐. source code Advantage LINE相比于其他算法 ...
- 团队作业——Beta冲刺3
团队作业--Beta冲刺 冲刺任务安排 杨光海天 今日任务:浏览详情界面的开发 明日任务:浏览详情界面的开发 吴松青 今日任务:与队长一同进行图片详情的开发,接触了一些自己没接触过的知识点并向队友学习 ...
- 绕过安全狗狗的WebShell for PHP
最近发现一款过狗shell,分享下... 本地搭建2008SERVER+php5+阿帕奇+网站安全狗+服务器安全狗+防护全开 测试可用... 默认密码:p0tt1 使用方法: ,没关系,按p键 ...