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>调 ...
随机推荐
- Lorem 占位符
Web开发者通常用lorem ipsum text来做占位符,占位符就是占着位置的一些文字,没有实际意义. 为什么叫lorem ipsum text呢? 是因为lorem ipsum是古罗马西塞罗谚语 ...
- 判断Exception类中是否有InnerException属性
public static class ExceptionExtend { /// <summary> /// 利用反射来判断对象是否包含某个属性 /// </summary> ...
- tail 尾巴
tail用法:尾巴,取文件的最后N行,默认前10行, -n 2 取前2行-n 2,简写就是-2 -f 文件 跟踪一个文件尾部的时时变化. 克隆出一个窗口执行:循环脚本:for n in `seq 1 ...
- python的学习之路day5
大纲: 1.双层装饰器 单层装饰器 双层装饰器 原理 2.字符串的格式化 3.format字符串格式化 4.生成器 5.递归 6.模块的安装 7.json模块 8.pickle模块 9.time模块 ...
- windows服务器安装telnet的方法指引
摘要: 1.telnet是一种网络排查的工具 2.当发现一台服务器异常的时候,通常有两个cmd命名做排查 3.ping 服务器ip,看网络是否联通 4.telnet 服务器ip 端口 看该服务器指定端 ...
- CheckTimeWait.bat实现windows下的TimeWait检查
原文链接: http://www.lookdaima.com/WebForms/WebPages/Blanks/Pm/Docs/DocItemDetail.aspx?id=c7bff196-cd9c- ...
- plupload 大文件分片上传与PHP分片合并探索
最近老大分给我了做一个电影cms系统,其中涉及到一个功能,使用七牛云的文件上传功能.七牛javascript skd,使用起来很方便,屏蔽了许多的技术细节.如果只满足与调用sdk,那么可能工作中也就没 ...
- 等我干IT发财了,就和你离婚。。。。。
01 “等我干IT发财了,就和你离婚” 他淡淡地说 听完后,她心里暖暖的, 她想,没有比这更天长地久. 海枯石烂的承诺了. ——2018年度最佳微小说奖 02 “等我干IT发财了,我就买房和你结婚.” ...
- linux禁止非法用户试探登录
当我们的linux主机一旦暴露在互联网上,就会遭受到来自网络上的一些非法用户的骚扰.如弱口令扫描,试探性登录:这些行为对linux主机构成一定的威胁.那怎样防范此类的攻击了,这里写了一个脚本,功能就是 ...
- Python代码小片段
1.前面变量值的改变不影响后面变量的调用 index=1 index,a=2,index+1 print(a,index) #2 2 2.类的继承(子类实例如何调用父类同名方法) class a: d ...