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>调 ...
随机推荐
- Prometheus Node_exporter 之 Node Exporter
Node Exporter 1. Node Exporter Scrape Time type: GraphUnit: secondsLabel: Seconds{{collector}} - 各个收 ...
- 使用 Azure PowerShell 监视和更新 Windows 虚拟机
Azure 监视使用代理从 Azure VM 收集启动和性能数据,将此数据存储在 Azure 存储中,并使其可供通过门户.Azure PowerShell 模块和 Azure CLI 进行访问. 使用 ...
- security/pam_appl.h:没有那个文件或目录
在编译开源库时, 提示 pam.h:4:10: 致命错误:security/pam_appl.h:没有那个文件或目录 #include <security/pam_appl.h> 解决方法 ...
- sysbench压力工具报错:
[root@ sysbench-]# /usr/local/sysbench/bin/sysbench --version : cannot open shared object file: No s ...
- TiDB数据库集群安装以及注意事项
今天尝试安装tidb集群.详细的安装步骤我们参考:https://pingcap.com/docs-cn/op-guide/ansible-deployment/ . 不过安装之前需要一些注意事项. ...
- 小渣渣的json和jsonp和ajax的实质和区别
json和jsonp和ajax的实质和区别ajax的两个问题 1.ajax以何种格式来交换数据 2.跨域的需求如何解决 数据跨域用自定义字符串或者用XML来描述 跨域可以用服务器代理来解决jsonp来 ...
- 【Python求助】在eclipse和pycharm中,通过adb install安装中文名字APK时老是报错,如何解决
# -*- coding: utf-8 -*- import os import sys import subprocess import time from uiautomator import d ...
- Redis系列三:reids常用命令
全局命令 keys * 查看所有键 dbsize 查看的是当前所在redis数据库的键总数 如果存在大量键,线上禁止使用此指令 exists key 检查键是否存在,存在返回1,不存在返回0 del ...
- Android APP的字体设置
Android系统自带有对字体的设置,这些设置是对字体的显示方式的设置,比如加粗,倾斜,下划线,字号等,但是对于字体本身,比如设置为楷体,隶书等貌似没有.Android系统只有一种默认的,如果需要修改 ...
- php无限分类 下拉框
无限分类 下拉框优势:填写参数少,只需要指定一个循环节点($parnent_id),就可以循环所有下级分类.循环输出结构很有特色,比较符合我的口味.补充: $parent_id才是上下级关联的节点,i ...