侯捷stl源码剖析注释之11 sgi-std-bastring-cc
hgat代码解析
Heterogeneous Graph Attention Network (H-GAT) 是一种用于处理异构图的神经网络模型。
下面是对H-GAT代码的解析:
首先,H-GAT模型的核心思想是利用异构图的节点类型和属性信息,通过自注意力机制对节点进行特征提取和分类。
在H-GAT代码中,首先定义了异构图的节点类型和属性信息,包括节点类型、节点属性等。
然后,定义了异构图的邻接矩阵和度矩阵,用于表示节点之间的连接关系和节点的重要性。
接下来,H-GAT模型定义了自注意力机制,通过计算节点之间的相似度来提取节点的特征。
在自注意力机制中,首先计算节点之间的相似度矩阵,然后通过softmax函数将相似度矩阵转化为注意力系数矩阵。
最后,将注意力系数矩阵与节点的特征向量相乘,得到节点的特征表示。
在H-GAT模型中,还定义了多个注意力模块,分别对应不同的节点类型和属性信息。
这些注意力模块通过共享参数的方式进行训练,使得模型能够同时处理不同类型的节点和属性信息。
最后,H-GAT模型通过损失函数对模型进行训练,并使用优化算法对模型参数进行更新。
在训练过程中,模型不断优化自注意力机制
和参数更新算法,使得模型能够更好地处理异构图数据。
总之,H-GAT模型是一种基于自注意力机制的神经网络模型,能够处理异构图数据并提取节点的特征表示。
在代码实现中,通过定义节点类型和属性信息、邻接矩阵和度矩阵、自注意力机制和多个注意力模块等关键组件,实现了对异构图数据的有效处理。
SIMPL Windows基础教程 - 最终版
快思聪SIMPL Windows编程语言初级教程目录第一章快思聪SIMPL WINDOWS (5)概览 (5)关于初级教程 (5)快思聪开发软件 (6)SIMPL Windows (6)快思聪VisionTool Pro-e (6)DEAL TM for Windows (6)Media Manager TM System Builder (6)D3 Pro TM (7)数据库(Database) (7)产品目录光盘 (7)快思聪控制系统 (9)为什么对控制系统编程? (9)控制系统组件 (9)主机 (9)网络控制模块 (10)Plug-in控制卡 (10)用户界面 (10)触摸屏 (10)键盘(按键面板) (10)无线摇控界面 (10)用户设备 (10)控制方式 (11)继电器控制 (11)串口通信控制 (11)红外 (11)自定义串量 (13)RS232,RS422,RS485 (13)MIDI(数字音乐设备接口) (14)模拟电压 (14)自定义快思聪接口界面 (14)Cresnet (14)第二章SIMPL WINDOWS编程 (16)SIMPL介绍 (16)函数库 (16)设备函数 (16)逻辑函数 (16)函数属性 (16)输入 (17)输出 (17)信号类型 (18)数字量 (18)模拟信号量 (18)串量 (19)特殊信号0和1 (19)逻辑波跟逻辑解决方案 (19)用户界面编程 (21)按钮动作 (21)按钮反馈 (21)子页(仅用于触摸屏) (23)模拟显示(仅用于触摸屏) (23)间接文本(仅用于触摸屏) (24)用SIMPL W INDOWS来创建一个程序 (25)编程步骤 (25)基本编程规则 (25)建立一个系统 (25)网络硬件 (28)控制插卡 (29)串口设备 (29)用户设备 (30)网络ID (30)配置设备 (31)快思聪网络设备 (31)以太网设备 (32)串口设备 (33)触摸屏 (33)连接信号 (34)定义用户界面信号 (34)使用逻辑函数 (35)第三章逻辑函数编程 (37)概述 (37)逻辑函数的类型 (37)基本逻辑 (38)NOT函数 (38)OR函数 (38)AND函数 (40)Buffer函数 (41)状态逻辑 (46)Set/Reset Latch函数 (46)Toggle函数 (47)Interlock函数 (49)基于时间的逻辑 (52)One Shot 系列 (52)Multiple One Shot (53)Retriggerable One Shot (53)Delay Symbol (54)Oscillator Symbol (55)模拟逻辑 (57)Analog Ramp函数 (57)Analog Initialize (58)Analog Preset函数 (59)Serial/Analog One-Shot (61)Modules模块 (61)Communication Settings (62)Compiling and Uploading Programs (64)第一章快思聪SIMPL Windows概览关于初级教程编写本教程的目的在于向程序设计人员介绍SIMPL windows编程技术以及如何应用快思聪控制系统,这包括对控制系统如何利用触摸屏和按钮作为用户界面的理解,通过这些界面,使用者可以发送一个信号(主要是逻辑函数)给控制系统处理后输出用以最终控制一个设备。
侯捷老师——STL源码剖析
侯捷老师——STL源码剖析侯捷老师是国内知名的C++专家,他在C++领域有着很高的知名度和影响力。
他的《STL源码剖析》是一本非常经典的C++书籍,深入剖析了C++标准模板库(Standard Template Library,STL)的源代码,并详细解释了其设计思想和实现细节。
下面是对这本书的1200字以上的介绍。
《STL源码剖析》是一本写给C++程序员的经典著作,它由侯捷老师亲自编写,内容非常详尽和深入。
这本书主要介绍了C++标准模板库(STL)的源代码,并解析了其中的设计思想和实现细节。
通过阅读这本书,读者可以更好地理解STL的底层原理,提高自己的C++编程能力。
这本书共分为13个章节,每个章节都涉及了STL的不同组件和特性。
书中的内容既包括理论知识,也包括具体的代码实现。
侯捷老师用通俗易懂的语言和形象生动的例子,对STL的各个组件进行了详细介绍。
他从容器、迭代器、算法和函数对象等方面入手,逐步展开对STL的剖析。
每一章的结尾都有相关的练习题,读者可以通过做题来巩固所学知识。
在《STL源码剖析》中,侯捷老师对STL的源代码进行了深入分析,解释了其中的设计思想和实现原理。
他通过对容器的底层结构和操作进行剖析,揭示了STL的高效性和灵活性。
在对算法和函数对象的讲解中,他详细介绍了STL中的各种常用算法,并解释了它们的内部实现原理。
通过这种深入的分析,读者可以更好地理解STL的运作机制,并能够灵活运用STL进行程序设计。
除了对STL源代码的剖析,侯捷老师还对STL的使用和扩展进行了说明。
他介绍了STL的使用注意事项和常见问题,并给出了一些实用的编程技巧和优化建议。
此外,他还展示了如何扩展STL,给出了一些自定义容器和算法的示例。
这些内容对于想要深入学习和应用STL的读者来说是非常有价值的。
总的来说,侯捷老师的《STL源码剖析》是一本非常权威和深入的C++书籍,对于想要深入学习STL的C++程序员来说是一本必读之作。
侯捷stl源码剖析注释之11 sgi-std-bastring-cc
<std\> 完整列表 The Annotated STL Sources 1G++ 2.91.57,cygnus\cygwin-b20\include\g++\std\ 完整列表// Member templates for the -*- C++ -*- string classes.// Copyright (C) 1994 Free Software Foundation// This file is part of the GNU ANSI C++ Library. This library is free// software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the// Free Software Foundation ; either version 2, or (at your option)// any later version.// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License// along with this library; see the file COPYING. If not, write to the Free// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.// As a special exception, if you link this library with files// compiled with a GNU compiler to produce an executable, this does not cause // the resulting executable to be covered by the GNU General Public License. // This exception does not however invalidate any other reasons why// the executable file might be covered by the GNU General Public License.// Written by Jason Merrill based upon the specification by Takanori Adachi // in ANSI X3J16/94-0013R2.extern "C++" {template <class charT, class traits, class Allocator>inline void * basic_string <charT, traits, Allocator>::Rep::operator new (size_t s, size_t extra){return Allocator::allocate(s + extra * sizeof (charT));}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::operator delete (void * ptr){Allocator::deallocate(ptr, sizeof(Rep) +reinterpret_cast<Rep *>(ptr)->res *sizeof (charT));}template <class charT, class traits, class Allocator>inline size_t basic_string <charT, traits, Allocator>::Rep::frob_size (size_t s){<std\> 完整列表 The Annotated STL Sources 2 size_t i = 16;while (i < s) i *= 2;return i;}template <class charT, class traits, class Allocator>inline basic_string <charT, traits, Allocator>::Rep *basic_string <charT, traits, Allocator>::Rep::create (size_t extra){extra = frob_size (extra + 1);Rep *p = new (extra) Rep;p->res = extra;p->ref = 1;p->selfish = false;return p;}template <class charT, class traits, class Allocator>charT * basic_string <charT, traits, Allocator>::Rep::clone (){Rep *p = Rep::create (len);p->copy (0, data (), len);p->len = len;return p->data ();}template <class charT, class traits, class Allocator>inline bool basic_string <charT, traits, Allocator>::Rep::excess_slop (size_t s, size_t r){return 2 * (s <= 16 ? 16 : s) < r;}template <class charT, class traits, class Allocator>inline bool basic_string <charT, traits, Allocator>::check_realloc (basic_string::size_type s) const{s += sizeof (charT);rep ()->selfish = false;return (rep ()->ref > 1|| s > capacity ()|| Rep::excess_slop (s, capacity ()));}template <class charT, class traits, class Allocator>void basic_string <charT, traits, Allocator>::alloc (basic_string::size_type size, bool save)<std\> 完整列表 The Annotated STL Sources 3{if (! check_realloc (size))return;Rep *p = Rep::create (size);if (save){p->copy (0, data (), length ());p->len = length ();}elsep->len = 0;repup (p);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>&basic_string <charT, traits, Allocator>::replace (size_type pos1, size_type n1,const basic_string& str, size_type pos2, size_type n2){const size_t len2 = str.length ();if (pos1 == 0 && n1 >= length () && pos2 == 0 && n2 >= len2)return operator= (str);OUTOFRANGE (pos2 > len2);if (n2 > len2 - pos2)n2 = len2 - pos2;return replace (pos1, n1, str.data () + pos2, n2);}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::copy (size_t pos, const charT *s, size_t n){if (n)traits::copy (data () + pos, s, n);}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::move (size_t pos, const charT *s, size_t n){if (n)<std\> 完整列表 The Annotated STL Sources 4 traits::move (data () + pos, s, n);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>&basic_string <charT, traits, Allocator>::replace (size_type pos, size_type n1, const charT* s, size_type n2){const size_type len = length ();OUTOFRANGE (pos > len);if (n1 > len - pos)n1 = len - pos;LENGTHERROR (len - n1 > max_size () - n2);size_t newlen = len - n1 + n2;if (check_realloc (newlen)){Rep *p = Rep::create (newlen);p->copy (0, data (), pos);p->copy (pos + n2, data () + pos + n1, len - (pos + n1));p->copy (pos, s, n2);repup (p);}else{rep ()->move (pos + n2, data () + pos + n1, len - (pos + n1));rep ()->copy (pos, s, n2);}rep ()->len = newlen;return *this;}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::set (size_t pos, const charT c, size_t n){traits::set (data () + pos, c, n);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>& basic_string <charT, traits, Allocator>:: replace (size_type pos, size_type n1, size_type n2, charT c){const size_t len = length ();OUTOFRANGE (pos > len);if (n1 > len - pos)n1 = len - pos;LENGTHERROR (len - n1 > max_size () - n2);<std\> 完整列表 The Annotated STL Sources 5size_t newlen = len - n1 + n2;if (check_realloc (newlen)){Rep *p = Rep::create (newlen);p->copy (0, data (), pos);p->copy (pos + n2, data () + pos + n1, len - (pos + n1));p->set (pos, c, n2);repup (p);}else{rep ()->move (pos + n2, data () + pos + n1, len - (pos + n1));rep ()->set (pos, c, n2);}rep ()->len = newlen;return *this;}template <class charT, class traits, class Allocator>void basic_string <charT, traits, Allocator>::resize (size_type n, charT c){LENGTHERROR (n > max_size ());if (n > length ())append (n - length (), c);elseerase (n);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::copy (charT* s, size_type n, size_type pos) const{OUTOFRANGE (pos > length ());if (n > length () - pos)n = length () - pos;traits::copy (s, data () + pos, n);return n;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::<std\> 完整列表 The Annotated STL Sources 6 find (const charT* s, size_type pos, size_type n) const{size_t xpos = pos;for (; xpos + n <= length (); ++xpos)if (traits::eq (data () [xpos], *s)&& traits::compare (data () + xpos, s, n) == 0)return xpos;return npos;}template <class charT, class traits, class Allocator>inline basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::_find (const charT* ptr, charT c, size_type xpos, size_type len){for (; xpos < len; ++xpos)if (traits::eq (ptr [xpos], c))return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find (charT c, size_type pos) const{return _find (data (), c, pos, length ());}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::rfind (const charT* s, size_type pos, size_type n) const{if (n > length ())return npos;size_t xpos = length () - n;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0; )if (traits::eq (data () [xpos], *s)&& traits::compare (data () + xpos, s, n) == 0)return xpos;return npos;}template <class charT, class traits, class Allocator><std\> 完整列表 The Annotated STL Sources 7basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::rfind (charT c, size_type pos) const{if (1 > length ())return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0; )if (traits::eq (data () [xpos], c))return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_first_of (const charT* s, size_type pos, size_type n) const{size_t xpos = pos;for (; xpos < length (); ++xpos)if (_find (s, data () [xpos], 0, n) != npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_last_of (const charT* s, size_type pos, size_type n) const{if (length() == 0)return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0;)if (_find (s, data () [xpos], 0, n) != npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_first_not_of (const charT* s, size_type pos, size_type n) const<std\> 完整列表 The Annotated STL Sources 8 {size_t xpos = pos;for (; xpos < length (); ++xpos)if (_find (s, data () [xpos], 0, n) == npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_first_not_of (charT c, size_type pos) const{size_t xpos = pos;for (; xpos < length (); ++xpos)if (traits::ne (data () [xpos], c))return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_last_not_of (const charT* s, size_type pos, size_type n) const{if (length() == 0)return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0;)if (_find (s, data () [xpos], 0, n) == npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_last_not_of (charT c, size_type pos) const{if (length() == 0)return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0;)if (traits::ne (data () [xpos], c))return xpos;<std\> 完整列表 The Annotated STL Sources 9return npos;}template <class charT, class traits, class Allocator>int basic_string <charT, traits, Allocator>::compare (const basic_string& str, size_type pos, size_type n) const{OUTOFRANGE (pos > length ());size_t rlen = length () - pos;if (rlen > n)rlen = n;if (rlen > str.length ())rlen = str.length ();int r = traits::compare (data () + pos, str.data (), rlen);if (r != 0)return r;if (rlen == n)return 0;return (length () - pos) - str.length ();}template <class charT, class traits, class Allocator>int basic_string <charT, traits, Allocator>::compare (const charT* s, size_type pos, size_type n) const{OUTOFRANGE (pos > length ());size_t rlen = length () - pos;if (rlen > n)rlen = n;int r = traits::compare (data () + pos, s, rlen);if (r != 0)return r;return (length () - pos) - n;}#include <iostream.h>template <class charT, class traits, class Allocator>istream &operator>> (istream &is, basic_string <charT, traits, Allocator> &s){int w = is.width (0);if (is.ipfx0 ()){register streambuf *sb = is.rdbuf ();s.resize (0);while (1)<std\> 完整列表 The Annotated STL Sources 10 {int ch = sb->sbumpc ();if (ch == EOF){is.setstate (ios::eofbit);break;}else if (traits::is_del (ch)){sb->sungetc ();break;}s += ch;if (--w == 1)break;}}is.isfx ();if (s.length () == 0)is.setstate (ios::failbit);return is;}template <class charT, class traits, class Allocator>ostream &operator<< (ostream &o, const basic_string <charT, traits, Allocator>& s) {return o.write (s.data (), s.length ());}template <class charT, class traits, class Allocator>istream&getline (istream &is, basic_string <charT, traits, Allocator>& s, charT delim) {if (is.ipfx1 ()){_IO_size_t count = 0;streambuf *sb = is.rdbuf ();s.resize (0);while (1){int ch = sb->sbumpc ();if (ch == EOF){is.setstate (count == 0? (ios::failbit|ios::eofbit)<std\> 完整列表 The Annotated STL Sources 11 : ios::eofbit);break;}++count;if (ch == delim)break;s += ch;if (s.length () == s.npos - 1){is.setstate (ios::failbit);break;}}}// We need to be friends with istream to do this.// is._gcount = count;is.isfx ();return is;}// static data member of class basic_string<>template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::Repbasic_string<charT, traits, Allocator>::nilRep = { 0, 0, 1, false };template <class charT, class traits, class Allocator>const basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::npos ;} // extern "C++"。
侯捷stl源码剖析注释45 stl-source-sgi-memory
STL source 1 G++ 2.91.57,cygnus\cygwin-b20\include\g++\memory 完整列表/** Copyright (c) 1997* Silicon Graphics Computer Systems, Inc.** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee,* provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation. Silicon Graphics makes no* representations about the suitability of this software for any* purpose. It is provided "as is" without express or implied warranty.**/#ifndef __SGI_STL_MEMORY#define __SGI_STL_MEMORY#include <stl_algobase.h>#include <stl_alloc.h>#include <stl_construct.h>#include <stl_tempbuf.h>#include <stl_uninitialized.h>#include <stl_raw_storage_iter.h>// Note: auto_ptr is commented out in this release because the details// of the interface are still being discussed by the C++ standardization// committee. It will be included once the iterface is finalized.#if 0#if defined(_MUTABLE_IS_KEYWORD) && defined(_EXPLICIT_IS_KEYWORD) && \defined(__STL_MEMBER_TEMPLATES)__STL_BEGIN_NAMESPACEtemplate <class X> class auto_ptr {private:X* ptr;mutable bool owns;public:typedef X element_type;explicit auto_ptr(X* p = 0) __STL_NOTHROW : ptr(p), owns(p) {}auto_ptr(const auto_ptr& a) __STL_NOTHROW : ptr(a.ptr), owns(a.owns) {a.owns = 0;}template <class T> auto_ptr(const auto_ptr<T>& a) __STL_NOTHROW: ptr(a.ptr), owns(a.owns) {a.owns = 0;2STL source }auto_ptr& operator=(const auto_ptr& a) __STL_NOTHROW {if (&a != this) {if (owns)delete ptr;owns = a.owns;ptr = a.ptr;a.owns = 0;}}template <class T> auto_ptr& operator=(const auto_ptr<T>& a) __STL_NOTHROW {if (&a != this) {if (owns)delete ptr;owns = a.owns;ptr = a.ptr;a.owns = 0;}}~auto_ptr() {if (owns)delete ptr;}X& operator*() const __STL_NOTHROW { return *ptr; }X* operator->() const __STL_NOTHROW { return ptr; }X* get() const __STL_NOTHROW { return ptr; }X* release const __STL_NOTHROW { owns = false; return ptr }};__STL_END_NAMESPACE#endif /* mutable && explicit && member templates */#endif /* 0 */#endif /* __SGI_STL_MEMORY */// Local Variables:// mode:C++// End:。
侯捷stl源码剖析注释之17 sgi-stl-33-function
SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 1SGI STL 3.3 stl_function.h 完整列表/*** Copyright (c) 1994* Hewlett-Packard Company** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation. Hewlett-Packard Company makes no* representations about the suitability of this software for any* purpose. It is provided "as is" without express or implied warranty. *** Copyright (c) 1996-1998* Silicon Graphics Computer Systems, Inc.** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation. Silicon Graphics makes no* representations about the suitability of this software for any* purpose. It is provided "as is" without express or implied warranty. *//* NOTE: This is an internal header file, included by other STL headers. * You should not attempt to use it directly.*/#ifndef __SGI_STL_INTERNAL_FUNCTION_H#define __SGI_STL_INTERNAL_FUNCTION_H__STL_BEGIN_NAMESPACEtemplate <class _Arg, class _Result>struct unary_function {typedef _Arg argument_type;typedef _Result result_type;};template <class _Arg1, class _Arg2, class _Result>struct binary_function {typedef _Arg1 first_argument_type;typedef _Arg2 second_argument_type;typedef _Result result_type;};第1章 Classes 的語法和語意The Annotated STL Sources 2 template <class _Tp>struct plus : public binary_function<_Tp,_Tp,_Tp> {_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; } };template <class _Tp>struct minus : public binary_function<_Tp,_Tp,_Tp> {_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; } };template <class _Tp>struct multiplies : public binary_function<_Tp,_Tp,_Tp> {_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; } };template <class _Tp>struct divides : public binary_function<_Tp,_Tp,_Tp> {_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; } };// identity_element (not part of the C++ standard).template <class _Tp> inline _Tp identity_element(plus<_Tp>) {return _Tp(0);}template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) {return _Tp(1);}template <class _Tp>struct modulus : public binary_function<_Tp,_Tp,_Tp>{_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; } };template <class _Tp>struct negate : public unary_function<_Tp,_Tp>{_Tp operator()(const _Tp& __x) const { return -__x; }};template <class _Tp>struct equal_to : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; } };template <class _Tp>struct not_equal_to : public binary_function<_Tp,_Tp,bool>SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 3{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; } };template <class _Tp>struct greater : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; } };template <class _Tp>struct less : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; } };template <class _Tp>struct greater_equal : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; } };template <class _Tp>struct less_equal : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; } };template <class _Tp>struct logical_and : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; } };template <class _Tp>struct logical_or : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; } };template <class _Tp>struct logical_not : public unary_function<_Tp,bool>{bool operator()(const _Tp& __x) const { return !__x; }};template <class _Predicate>class unary_negate: public unary_function<typename _Predicate::argument_type, bool> {第1章 Classes 的語法和語意The Annotated STL Sources 4 protected:_Predicate _M_pred;public:explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}bool operator()(const typename _Predicate::argument_type& __x) const { return !_M_pred(__x);}};template <class _Predicate>inline unary_negate<_Predicate>not1(const _Predicate& __pred){return unary_negate<_Predicate>(__pred);}template <class _Predicate>class binary_negate: public binary_function<typename _Predicate::first_argument_type,typename _Predicate::second_argument_type,bool> {protected:_Predicate _M_pred;public:explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}bool operator()(const typename _Predicate::first_argument_type& __x, const typename _Predicate::second_argument_type& __y) const {return !_M_pred(__x, __y);}};template <class _Predicate>inline binary_negate<_Predicate>not2(const _Predicate& __pred){return binary_negate<_Predicate>(__pred);}template <class _Operation>class binder1st: public unary_function<typename _Operation::second_argument_type,typename _Operation::result_type> {protected:_Operation op;typename _Operation::first_argument_type value;public:binder1st(const _Operation& __x,const typename _Operation::first_argument_type& __y)SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 5: op(__x), value(__y) {}typename _Operation::result_typeoperator()(const typename _Operation::second_argument_type& __x) const { return op(value, __x);}};template <class _Operation, class _Tp>inline binder1st<_Operation>bind1st(const _Operation& __fn, const _Tp& __x){typedef typename _Operation::first_argument_type _Arg1_type;return binder1st<_Operation>(__fn, _Arg1_type(__x));}template <class _Operation>class binder2nd: public unary_function<typename _Operation::first_argument_type,typename _Operation::result_type> {protected:_Operation op;typename _Operation::second_argument_type value;public:binder2nd(const _Operation& __x,const typename _Operation::second_argument_type& __y): op(__x), value(__y) {}typename _Operation::result_typeoperator()(const typename _Operation::first_argument_type& __x) const { return op(__x, value);}};template <class _Operation, class _Tp>inline binder2nd<_Operation>bind2nd(const _Operation& __fn, const _Tp& __x){typedef typename _Operation::second_argument_type _Arg2_type;return binder2nd<_Operation>(__fn, _Arg2_type(__x));}// unary_compose and binary_compose (extensions, not part of the standard).template <class _Operation1, class _Operation2>class unary_compose: public unary_function<typename _Operation2::argument_type,typename _Operation1::result_type>{protected:_Operation1 _M_fn1;第1章 Classes 的語法和語意The Annotated STL Sources 6 _Operation2 _M_fn2;public:unary_compose(const _Operation1& __x, const _Operation2& __y): _M_fn1(__x), _M_fn2(__y) {}typename _Operation1::result_typeoperator()(const typename _Operation2::argument_type& __x) const {return _M_fn1(_M_fn2(__x));}};template <class _Operation1, class _Operation2>inline unary_compose<_Operation1,_Operation2>compose1(const _Operation1& __fn1, const _Operation2& __fn2){return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);}template <class _Operation1, class _Operation2, class _Operation3>class binary_compose: public unary_function<typename _Operation2::argument_type,typename _Operation1::result_type> {protected:_Operation1 _M_fn1;_Operation2 _M_fn2;_Operation3 _M_fn3;public:binary_compose(const _Operation1& __x, const _Operation2& __y,const _Operation3& __z): _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }typename _Operation1::result_typeoperator()(const typename _Operation2::argument_type& __x) const {return _M_fn1(_M_fn2(__x), _M_fn3(__x));}};template <class _Operation1, class _Operation2, class _Operation3>inline binary_compose<_Operation1, _Operation2, _Operation3>compose2(const _Operation1& __fn1, const _Operation2& __fn2,const _Operation3& __fn3){return binary_compose<_Operation1,_Operation2,_Operation3>(__fn1, __fn2, __fn3);}template <class _Arg, class _Result>class pointer_to_unary_function : public unary_function<_Arg, _Result> { protected:_Result (*_M_ptr)(_Arg);public:SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 7pointer_to_unary_function() {}explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {} _Result operator()(_Arg __x) const { return _M_ptr(__x); }};template <class _Arg, class _Result>inline pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__x)(_Arg)) {return pointer_to_unary_function<_Arg, _Result>(__x);}template <class _Arg1, class _Arg2, class _Result>class pointer_to_binary_function :public binary_function<_Arg1,_Arg2,_Result> {protected:_Result (*_M_ptr)(_Arg1, _Arg2);public:pointer_to_binary_function() {}explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2)): _M_ptr(__x) {}_Result operator()(_Arg1 __x, _Arg2 __y) const {return _M_ptr(__x, __y);}};template <class _Arg1, class _Arg2, class _Result>inline pointer_to_binary_function<_Arg1,_Arg2,_Result>ptr_fun(_Result (*__x)(_Arg1, _Arg2)) {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__x);}// identity is an extensions: it is not part of the standard.template <class _Tp>struct _Identity : public unary_function<_Tp,_Tp> {const _Tp& operator()(const _Tp& __x) const { return __x; }};template <class _Tp> struct identity : public _Identity<_Tp> {};// select1st and select2nd are extensions: they are not part of the standard. template <class _Pair>struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> { const typename _Pair::first_type& operator()(const _Pair& __x) const { return __x.first;}};template <class _Pair>struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>第1章 Classes 的語法和語意The Annotated STL Sources 8 {const typename _Pair::second_type& operator()(const _Pair& __x) const { return __x.second;}};template <class _Pair> struct select1st : public _Select1st<_Pair> {}; template <class _Pair> struct select2nd : public _Select2nd<_Pair> {};// project1st and project2nd are extensions: they are not part of the standard template <class _Arg1, class _Arg2>struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {_Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; } };template <class _Arg1, class _Arg2>struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {_Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; } };template <class _Arg1, class _Arg2>struct project1st : public _Project1st<_Arg1, _Arg2> {};template <class _Arg1, class _Arg2>struct project2nd : public _Project2nd<_Arg1, _Arg2> {};// constant_void_fun, constant_unary_fun, and constant_binary_fun are // extensions: they are not part of the standard. (The same, of course, // is true of the helper functions constant0, constant1, and constant2.)template <class _Result>struct _Constant_void_fun {typedef _Result result_type;result_type _M_val;_Constant_void_fun(const result_type& __v) : _M_val(__v) {}const result_type& operator()() const { return _M_val; }};template <class _Result, class _Argument>struct _Constant_unary_fun {typedef _Argument argument_type;typedef _Result result_type;result_type _M_val;_Constant_unary_fun(const result_type& __v) : _M_val(__v) {}const result_type& operator()(const _Argument&) const { return _M_val; } };SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 9template <class _Result, class _Arg1, class _Arg2>struct _Constant_binary_fun {typedef _Arg1 first_argument_type;typedef _Arg2 second_argument_type;typedef _Result result_type;_Result _M_val;_Constant_binary_fun(const _Result& __v) : _M_val(__v) {}const result_type& operator()(const _Arg1&, const _Arg2&) const {return _M_val;}};template <class _Result>struct constant_void_fun : public _Constant_void_fun<_Result> {constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(__v) {} };template <class _Result,class _Argument __STL_DEPENDENT_DEFAULT_TMPL(_Result)>struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument> {constant_unary_fun(const _Result& __v): _Constant_unary_fun<_Result, _Argument>(__v) {}};template <class _Result,class _Arg1 __STL_DEPENDENT_DEFAULT_TMPL(_Result),class _Arg2 __STL_DEPENDENT_DEFAULT_TMPL(_Arg1)>struct constant_binary_fun: public _Constant_binary_fun<_Result, _Arg1, _Arg2>{constant_binary_fun(const _Result& __v): _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}};template <class _Result>inline constant_void_fun<_Result> constant0(const _Result& __val){return constant_void_fun<_Result>(__val);}template <class _Result>inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val) {return constant_unary_fun<_Result,_Result>(__val);}第1章 Classes 的語法和語意 The Annotated STL Sources 10template <class _Result>inline constant_binary_fun<_Result,_Result,_Result>constant2(const _Result& __val){return constant_binary_fun<_Result,_Result,_Result>(__val);}// subtractive_rng is an extension: it is not part of the standard. // Note: this code assumes that int is 32 bits.class subtractive_rng : public unary_function<unsigned int, unsigned int> { private:unsigned int _M_table[55];size_t _M_index1;size_t _M_index2;public:unsigned int operator()(unsigned int __limit) {_M_index1 = (_M_index1 + 1) % 55;_M_index2 = (_M_index2 + 1) % 55;_M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2]; return _M_table[_M_index1] % __limit;}void _M_initialize(unsigned int __seed){unsigned int __k = 1;_M_table[54] = __seed;size_t __i;for (__i = 0; __i < 54; __i++) {size_t __ii = (21 * (__i + 1) % 55) - 1;_M_table[__ii] = __k;__k = __seed - __k;__seed = _M_table[__ii];}for (int __loop = 0; __loop < 4; __loop++) {for (__i = 0; __i < 55; __i++)_M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55]; }_M_index1 = 0;_M_index2 = 31;}subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }subtractive_rng() { _M_initialize(161803398u); }};// Adaptor function objects: pointers to member functions.SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 11// There are a total of 16 = 2^4 function objects in this family.// (1) Member functions taking no arguments vs member functions taking // one argument.// (2) Call through pointer vs call through reference.// (3) Member function with void return type vs member function with// non-void return type.// (4) Const vs non-const member function.// Note that choice (3) is nothing more than a workaround: according// to the draft, compilers should handle void and non-void the same way. // This feature is not yet widely implemented, though. You can only use // member functions returning void if your compiler supports partial// specialization.// All of this complexity is in the function objects themselves. You can // ignore it by using the helper function mem_fun and mem_fun_ref,// which create whichever type of adaptor is appropriate.// (mem_fun1 and mem_fun1_ref are no longer part of the C++ standard,// but they are provided for backward compatibility.)template <class _Ret, class _Tp>class mem_fun_t : public unary_function<_Tp*,_Ret> {public:explicit mem_fun_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}_Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }private:_Ret (_Tp::*_M_f)();};template <class _Ret, class _Tp>class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {public:explicit const_mem_fun_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}_Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }private:_Ret (_Tp::*_M_f)() const;};template <class _Ret, class _Tp>class mem_fun_ref_t : public unary_function<_Tp,_Ret> {public:explicit mem_fun_ref_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}_Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }private:_Ret (_Tp::*_M_f)();};第1章 Classes 的語法和語意The Annotated STL Sources 12 template <class _Ret, class _Tp>class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {public:explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {} _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }private:_Ret (_Tp::*_M_f)() const;};template <class _Ret, class _Tp, class _Arg>class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {public:explicit mem_fun1_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}_Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); } private:_Ret (_Tp::*_M_f)(_Arg);};template <class _Ret, class _Tp, class _Arg>class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> { public:explicit const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} _Ret operator()(const _Tp* __p, _Arg __x) const{ return (__p->*_M_f)(__x); }private:_Ret (_Tp::*_M_f)(_Arg) const;};template <class _Ret, class _Tp, class _Arg>class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {public:explicit mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}_Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); } private:_Ret (_Tp::*_M_f)(_Arg);};template <class _Ret, class _Tp, class _Arg>class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {public:explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} _Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); } private:_Ret (_Tp::*_M_f)(_Arg) const;};#ifdef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class _Tp>SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 13class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {public:explicit mem_fun_t(void (_Tp::*__pf)()) : _M_f(__pf) {}void operator()(_Tp* __p) const { (__p->*_M_f)(); }private:void (_Tp::*_M_f)();};template <class _Tp>class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> { public:explicit const_mem_fun_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}void operator()(const _Tp* __p) const { (__p->*_M_f)(); }private:void (_Tp::*_M_f)() const;};template <class _Tp>class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {public:explicit mem_fun_ref_t(void (_Tp::*__pf)()) : _M_f(__pf) {}void operator()(_Tp& __r) const { (__r.*_M_f)(); }private:void (_Tp::*_M_f)();};template <class _Tp>class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> { public:explicit const_mem_fun_ref_t(void (_Tp::*__pf)() const) : _M_f(__pf) {} void operator()(const _Tp& __r) const { (__r.*_M_f)(); }private:void (_Tp::*_M_f)() const;};template <class _Tp, class _Arg>class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> { public:explicit mem_fun1_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }private:void (_Tp::*_M_f)(_Arg);};template <class _Tp, class _Arg>class const_mem_fun1_t<void, _Tp, _Arg>: public binary_function<const _Tp*,_Arg,void> {public:explicit const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}第1章 Classes 的語法和語意The Annotated STL Sources 14 void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } private:void (_Tp::*_M_f)(_Arg) const;};template <class _Tp, class _Arg>class mem_fun1_ref_t<void, _Tp, _Arg>: public binary_function<_Tp,_Arg,void> {public:explicit mem_fun1_ref_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }private:void (_Tp::*_M_f)(_Arg);};template <class _Tp, class _Arg>class const_mem_fun1_ref_t<void, _Tp, _Arg>: public binary_function<_Tp,_Arg,void> {public:explicit const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); } private:void (_Tp::*_M_f)(_Arg) const;};#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */// Mem_fun adaptor helper functions. There are only two:// mem_fun and mem_fun_ref. (mem_fun1 and mem_fun1_ref// are provided for backward compatibility, but they are no longer// part of the C++ standard.)template <class _Ret, class _Tp>inline mem_fun_t<_Ret,_Tp> mem_fun (_Ret (_Tp::*__f)()){ return mem_fun_t<_Ret,_Tp>(__f); }template <class _Ret, class _Tp>inline const_mem_fun_t<_Ret,_Tp> mem_fun (_Ret (_Tp::*__f)() const){ return const_mem_fun_t<_Ret,_Tp>(__f); }template <class _Ret, class _Tp>inline mem_fun_ref_t<_Ret,_Tp> mem_fun_ref (_Ret (_Tp::*__f)()){ return mem_fun_ref_t<_Ret,_Tp>(__f); }template <class _Ret, class _Tp>inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref (_Ret (_Tp::*__f)() const) { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }template <class _Ret, class _Tp, class _Arg>SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 15inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun (_Ret (_Tp::*__f)(_Arg)){ return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun (_Ret (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun_ref (_Ret (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>mem_fun_ref (_Ret (_Tp::*__f)(_Arg) const){ return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg)){ return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun1_ref(_Ret (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>mem_fun1_ref(_Ret (_Tp::*__f)(_Arg) const){ return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }__STL_END_NAMESPACE#endif /* __SGI_STL_INTERNAL_FUNCTION_H */// Local Variables:// mode:C++// End:。
分享一些学习资料-大量PDF电子书
分享⼀些学习资料-⼤量PDF电⼦书分享⼀些学习⽤的电⼦书籍,给那些喜欢看书⽽不⼀定有机会买书的童鞋。
反对积分下载,提倡⾃由分享。
提取密码: np33主要包括⼏个部分的东西:1. C/C++/数据结构、算法类的,也会有⼀些计算机基础的,如《深⼊理解计算机系统》2. PHP书籍及周边。
如Apache,Nginx, mysql, HTTP,前端等。
3. Linux开发及内核相关。
4. ⾮技术类书籍。
技术之外,还是要有⽣活滴。
各书⽬明细如下:⼀、C/C++/数据结构与算法系列1. 《编程珠玑2》中⽂版及英⽂原版2. 《数据结构与算法分析 C++描述》3. 侯捷的《STL源码剖析》和《泛型编程与STL》(侯捷译)4. 程序员锻炼三部曲(单元测试之道、版本控制之道、项⽬⾃动化之道)5. 《深⼊理解计算机系统》6. 《⾼效能⼈⼠的七个习惯》7. 《计算机程序设计艺术》卷1和卷28. 《代码⼤全(第⼆版)》9. 《代码之美》中⽂版10. 《c++沉思录》11. 《c缺陷与陷阱》12. 《c语⾔⼊门经典》13. 《数据结构-c语⾔版》严蔚敏14. 《数据结构与算法分析-c描述》15. 《21天学通c语⾔》16. ⼀些c语⾔⾯试题⽬17. 《C++ Primer》18. 《C++编程艺术》19. 《c和指针》⼆、PHP书籍及周边⽂件夹中有个【前辈分享的php书籍】,包含了不少书籍。
这⾥仅列出不包含在这个⽂件夹中的:1. 《由浅⼊深探究mysql索引结构原理、性能分析与优化》,⼀个博友写的博客,可以看看2. 《深⼊理解PHP内核》不是官⽅出的,⾥边应该有些错误。
看看就⾏3. 《PHP DEBUG Manual Public》 php调试的书籍4. 《git指南》和《pro Git》 Git版本控制⼯具的书籍5. 《TCP/IP详解》3卷。
貌似应该放到⼀个单独的⽬录<⽹络编程>中,有时间再打理吧6. 《PHP5权威编程》7. 《PHP design pattern》设计模式的书8. 《Learning PHP、Mysql、JavaScript》基础书籍9. 《精通正则表达式》学习正则表达式的经典著作10. 《HTTP权威指南》的确很权威11. 《PHP应⽤性能最优化实践》12. 《⼤数据时代》待整理。
Adobe Acrobat SDK 开发者指南说明书
This guide is governed by the Adobe Acrobat SDK License Agreement and may be used or copied only in accordance with the terms of this agreement. Except as permitted by any such agreement, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe. Please note that the content in this guide is protected under copyright law.
c++ std原理
STL (Standard Template Library)是 C++ 标准库中提供泛型容器和算法的集合。
它使用模板化编程,可以创建编译时确定类型和行为的数据结构和算法。
STL 原理STL 由以下关键思想组成:•泛型编程: STL 容器和算法使用模板创建,这意味着它们可以处理不同类型的对象,而无需创建特定类型版本的容器或算法。
•容器: STL 提供各种容器,例如向量、列表、集合和映射,用于存储和组织数据。
容器提供了基于索引的访问、插入、删除和遍历等常用操作。
•迭代器: STL 使用迭代器来遍历容器。
迭代器指向容器中的元素,并提供对该元素及其邻居的访问。
•算法: STL 提供了大量的算法,用于执行常见的操作,例如排序、搜索、转换和修改容器中的数据。
算法独立于容器类型,并使用迭代器来遍历数据。
STL 组件STL 主要由以下组件组成:•容器: vector、list、deque、set、map、multiset、multimap•迭代器: input iterator、output iterator、forward iterator、bidirectional iterator、random access iterator•算法: find、sort、transform、copy•函数对象: less、greater、equal_toSTL 的优点•可重用性: STL 容器和算法是可重用的组件,可以节省开发时间和精力。
•类型安全: STL 使用模板来确保类型安全性,这意味着编译器会在编译时检查类型错误。
•效率: STL 算法针对性能进行了优化,并使用高效的数据结构。
•标准化: STL 是 C++ 标准的一部分,这意味着所有 C++ 编译器都支持它。
使用 STL 的步骤要使用 STL,请执行以下步骤:1.包含必要的头文件。
2.创建包含数据类型的容器对象。
3.使用迭代器遍历容器并执行操作。
4.使用算法对容器中的数据执行操作。
TD信息元素详解
信息元素功能性定义作者:李欣目录目录 (1)信息元素功能性定义 (11)1 核心网信息元素 (11)1.1 CN Information elements (11)1.2 CN Domain System Information (11)1.3 CN Information info (11)1.4 IMEI (11)1.5 IMSI (GSM-MAP) (11)1.6 Intra Domain NAS Node Selector (11)1.7 Location Area Identification (12)1.8 NAS message (12)1.9 NAS system information (GSM-MAP) (12)1.10 Paging record type identifier (12)1.11 PLMN identity (12)1.12 PLMN Type (12)1.13 P-TMSI (GSM-MAP) (12)1.14 RAB identity (12)1.15 Routing Area Code (12)1.16 Routing Area Identification (13)1.17 TMSI (GSM-MAP) (13)2 UTRAN 移动信息元素 (13)2.1 Cell Access Restriction (13)2.2 Cell identity (13)2.3 Cell selection and re-selection info for SIB3/4 (13)2.4 Cell selection and re-selection info for SIB11/12 (13)2.5 Mapping Info (14)2.6 URA identity (14)3 UE 信息元素 (14)3.1 Activation time (14)3.2 Capability Update Requirement (14)3.3 Cell update cause (15)3.4 Ciphering Algorithm (15)3.5 Ciphering mode info (15)3.6 CN domain specific DRX cycle length coefficient (15)3.7 CPCH Parameters (15)3.8 C-RNTI (15)3.9 DRAC system information (15)3.10 Void (16)3.11 Establishment cause (16)3.12 Expiration Time Factor (16)3.13 Failure cause (16)3.14 Failure cause and error information (16)3.15 Initial UE identity (16)3.16 Integrity check info (16)3.17 Integrity protection activation info (17)3.18 Integrity protection Algorithm (17)3.19 Integrity protection mode info (17)3.20 Maximum bit rate (17)3.21 Measurement capability (17)3.22 Paging cause (17)3.23 Paging record (17)3.24 PDCP capability (17)3.25 Physical channel capability (18)3.26 Protocol error cause (18)3.27 Protocol error indicator (18)3.28 RB timer indicator (18)3.29 Redirection info (18)3.30 Re-establishment timer (18)3.31 Rejection cause (18)3.32 Release cause (18)3.33 RF capability FDD (19)3.34 RLC capability (19)3.35 RLC re-establish indicator (19)3.36 RRC transaction identifier (19)3.37 Security capability (19)3.38 START (19)3.39 Transmission probability (19)3.40 Transport channel capability (20)3.41 UE multi-mode/multi-RAT capability (20)3.42 UE radio access capability (20)3.43 UE Timers and Constants in connected mode (21)3.44 UE Timers and Constants in idle mode (21)3.45 UE positioning capability (21)3.46 URA update cause (21)3.47 U-RNTI (21)3.48 U-RNTI Short (21)3.49 UTRAN DRX cycle length coefficient (21)3.50 Wait time (21)3.51 UE Specific Behavior Information 1 idle (21)3.52 UE Specific Behavior Information 1 interRAT (22)4 无线承载信息元素 (22)4.0 Default configuration identity (22)4.1 Downlink RLC STATUS info (22)4.2 PDCP info (22)4.3 PDCP SN info (22)4.4 Polling info (22)4.5 Predefined configuration identity (23)4.6 Predefined configuration value tag (23)4.7 Predefined RB configuration (23)4.8 RAB info (23)4.9 RAB info Post (23)4.10 RAB information for setup (23)4.11 RAB information to reconfigure (24)4.12 NAS Synchronization indicator (24)4.13 RB activation time info (24)4.14 RB COUNT-C MSB information (24)4.15 RB COUNT-C information (24)4.16 RB identity (24)4.17 RB information to be affected (24)4.18 RB information to reconfigure (25)4.19 RB information to release (25)4.20 RB information to setup (25)4.21 RB mapping info (25)4.22 RB with PDCP information (25)4.23 RLC info (25)4.24 Signaling RB information to setup (26)4.25 Transmission RLC Discard (26)5 传输信道信息元素 (26)5.1 Added or Reconfigured DL TrCH information (26)5.2 Added or Reconfigured UL TrCH information (27)5.3 CPCH set ID (27)5.4 Deleted DL TrCH information (27)5.5 Deleted UL TrCH information (27)5.6 DL Transport channel information common for all transport channels (27)5.7 DRAC Static Information (27)5.8 Power Offset Information (28)5.9 Predefined TrCH configuration (28)5.10 Quality Target (28)5.11 Semi-static Transport Format Information (28)5.12 TFCI Field 2 Information (28)5.13 TFCS Explicit Configuration (28)5.14 TFCS Information for DSCH (TFCI range method) (29)5.15 TFCS Reconfiguration/Addition Information (29)5.16 TFCS Removal Information (29)5.17 Void (29)5.18 Transport channel identity (29)5.19 Transport Format Combination (TFC) (29)5.20 Transport Format Combination Set (29)5.21 Transport Format Combination Set Identity (29)5.22 Transport Format Combination Subset (29)5.23 Transport Format Set (29)5.24 UL Transport channel information common for all transport channels (30)6 物理信道信息元素 (30)6.1 AC-to-ASC mapping (30)6.2 AICH Info (30)6.3 AICH Power offset (30)6.4 Allocation period info (30)6.5 Alpha (30)6.6 ASC Setting (30)6.7 Void (31)6.8 CCTrCH power control info (31)6.9 Cell parameters Id (31)6.10 Common timeslot info (31)6.11 Constant value (31)6.12 CPCH persistence levels (31)6.13 CPCH set info (31)6.14 CPCH Status Indication mode (31)6.15 CSICH Power offset (32)6.16 Default DPCH Offset Value (32)6.17 Downlink channelisation codes (32)6.18 Downlink DPCH info common for all RL (32)6.19 Downlink DPCH info common for all RL Post (32)6.20 Downlink DPCH info common for all RL Pre (32)6.21 Downlink DPCH info for each RL (32)6.22 Downlink DPCH info for each RL Post (33)6.23 Downlink DPCH power control information (33)6.24 Downlink information common for all radio links (33)6.25 Downlink information common for all radio links Post (33)6.26 Downlink information common for all radio links Pre (33)6.27 Downlink information for each radio link (33)6.28 Downlink information for each radio link Post (33)6.29 Void (33)6.30 Downlink PDSCH information (33)6.31 Downlink rate matching restriction information (34)6.32 Downlink Timeslots and Codes (34)6.33 DPCH compressed mode info (34)6.34 DPCH Compressed Mode Status Info (34)6.35 Dynamic persistence level (34)6.36 Frequency info (34)6.37 Individual timeslot info (35)6.38 Individual Timeslot interference (35)6.39 Maximum allowed UL TX power (35)6.40 Void (35)6.41 Midamble shift and burst type (35)6.42 PDSCH Capacity Allocation info (35)6.43 PDSCH code mapping (36)6.44 PDSCH info (36)6.45 PDSCH Power Control info (36)6.46 PDSCH system information (36)6.47 PDSCH with SHO DCH Info (36)6.48 Persistence scaling factors (36)6.49 PICH Info (36)6.50 PICH Power offset (37)6.51 PRACH Channelisation Code List (37)6.52 PRACH info (for RACH) (37)6.53 PRACH partitioning (37)6.54 PRACH power offset (37)6.55 PRACH system information list (37)6.56 Predefined PhyCH configuration (38)6.57 Primary CCPCH info (38)6.58 Primary CCPCH info post (38)6.59 Primary CCPCH TX Power (38)6.60 Primary CPICH info (38)6.61 Primary CPICH Tx power (38)6.62 Primary CPICH usage for channel estimation (38)6.63 PUSCH info (38)6.64 PUSCH Capacity Allocation info (38)6.65 PUSCH power control info (39)6.66 PUSCH system information (39)6.67 RACH transmission parameters (39)6.68 Radio link addition information (39)6.69 Radio link removal information (39)6.70 SCCPCH Information for FACH (39)6.71 Secondary CCPCH info (39)6.72 Secondary CCPCH system information (40)6.73 Secondary CPICH info (40)6.74 Secondary scrambling code (40)6.75 SFN Time info (40)6.76 SSDT cell identity (40)6.77 SSDT information (40)6.78 STTD indicator (40)6.79 TDD open loop power control (41)6.80 TFC Control duration (41)6.81 TFCI Combining Indicator (41)6.82 TGPSI (41)6.83 Time info (41)6.84 Timeslot number (41)6.85 TPC combination index (41)6.86 TSTD indicator (41)6.87 TX Diversity Mode (41)6.88 Uplink DPCH info (41)6.89 Uplink DPCH info Post (42)6.90 Uplink DPCH info Pre (42)6.91 Uplink DPCH power control info (42)6.92 Uplink DPCH power control info Post (42)6.93 Uplink DPCH power control info Pre (42)6.94 Uplink Timeslots and Codes (42)6.95 Uplink Timing Advance (42)6.96 Uplink Timing Advance Control (43)7 测量信息元素 (43)7.1 Additional measurements list (43)7.2 Cell info (43)7.3 Cell measured results (43)7.4 Cell measurement event results (44)7.5 Cell reporting quantities (44)7.6 Cell synchronization information (44)7.7 Event results (44)7.8 FACH measurement occasion info (45)7.9 Filter coefficient (45)7.10 HCS Cell re-selection information (45)7.11 HCS neighboring cell information (45)7.12 HCS Serving cell information (45)7.13 Inter-frequency cell info list (46)7.14 Inter-frequency event identity (46)7.15 Inter-frequency measured results list (46)7.16 Inter-frequency measurement (46)7.17 Inter-frequency measurement event results (47)7.18 Inter-frequency measurement quantity (47)7.19 Inter-frequency measurement reporting criteria (47)7.20 Inter-frequency measurement system information (47)7.21 Inter-frequency reporting quantity (47)7.22 Inter-frequency SET UPDATE (48)7.23 Inter-RAT cell info list (48)7.24 Inter-RAT event identity (48)7.25 Inter-RAT info (48)7.26 Inter-RAT measured results list (48)7.27 Inter-RAT measurement (49)7.28 Inter-RAT measurement event results (49)7.29 Inter-RAT measurement quantity (49)7.30 Inter-RAT measurement reporting criteria (49)7.31 Inter-RAT measurement system information (50)7.32 Inter-RAT reporting quantity (50)7.33 Intra-frequency cell info list (50)7.34 Intra-frequency event identity (50)7.35 Intra-frequency measured results list (50)7.36 Intra-frequency measurement (50)7.37 Intra-frequency measurement event results (51)7.38 Intra-frequency measurement quantity (51)7.39 Intra-frequency measurement reporting criteria (51)7.40 Intra-frequency measurement system information (51)7.41 Intra-frequency reporting quantity (52)7.42 Intra-frequency reporting quantity for RACH reporting (52)7.43 Maximum number of reported cells on RACH (52)7.44 Measured results (52)7.45 Measured results on RACH (52)7.46 Measurement Command (52)7.47 Measurement control system information (53)7.48 Measurement Identity (53)7.49 Measurement reporting mode (53)7.50 Measurement Type (53)7.51 Measurement validity (53)7.52 Observed time difference to GSM cell (53)7.53 Periodical reporting criteria (53)7.54 Primary CCPCH RSCP info (54)7.55 Quality measured results list (54)7.56 Quality measurement (54)7.57 Quality measurement event results (54)7.58 Quality measurement reporting criteria (54)7.59 Quality reporting quantity (54)7.60 Reference time difference to cell (54)7.61 Reporting Cell Status (55)7.62 Reporting information for state CELL_DCH (55)7.63 SFN-SFN observed time difference (55)7.64 Time to trigger (55)7.65 Timeslot ISCP info (55)7.66 Traffic volume event identity (55)7.67 Traffic volume measured results list (55)7.68 Traffic volume measurement (55)7.69 Traffic volume measurement event results (56)7.70 Traffic volume measurement object (56)7.71 Traffic volume measurement quantity (56)7.72 Traffic volume measurement reporting criteria (56)7.73 Traffic volume measurement system information (56)7.74 Traffic volume reporting quantity (56)7.75 UE internal event identity (56)7.76 UE internal measured results (57)7.77 UE internal measurement (57)7.78 UE internal measurement event results (57)7.79 UE internal measurement quantity (57)7.80 UE internal measurement reporting criteria (57)7.81 Void (58)7.82 UE Internal reporting quantity (58)7.83 UE Rx-Tx time difference type 1 (58)7.84 UE Rx-Tx time difference type 2 (58)7.85 UE Transmitted Power info (58)7.86 UE positioning Ciphering info (58)7.87 UE positioning Error (58)7.88 UE positioning GPS acquisition assistance (59)7.89 UE positioning GPS almanac (59)7.90 UE positioning GPS assistance data (59)7.91 UE positioning GPS DGPS corrections (59)7.92 UE positioning GPS ionospheric model (59)7.93 UE positioning GPS measured results (59)7.94 UE positioning GPS navigation model (60)7.95 UE positioning GPS real-time integrity (60)7.96 UE positioning GPS reference time (60)7.97 UE positioning GPS UTC model (61)7.98 UE positioning IPDL parameters (61)7.99 UE positioning measured results (61)7.100 UE positioning measurement (61)7.101 UE positioning measurement event results (61)7.102 Void (62)7.103 UE positioning OTDOA assistance data for UE-assisted (62)7.104 Void (62)7.105 UE positioning OTDOA measured results (62)7.106 UE positioning OTDOA neighbor cell info (62)7.107 UE positioning OTDOA quality (63)7.108 UE positioning OTDOA reference cell info (63)7.109 UE positioning position estimate info (64)7.110 UE positioning reporting criteria (64)7.111 UE positioning reporting quantity (64)7.112 T ADV info (65)8 其它信息元素 (65)8.1 BCCH modification info (65)8.2 BSIC (65)8.3 CBS DRX Level 1 information (65)8.4 Cell Value tag (65)8.5 Inter-RAT change failure (65)8.6 Inter-RAT handover failure (66)8.7 Inter-RAT UE radio access capability (66)8.8 Void (66)8.9 MIB Value tag (66)8.10 PLMN Value tag (66)8.11 Predefined configuration identity and value tag (66)8.12 Protocol error information (66)8.13 References to other system information blocks (66)8.14 References to other system information blocks and scheduling blocks (67)8.15 Rplmn information (67)8.16 Scheduling information (67)8.17 SEG COUNT (67)8.18 Segment index (67)8.19 SIB data fixed (67)8.20 SIB data variable (67)8.21 SIB type (67)8.22 SIB type SIBs only (67)9 ANSI-41 Information elements (68)10 Multiplicity values and type constraint values (68)信息元素功能性定义消息是由多个信息元素组合而成,信息元素根据其功能的不同划分为:核心网域信息元素、UTRAN 移动信息元素、UE 信息元素、无线承载信息元素、传输信道信息元素、物理信道信息元素和测量信息元素。
侯捷stl源码剖析注释之33 sgi-stl-list
The Annotated STL Sources
2
<stl_list.h> 完整列表
}; // 串列專屬迭代器。既然撰寫串列迭代器避免不了要曝露串列的實作細節, // 那麼就讓串列和串列迭代器一起設計好了。 template<class T, class Ref, class Ptr> struct __list_iterator { // 未繼承 std::iterator typedef __list_iterator<T, T&, T*> iterator; typedef __list_iterator<T, const T&, const T*> const_iterator; typedef __list_iterator<T, Ref, Ptr> self; // 未繼承 std::iterator,所以必須自行撰寫五個必要的迭代器相應型別 typedef bidirectional_iterator_tag iterator_category; // (1) typedef T value_type; // (2) typedef Ptr pointer; // (3) typedef Ref reference; // (4) typedef __list_node<T>* link_type; typedef size_t size_type; typedef ptrdiff_t difference_type; // (5) link_type node; // 保持與容器的聯結
// 關鍵
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION // 編譯器不支援 partial specialization 時,才需以下定義 template <class T, class Ref, class Ptr> inline bidirectional_iterator_tag iterator_category(const __list_iterator<T, Ref, Ptr>&) { return bidirectional_iterator_tag(); } template <class T, class Ref, class Ptr> inline T* value_type(const __list_iterator<T, Ref, Ptr>&) { return 0; } template <class T, class Ref, class Ptr> inline ptrdiff_t* distance_type(const __list_iterator<T, Ref, Ptr>&) { return 0; } // 編譯器不支援 partial specialization 時,才需以上定義 #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */ template <class T, class Alloc = alloc > // 預設使用 alloc 為配置器 class list { protected: typedef void* void_pointer; typedef __list_node<T> list_node ; // 專屬之空間配置器,每次配置一個節點大小 typedef simple_alloc<list_node, Alloc> list_node_allocator; public: typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; typedef list_node* link_type; typedef size_t size_type; typedef ptrdiff_t difference_type;
侯捷STL课程及源码剖析学习1
侯捷STL课程及源码剖析学习11.C++标准库和STL C++标准库以header files形式呈现:1. C++标准库的header files不带后缀名(.h),例如#include <vector>2. 新式C header files 不带后缀名.h,例如#include<cstdio>3. 旧式C header files (带有后缀名.h)仍然可⽤,例如#include <stdio.h>4. 新式headers内的组件封装于namespace “std”。
using namespace std;或者以 using std::cout;的形式5. 旧式headers 内的组件不封装于namespace "std" 在标准库中,标准模板库STL(Standard Template Library),占据了标准库70%,80%以上的内容。
C++ 标准库的范围⼤于STL的范围。
STL的核⼼思想是泛型编程(Generic Programming)。
重要资源:⽹站:书籍:The C++ standard Library second edition;STL 源码剖析2.STL 六⼤组件STL分为六⼤组件:容器(container):常⽤数据结构,⼤致分为两类,序列容器,如vector,list,deque,关联容器,如set,map。
在实现上,是类模板(class template)迭代器(iterator):⼀套访问容器的接⼝,⾏为类似于指针。
它为不同算法提供的相对统⼀的容器访问⽅式,使得设计算法时⽆需关注过多关注数据。
(“算法”指⼴义的算法,操作数据的逻辑代码都可认为是算法)算法(algorithm):提供⼀套常⽤的算法,如sort,search,copy,erase … 在实现上,可以认为是⼀种函数模板(function template)。
侯捷-C++ 内存管理与优化高级培训
培训纲要
第 1 阶段:CRT (C Runtime) malloc 深度剖析 讓學員充份了解 Microsoft C++ 對 malloc 的作法(非常複雜精巧) ; 除學習其中技術, 也足以評估自行加上各種 allocators 是必要還是多 餘。 第 2 阶段:C++内存管理相关操作深入剖析,应用开发技巧、实践与模式 new expression vs. operator new delete expression vs. operator delete array new and array delete placement new about overhead examples for operator new/delete overloading 第 3 阶段: STL 程序库内存管理设施深入剖析,应用开发技巧、实践与模式 std::auto_ptr boost::shared_ptr How to inherit operator new/delete Introduction to std::allocator
第 3 页 共 3 页
培训简介
Memory management 一向是 C++ programmer 的痛点,主要因为 C++ 不提供 Garbage Collection。这是效能顾虑下的一种取舍。现实如此,我们必须追求在如此的现 实下如何又快又好地运用 memory,使符合速度和空间的最大利益。本课程在低阶上全 面介绍 C++ 提供的各种 memory 管理工具(各种 overloadable operators) ,在高阶上 深刻学习各大链接库(包括 STL, Loki, MFC, Boost)的 Pooled Allocation 的作法,并 提供它们的高度可移植版(侯捷改编) ,同时提供各种效率优化技巧实践、与模式。
ACM-GIS%202006-A%20Peer-to-Peer%20Spatial%20Cloaking%20Algorithm%20for%20Anonymous%20Location-based%
A Peer-to-Peer Spatial Cloaking Algorithm for AnonymousLocation-based Services∗Chi-Yin Chow Department of Computer Science and Engineering University of Minnesota Minneapolis,MN cchow@ Mohamed F.MokbelDepartment of ComputerScience and EngineeringUniversity of MinnesotaMinneapolis,MNmokbel@Xuan LiuIBM Thomas J.WatsonResearch CenterHawthorne,NYxuanliu@ABSTRACTThis paper tackles a major privacy threat in current location-based services where users have to report their ex-act locations to the database server in order to obtain their desired services.For example,a mobile user asking about her nearest restaurant has to report her exact location.With untrusted service providers,reporting private location in-formation may lead to several privacy threats.In this pa-per,we present a peer-to-peer(P2P)spatial cloaking algo-rithm in which mobile and stationary users can entertain location-based services without revealing their exact loca-tion information.The main idea is that before requesting any location-based service,the mobile user will form a group from her peers via single-hop communication and/or multi-hop routing.Then,the spatial cloaked area is computed as the region that covers the entire group of peers.Two modes of operations are supported within the proposed P2P spa-tial cloaking algorithm,namely,the on-demand mode and the proactive mode.Experimental results show that the P2P spatial cloaking algorithm operated in the on-demand mode has lower communication cost and better quality of services than the proactive mode,but the on-demand incurs longer response time.Categories and Subject Descriptors:H.2.8[Database Applications]:Spatial databases and GISGeneral Terms:Algorithms and Experimentation. Keywords:Mobile computing,location-based services,lo-cation privacy and spatial cloaking.1.INTRODUCTIONThe emergence of state-of-the-art location-detection de-vices,e.g.,cellular phones,global positioning system(GPS) devices,and radio-frequency identification(RFID)chips re-sults in a location-dependent information access paradigm,∗This work is supported in part by the Grants-in-Aid of Re-search,Artistry,and Scholarship,University of Minnesota. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on thefirst page.To copy otherwise,to republish,to post on servers or to redistribute to lists,requires prior specific permission and/or a fee.ACM-GIS’06,November10-11,2006,Arlington,Virginia,USA. Copyright2006ACM1-59593-529-0/06/0011...$5.00.known as location-based services(LBS)[30].In LBS,mobile users have the ability to issue location-based queries to the location-based database server.Examples of such queries include“where is my nearest gas station”,“what are the restaurants within one mile of my location”,and“what is the traffic condition within ten minutes of my route”.To get the precise answer of these queries,the user has to pro-vide her exact location information to the database server. With untrustworthy servers,adversaries may access sensi-tive information about specific individuals based on their location information and issued queries.For example,an adversary may check a user’s habit and interest by knowing the places she visits and the time of each visit,or someone can track the locations of his ex-friends.In fact,in many cases,GPS devices have been used in stalking personal lo-cations[12,39].To tackle this major privacy concern,three centralized privacy-preserving frameworks are proposed for LBS[13,14,31],in which a trusted third party is used as a middleware to blur user locations into spatial regions to achieve k-anonymity,i.e.,a user is indistinguishable among other k−1users.The centralized privacy-preserving frame-work possesses the following shortcomings:1)The central-ized trusted third party could be the system bottleneck or single point of failure.2)Since the centralized third party has the complete knowledge of the location information and queries of all users,it may pose a serious privacy threat when the third party is attacked by adversaries.In this paper,we propose a peer-to-peer(P2P)spatial cloaking algorithm.Mobile users adopting the P2P spatial cloaking algorithm can protect their privacy without seeking help from any centralized third party.Other than the short-comings of the centralized approach,our work is also moti-vated by the following facts:1)The computation power and storage capacity of most mobile devices have been improv-ing at a fast pace.2)P2P communication technologies,such as IEEE802.11and Bluetooth,have been widely deployed.3)Many new applications based on P2P information shar-ing have rapidly taken shape,e.g.,cooperative information access[9,32]and P2P spatio-temporal query processing[20, 24].Figure1gives an illustrative example of P2P spatial cloak-ing.The mobile user A wants tofind her nearest gas station while beingfive anonymous,i.e.,the user is indistinguish-able amongfive users.Thus,the mobile user A has to look around andfind other four peers to collaborate as a group. In this example,the four peers are B,C,D,and E.Then, the mobile user A cloaks her exact location into a spatialA B CDEBase Stationregion that covers the entire group of mobile users A ,B ,C ,D ,and E .The mobile user A randomly selects one of the mobile users within the group as an agent .In the ex-ample given in Figure 1,the mobile user D is selected as an agent.Then,the mobile user A sends her query (i.e.,what is the nearest gas station)along with her cloaked spa-tial region to the agent.The agent forwards the query to the location-based database server through a base station.Since the location-based database server processes the query based on the cloaked spatial region,it can only give a list of candidate answers that includes the actual answers and some false positives.After the agent receives the candidate answers,it forwards the candidate answers to the mobile user A .Finally,the mobile user A gets the actual answer by filtering out all the false positives.The proposed P2P spatial cloaking algorithm can operate in two modes:on-demand and proactive .In the on-demand mode,mobile clients execute the cloaking algorithm when they need to access information from the location-based database server.On the other side,in the proactive mode,mobile clients periodically look around to find the desired number of peers.Thus,they can cloak their exact locations into spatial regions whenever they want to retrieve informa-tion from the location-based database server.In general,the contributions of this paper can be summarized as follows:1.We introduce a distributed system architecture for pro-viding anonymous location-based services (LBS)for mobile users.2.We propose the first P2P spatial cloaking algorithm for mobile users to entertain high quality location-based services without compromising their privacy.3.We provide experimental evidence that our proposed algorithm is efficient in terms of the response time,is scalable to large numbers of mobile clients,and is effective as it provides high-quality services for mobile clients without the need of exact location information.The rest of this paper is organized as follows.Section 2highlights the related work.The system model of the P2P spatial cloaking algorithm is presented in Section 3.The P2P spatial cloaking algorithm is described in Section 4.Section 5discusses the integration of the P2P spatial cloak-ing algorithm with privacy-aware location-based database servers.Section 6depicts the experimental evaluation of the P2P spatial cloaking algorithm.Finally,Section 7con-cludes this paper.2.RELATED WORKThe k -anonymity model [37,38]has been widely used in maintaining privacy in databases [5,26,27,28].The main idea is to have each tuple in the table as k -anonymous,i.e.,indistinguishable among other k −1tuples.Although we aim for the similar k -anonymity model for the P2P spatial cloaking algorithm,none of these techniques can be applied to protect user privacy for LBS,mainly for the following four reasons:1)These techniques preserve the privacy of the stored data.In our model,we aim not to store the data at all.Instead,we store perturbed versions of the data.Thus,data privacy is managed before storing the data.2)These approaches protect the data not the queries.In anonymous LBS,we aim to protect the user who issues the query to the location-based database server.For example,a mobile user who wants to ask about her nearest gas station needs to pro-tect her location while the location information of the gas station is not protected.3)These approaches guarantee the k -anonymity for a snapshot of the database.In LBS,the user location is continuously changing.Such dynamic be-havior calls for continuous maintenance of the k -anonymity model.(4)These approaches assume a unified k -anonymity requirement for all the stored records.In our P2P spatial cloaking algorithm,k -anonymity is a user-specified privacy requirement which may have a different value for each user.Motivated by the privacy threats of location-detection de-vices [1,4,6,40],several research efforts are dedicated to protect the locations of mobile users (e.g.,false dummies [23],landmark objects [18],and location perturbation [10,13,14]).The most closed approaches to ours are two centralized spatial cloaking algorithms,namely,the spatio-temporal cloaking [14]and the CliqueCloak algorithm [13],and one decentralized privacy-preserving algorithm [23].The spatio-temporal cloaking algorithm [14]assumes that all users have the same k -anonymity requirements.Furthermore,it lacks the scalability because it deals with each single request of each user individually.The CliqueCloak algorithm [13]as-sumes a different k -anonymity requirement for each user.However,since it has large computation overhead,it is lim-ited to a small k -anonymity requirement,i.e.,k is from 5to 10.A decentralized privacy-preserving algorithm is proposed for LBS [23].The main idea is that the mobile client sends a set of false locations,called dummies ,along with its true location to the location-based database server.However,the disadvantages of using dummies are threefold.First,the user has to generate realistic dummies to pre-vent the adversary from guessing its true location.Second,the location-based database server wastes a lot of resources to process the dummies.Finally,the adversary may esti-mate the user location by using cellular positioning tech-niques [34],e.g.,the time-of-arrival (TOA),the time differ-ence of arrival (TDOA)and the direction of arrival (DOA).Although several existing distributed group formation al-gorithms can be used to find peers in a mobile environment,they are not designed for privacy preserving in LBS.Some algorithms are limited to only finding the neighboring peers,e.g.,lowest-ID [11],largest-connectivity (degree)[33]and mobility-based clustering algorithms [2,25].When a mo-bile user with a strict privacy requirement,i.e.,the value of k −1is larger than the number of neighboring peers,it has to enlist other peers for help via multi-hop routing.Other algorithms do not have this limitation,but they are designed for grouping stable mobile clients together to facil-Location-based Database ServerDatabase ServerDatabase ServerFigure 2:The system architectureitate efficient data replica allocation,e.g.,dynamic connec-tivity based group algorithm [16]and mobility-based clus-tering algorithm,called DRAM [19].Our work is different from these approaches in that we propose a P2P spatial cloaking algorithm that is dedicated for mobile users to dis-cover other k −1peers via single-hop communication and/or via multi-hop routing,in order to preserve user privacy in LBS.3.SYSTEM MODELFigure 2depicts the system architecture for the pro-posed P2P spatial cloaking algorithm which contains two main components:mobile clients and location-based data-base server .Each mobile client has its own privacy profile that specifies its desired level of privacy.A privacy profile includes two parameters,k and A min ,k indicates that the user wants to be k -anonymous,i.e.,indistinguishable among k users,while A min specifies the minimum resolution of the cloaked spatial region.The larger the value of k and A min ,the more strict privacy requirements a user needs.Mobile users have the ability to change their privacy profile at any time.Our employed privacy profile matches the privacy re-quirements of mobiles users as depicted by several social science studies (e.g.,see [4,15,17,22,29]).In this architecture,each mobile user is equipped with two wireless network interface cards;one of them is dedicated to communicate with the location-based database server through the base station,while the other one is devoted to the communication with other peers.A similar multi-interface technique has been used to implement IP multi-homing for stream control transmission protocol (SCTP),in which a machine is installed with multiple network in-terface cards,and each assigned a different IP address [36].Similarly,in mobile P2P cooperation environment,mobile users have a network connection to access information from the server,e.g.,through a wireless modem or a base station,and the mobile users also have the ability to communicate with other peers via a wireless LAN,e.g.,IEEE 802.11or Bluetooth [9,24,32].Furthermore,each mobile client is equipped with a positioning device, e.g.,GPS or sensor-based local positioning systems,to determine its current lo-cation information.4.P2P SPATIAL CLOAKINGIn this section,we present the data structure and the P2P spatial cloaking algorithm.Then,we describe two operation modes of the algorithm:on-demand and proactive .4.1Data StructureThe entire system area is divided into grid.The mobile client communicates with each other to discover other k −1peers,in order to achieve the k -anonymity requirement.TheAlgorithm 1P2P Spatial Cloaking:Request Originator m 1:Function P2PCloaking-Originator (h ,k )2://Phase 1:Peer searching phase 3:The hop distance h is set to h4:The set of discovered peers T is set to {∅},and the number ofdiscovered peers k =|T |=05:while k <k −1do6:Broadcast a FORM GROUP request with the parameter h (Al-gorithm 2gives the response of each peer p that receives this request)7:T is the set of peers that respond back to m by executingAlgorithm 28:k =|T |;9:if k <k −1then 10:if T =T then 11:Suspend the request 12:end if 13:h ←h +1;14:T ←T ;15:end if 16:end while17://Phase 2:Location adjustment phase 18:for all T i ∈T do19:|mT i .p |←the greatest possible distance between m and T i .pby considering the timestamp of T i .p ’s reply and maximum speed20:end for21://Phase 3:Spatial cloaking phase22:Form a group with k −1peers having the smallest |mp |23:h ←the largest hop distance h p of the selected k −1peers 24:Determine a grid area A that covers the entire group 25:if A <A min then26:Extend the area of A till it covers A min 27:end if28:Randomly select a mobile client of the group as an agent 29:Forward the query and A to the agentmobile client can thus blur its exact location into a cloaked spatial region that is the minimum grid area covering the k −1peers and itself,and satisfies A min as well.The grid area is represented by the ID of the left-bottom and right-top cells,i.e.,(l,b )and (r,t ).In addition,each mobile client maintains a parameter h that is the required hop distance of the last peer searching.The initial value of h is equal to one.4.2AlgorithmFigure 3gives a running example for the P2P spatial cloaking algorithm.There are 15mobile clients,m 1to m 15,represented as solid circles.m 8is the request originator,other black circles represent the mobile clients received the request from m 8.The dotted circles represent the commu-nication range of the mobile client,and the arrow represents the movement direction.Algorithms 1and 2give the pseudo code for the request originator (denoted as m )and the re-quest receivers (denoted as p ),respectively.In general,the algorithm consists of the following three phases:Phase 1:Peer searching phase .The request origina-tor m wants to retrieve information from the location-based database server.m first sets h to h ,a set of discovered peers T to {∅}and the number of discovered peers k to zero,i.e.,|T |.(Lines 3to 4in Algorithm 1).Then,m broadcasts a FORM GROUP request along with a message sequence ID and the hop distance h to its neighboring peers (Line 6in Algorithm 1).m listens to the network and waits for the reply from its neighboring peers.Algorithm 2describes how a peer p responds to the FORM GROUP request along with a hop distance h and aFigure3:P2P spatial cloaking algorithm.Algorithm2P2P Spatial Cloaking:Request Receiver p1:Function P2PCloaking-Receiver(h)2://Let r be the request forwarder3:if the request is duplicate then4:Reply r with an ACK message5:return;6:end if7:h p←1;8:if h=1then9:Send the tuple T=<p,(x p,y p),v maxp ,t p,h p>to r10:else11:h←h−1;12:Broadcast a FORM GROUP request with the parameter h 13:T p is the set of peers that respond back to p14:for all T i∈T p do15:T i.h p←T i.h p+1;16:end for17:T p←T p∪{<p,(x p,y p),v maxp ,t p,h p>};18:Send T p back to r19:end ifmessage sequence ID from another peer(denoted as r)that is either the request originator or the forwarder of the re-quest.First,p checks if it is a duplicate request based on the message sequence ID.If it is a duplicate request,it sim-ply replies r with an ACK message without processing the request.Otherwise,p processes the request based on the value of h:Case1:h= 1.p turns in a tuple that contains its ID,current location,maximum movement speed,a timestamp and a hop distance(it is set to one),i.e.,< p,(x p,y p),v max p,t p,h p>,to r(Line9in Algorithm2). Case2:h> 1.p decrements h and broadcasts the FORM GROUP request with the updated h and the origi-nal message sequence ID to its neighboring peers.p keeps listening to the network,until it collects the replies from all its neighboring peers.After that,p increments the h p of each collected tuple,and then it appends its own tuple to the collected tuples T p.Finally,it sends T p back to r (Lines11to18in Algorithm2).After m collects the tuples T from its neighboring peers, if m cannotfind other k−1peers with a hop distance of h,it increments h and re-broadcasts the FORM GROUP request along with a new message sequence ID and h.m repeatedly increments h till itfinds other k−1peers(Lines6to14in Algorithm1).However,if mfinds the same set of peers in two consecutive broadcasts,i.e.,with hop distances h and h+1,there are not enough connected peers for m.Thus, m has to relax its privacy profile,i.e.,use a smaller value of k,or to be suspended for a period of time(Line11in Algorithm1).Figures3(a)and3(b)depict single-hop and multi-hop peer searching in our running example,respectively.In Fig-ure3(a),the request originator,m8,(e.g.,k=5)canfind k−1peers via single-hop communication,so m8sets h=1. Since h=1,its neighboring peers,m5,m6,m7,m9,m10, and m11,will not further broadcast the FORM GROUP re-quest.On the other hand,in Figure3(b),m8does not connect to k−1peers directly,so it has to set h>1.Thus, its neighboring peers,m7,m10,and m11,will broadcast the FORM GROUP request along with a decremented hop dis-tance,i.e.,h=h−1,and the original message sequence ID to their neighboring peers.Phase2:Location adjustment phase.Since the peer keeps moving,we have to capture the movement between the time when the peer sends its tuple and the current time. For each received tuple from a peer p,the request originator, m,determines the greatest possible distance between them by an equation,|mp |=|mp|+(t c−t p)×v max p,where |mp|is the Euclidean distance between m and p at time t p,i.e.,|mp|=(x m−x p)2+(y m−y p)2,t c is the currenttime,t p is the timestamp of the tuple and v maxpis the maximum speed of p(Lines18to20in Algorithm1).In this paper,a conservative approach is used to determine the distance,because we assume that the peer will move with the maximum speed in any direction.If p gives its movement direction,m has the ability to determine a more precise distance between them.Figure3(c)illustrates that,for each discovered peer,the circle represents the largest region where the peer can lo-cate at time t c.The greatest possible distance between the request originator m8and its discovered peer,m5,m6,m7, m9,m10,or m11is represented by a dotted line.For exam-ple,the distance of the line m8m 11is the greatest possible distance between m8and m11at time t c,i.e.,|m8m 11|. Phase3:Spatial cloaking phase.In this phase,the request originator,m,forms a virtual group with the k−1 nearest peers,based on the greatest possible distance be-tween them(Line22in Algorithm1).To adapt to the dynamic network topology and k-anonymity requirement, m sets h to the largest value of h p of the selected k−1 peers(Line15in Algorithm1).Then,m determines the minimum grid area A covering the entire group(Line24in Algorithm1).If the area of A is less than A min,m extends A,until it satisfies A min(Lines25to27in Algorithm1). Figure3(c)gives the k−1nearest peers,m6,m7,m10,and m11to the request originator,m8.For example,the privacy profile of m8is(k=5,A min=20cells),and the required cloaked spatial region of m8is represented by a bold rectan-gle,as depicted in Figure3(d).To issue the query to the location-based database server anonymously,m randomly selects a mobile client in the group as an agent(Line28in Algorithm1).Then,m sendsthe query along with the cloaked spatial region,i.e.,A,to the agent(Line29in Algorithm1).The agent forwards thequery to the location-based database server.After the serverprocesses the query with respect to the cloaked spatial re-gion,it sends a list of candidate answers back to the agent.The agent forwards the candidate answer to m,and then mfilters out the false positives from the candidate answers. 4.3Modes of OperationsThe P2P spatial cloaking algorithm can operate in twomodes,on-demand and proactive.The on-demand mode:The mobile client only executesthe algorithm when it needs to retrieve information from the location-based database server.The algorithm operatedin the on-demand mode generally incurs less communica-tion overhead than the proactive mode,because the mobileclient only executes the algorithm when necessary.However,it suffers from a longer response time than the algorithm op-erated in the proactive mode.The proactive mode:The mobile client adopting theproactive mode periodically executes the algorithm in back-ground.The mobile client can cloak its location into a spa-tial region immediately,once it wants to communicate withthe location-based database server.The proactive mode pro-vides a better response time than the on-demand mode,but it generally incurs higher communication overhead and giveslower quality of service than the on-demand mode.5.ANONYMOUS LOCATION-BASEDSERVICESHaving the spatial cloaked region as an output form Algo-rithm1,the mobile user m sends her request to the location-based server through an agent p that is randomly selected.Existing location-based database servers can support onlyexact point locations rather than cloaked regions.In or-der to be able to work with a spatial region,location-basedservers need to be equipped with a privacy-aware queryprocessor(e.g.,see[29,31]).The main idea of the privacy-aware query processor is to return a list of candidate answerrather than the exact query answer.Then,the mobile user m willfilter the candidate list to eliminate its false positives andfind its exact answer.The tighter the spatial cloaked re-gion,the lower is the size of the candidate answer,and hencethe better is the performance of the privacy-aware query processor.However,tight cloaked regions may represent re-laxed privacy constrained.Thus,a trade-offbetween the user privacy and the quality of service can be achieved[31]. Figure4(a)depicts such scenario by showing the data stored at the server side.There are32target objects,i.e., gas stations,T1to T32represented as black circles,the shaded area represents the spatial cloaked area of the mo-bile client who issued the query.For clarification,the actual mobile client location is plotted in Figure4(a)as a black square inside the cloaked area.However,such information is neither stored at the server side nor revealed to the server. The privacy-aware query processor determines a range that includes all target objects that are possibly contributing to the answer given that the actual location of the mobile client could be anywhere within the shaded area.The range is rep-resented as a bold rectangle,as depicted in Figure4(b).The server sends a list of candidate answers,i.e.,T8,T12,T13, T16,T17,T21,and T22,back to the agent.The agent next for-(a)Server Side(b)Client SideFigure4:Anonymous location-based services wards the candidate answers to the requesting mobile client either through single-hop communication or through multi-hop routing.Finally,the mobile client can get the actualanswer,i.e.,T13,byfiltering out the false positives from thecandidate answers.The algorithmic details of the privacy-aware query proces-sor is beyond the scope of this paper.Interested readers are referred to[31]for more details.6.EXPERIMENTAL RESULTSIn this section,we evaluate and compare the scalabilityand efficiency of the P2P spatial cloaking algorithm in boththe on-demand and proactive modes with respect to the av-erage response time per query,the average number of mes-sages per query,and the size of the returned candidate an-swers from the location-based database server.The queryresponse time in the on-demand mode is defined as the timeelapsed between a mobile client starting to search k−1peersand receiving the candidate answers from the agent.On theother hand,the query response time in the proactive mode is defined as the time elapsed between a mobile client startingto forward its query along with the cloaked spatial regionto the agent and receiving the candidate answers from theagent.The simulation model is implemented in C++usingCSIM[35].In all the experiments in this section,we consider an in-dividual random walk model that is based on“random way-point”model[7,8].At the beginning,the mobile clientsare randomly distributed in a spatial space of1,000×1,000square meters,in which a uniform grid structure of100×100cells is constructed.Each mobile client randomly chooses itsown destination in the space with a randomly determined speed s from a uniform distribution U(v min,v max).When the mobile client reaches the destination,it comes to a stand-still for one second to determine its next destination.Afterthat,the mobile client moves towards its new destinationwith another speed.All the mobile clients repeat this move-ment behavior during the simulation.The time interval be-tween two consecutive queries generated by a mobile client follows an exponential distribution with a mean of ten sec-onds.All the experiments consider one half-duplex wirelesschannel for a mobile client to communicate with its peers with a total bandwidth of2Mbps and a transmission range of250meters.When a mobile client wants to communicate with other peers or the location-based database server,it has to wait if the requested channel is busy.In the simulated mobile environment,there is a centralized location-based database server,and one wireless communication channel between the location-based database server and the mobile。
C++11shared_ptr与make_shared源码剖析详解
C++11shared_ptr与make_shared源码剖析详解⽬录0. 前⾔1. 源码分析1.1 头⽂件1.2 构造1.2.1 shared_ptr 的移动构造函数1.2.2 shared_ptr 的拷贝构造函数1.3 赋值重载1.4 修改的接⼝1.5 获取2. make_shared2.1 make_shared 优点2.1.1 效率⾼2.1.2 异常安全2.2 make_shared缺点3. 举例参考:总结0. 前⾔所谓智能指针,可以从字⾯上理解为“智能”的指针。
具体来讲,智能指针和普通指针的⽤法是相似的,不同之处在于,智能指针可以在适当时机⾃动释放分配的内存。
也就是说,使⽤智能指针可以很好地避免“忘记释放内存⽽导致内存泄漏”问题出现。
由此可见,C++ 也逐渐开始⽀持垃圾回收机制了,尽管⽬前⽀持程度还有限。
c++11 中发布了shared_ptr、unique_ptr、weak_ptr⽤以资源的管理,都是定义在memory 这个头⽂件中。
std::shared_ptr允许多个shared_ptr 实例指向同⼀个对象,通过计数管理;std::unique_ptr是独占对象;weak_ptr是辅助类,是⼀种弱引⽤,指向shared_ptr 所管理的对象。
1. 源码分析1.1 头⽂件#include <memory>1.2 构造constexpr shared_ptr() noexcept;template<class Y> explicit shared_ptr(Y* p);template<class Y, class D> shared_ptr(Y* p, D d);template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);template <class D> shared_ptr(nullptr_t p, D d);template <class D, class A> shared_ptr(nullptr_t p, D d, A a);template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;shared_ptr(const shared_ptr& r) noexcept;template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;shared_ptr(shared_ptr&& r) noexcept;template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);shared_ptr(nullptr_t) : shared_ptr() { }构造函数⽐较多啊,抽⼀个看看源码。
STL源码 侯捷注释
STL源码侯捷注释《STL源码侯捷注释》是一本经典的程序员必备书籍,它为广大程序员提供了深入了解STL源码的机会。
本文将从以下几个方面进行分析和评价。
一、作者介绍侯捷是一位著名的程序员和作家,他曾获得多项国际和国内大奖,包括ACM国际程序设计竞赛金牌、IBM杰出软件奖、国家自然科学二等奖等。
他还是多本计算机书籍的作者,如《STL源码剖析》、《C++程序设计》等。
二、书籍概述《STL源码侯捷注释》是一本详细介绍STL源码的书籍,它对STL的各个组成部分进行了详细的解析和注释。
本书的主要特点包括:1.详细的注释:本书对STL源码的每个细节都进行了详细的解释和注释,使读者能够深入了解STL的实现原理。
2.清晰的结构:本书按照STL源码的结构进行组织,并提供了详细的目录和索引,方便读者查找和理解。
3.丰富的例子:本书提供了大量的例子,帮助读者更好地理解STL的使用方法和实现原理。
4.全面的覆盖:本书覆盖了STL的所有组成部分,包括容器、迭代器、算法、仿函数等。
三、书籍优点1.深入浅出:本书的注释和解释非常详细,但又不失深入浅出的风格,使读者能够轻松理解STL的实现原理。
2.丰富的例子:本书提供了大量的例子,使读者能够更好地理解STL的使用方法和实现原理。
3.清晰的结构:本书按照STL源码的结构进行组织,并提供了详细的目录和索引,方便读者查找和理解。
4.全面的覆盖:本书覆盖了STL的所有组成部分,包括容器、迭代器、算法、仿函数等。
四、书籍不足之处1.过于复杂:本书注释和解释的内容非常详细,但有时候可能会让读者感到过于复杂和深入,不太适合初学者。
2.缺少实战案例:本书提供了大量的例子,但是缺少实战案例,读者可能需要自己去实践。
五、适合读者群体《STL源码侯捷注释》适合以下读者群体:1.对STL源码有兴趣的程序员。
2.希望深入了解STL实现原理的程序员。
3.希望提高自己的STL编程能力的程序员。
4.想要更好地掌握C++语言和STL的程序员。
Rust语言程序设计形考任务十一源码截图
Rust语言程序设计形考任务十一源码截
图
任务概述
本任务要求同学们运用Rust语言完成一个程序设计,并进行源码截图。
目的是检验同学们对Rust语言的掌握程度,以及能否将所学知识应用于实际编程中。
任务要求
1. 请使用Rust编写一个程序,实现一个简单的命令行工具。
2. 程序需要具备以下功能:
- 接收一个参数,表示要操作的文件路径。
- 根据文件路径,判断文件是否存在,并输出相应信息。
- 如果文件存在,输出文件内容。
3. 请确保程序能够正确处理各种异常情况,例如文件不存在、文件无法打开等。
4. 完成程序编写后,请将源码截图保存为.png格式,并提交截图。
评分标准
- 程序是否能正确接收参数:20分
- 程序是否能正确判断文件是否存在:20分
- 程序是否能正确输出文件内容:20分
- 程序是否能正确处理异常情况:20分
- 源码截图质量:10分
提交要求
1. 请将源码截图保存为.png格式。
2. 请确保截图清晰,文字可辨。
3. 请在截图中包含以下信息:
- 程序名称
- 截图时间
- 屏幕分辨率
4. 请将截图命名为“任务十一源码截图.png”,并提交至指定位置。
提示
- 在编写程序时,可以使用Rust的`std::path::Path`和`std::fs`模块来处理文件路径和文件操作。
- 在处理异常情况时,可以使用Rust的`Result`类型来返回可能的错误。
祝大家编程顺利!。
SGISTL源码stl_vector.h分析
SGISTL源码stl_vector.h分析前⾔vector 是最常⽤的 C++ 容器,其动态扩容的特性是普通数组不具备的,这⼤⼤增加了编程的灵活性。
虽然平时⽤ vector 很多,也能基本理解其原理,但⽆法从深层次理解。
直到研读了 vector 的源码,才能⽐较⾃信的说⾃⼰真正理解了 vector 的基本原理,正应了侯捷说的那句话:源码⾯前,了⽆密码。
我会写两篇⽂章分别分析泛化 vector 和针对 bool 类型的特化 vector(即是 bit_vector,位向量容器)。
本⽂将分析泛化的 vector 的源码。
vector概述vector 是动态扩容的连续数组。
普通数组是静态空间,⼀旦配置就⽆法改变,⽽ vector 是动态空间,其内部机制会⾃动扩充空间以容纳更多的元素。
其动态扩容的具体过程:当容器没有备⽤空间时,会开辟⼀块⼤⼩是原空间两倍的新空间,将数据从原空间复制到新空间并释放原空间。
因此,vector 提⾼了内存的合理利⽤和运⽤的灵活性,⽤户再也不⽤考虑数组的容量不⾜的问题。
vector部分源码本⽂分析的 vector 源码来⾃侯捷⽼师《STL源码剖析》⽤的 SGI-STL-v2.91 的版本。
其泛化版本的 vector 具体实现在 stl_vector.h ⽂件中,部分源码如下:// alloc 是 SGI STL 的空间配置器template<class T, class Alloc = alloc>class vector {public:typedef T value_type;typedef value_type* pointer;typedef const value_type* const_pointer;typedef value_type* iterator;typedef const value_type* const_iterator;typedef value_type& reference;typedef const value_type& const_reference;typedef size_t size_type;typedef ptrdiff_t difference_type;#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION //这⾥是反转迭代器,可先忽略typedef reverse_iterator<const_iterator> const_reverse_iterator;typedef reverse_iterator<iterator> reverse_iterator;#endifprotected:// simple_alloc 是 SGI STL 的空间配置器,是源码所有容器都使⽤这个接⼝typedef simple_alloc<value_type, Alloc> data_allocator;iterator start; //表⽰⽬前使⽤空间的头iterator finish; //表⽰⽬前使⽤空间的尾iterator end_of_storage; //表⽰⽬前可⽤空间的尾void insert_aux(iterator position, const T& x);void deallocate() {if(start)data_allocator::deallocate(start, end_of_storage - start);}void fill_initialize(size_type n, const T& value) {start = allocate_and_fill(n, value);finish = start + n;end_of_storage = finish;}public:iterator begin() { return start; }const_iterator begin() const { return start; }iterator end() { return finish; }const_iterator end() const { return finish; }reverse_iterator rbegin() { return reverse_iterator(end()); }const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}reverse_iterator rend() { return reverse_iterator(begin()); }const_reverse_iterator rend() const {return const_reverse_iterator(begin());}size_type size() const {return size_type(end() - begin());}size_type max_size() const {return size_type(-1) / sizeof(T);}size_type capacity() const {return size_type(end_of_storage - begin());}bool empty() const { return begin() == end(); }reference operator[](size_type n) {return *(begin() + n);}const_reference operator[](size_type n) const {return *(begin() + n);}vector() : start(0), finish(0), end_of_storage(0) {}vector(size_type n, const T& value) {fill_initialize(n, value);}vector(int n, const T& value) {fill_initialize(n, value);}vector(long n, const T& value) {fill_initialize(n, value);}explicit vector(size_type n) {fill_initialize(n, T());}vector(const vector<T, Alloc>& x) {start = allocate_and_copy(x.end() - x.begin(), x.begin(), x.end()); finish = start + (x.end() - x.begin());end_of_storage = finish;}template <class InputIterator>vector(InputIterator first, InputIterator last) :start(0), finish(0), end_of_storage(0){range_initialize(first, last, iterator_category(first));}~vector() {destroy(start, finish); //全局变量deallocate();}vector<T, Alloc>& operator=(const vector<T, Alloc>& x);void reverve(size_type n) {if (capacity() < n) {const size_type old_size = size();iterator tmp = allocate_and_copy(n, start, finish);destroy(start, finish);deallocate();start = tmp;finish = start + old_size;end_of_storage = start + n;}}reference front() { return *begin(); }const_reference front() const { return *begin(); }reference back() { return *(end() - 1); }const_reference back() const { return *(end() - 1); }void push_back(const T& x) {if (finish != end_of_storage) { //还有备⽤空间construct(finish, x); //全局函数++finish;} else//⽆备⽤空间insert_aux(end(), x); //成员函数,后续会分析}void swap(vector<T, Alloc>& x) {__STD::swap(start, x.start);__STD::swap(finish, x.finish);__STD::swap(end_of_storage, x.end_of_storage);}//和push_back差别不⼤,只是插⼊位置不⼀样,复杂⼀点iterator insert(iterator position, const T& x) {size_type n = position - begin();if (finish != end_of_storage && position == end()) {construct(finish, x);} elseinsert_aux(position, x);return begin() + n;}iterator insert(iterator position) {insert(position, T());}#ifdef __STL_MEMBER_TEMPLATEStemplate <class InputIterator>void insert(iterator position, InputIterator first, InputIterator last){range_insert(position, first, last, iterator_category(first));}#endifvoid insert(iterator pos, size_type n, const T& x);void insert(iterator pos, int n, const T& x) {insert(pos, (size_type) n, x);}void insert(iterator pos, long n, const T& x) {insert(pos, (size_type) n, x);}void pop_back() {--finish;destroy(finish); //finish->~T 这⾥仅仅是调⽤指针finish所指对象的析构函数,不能释放内存 }iterator erase(iterator position) {//如果移除的不是最后⼀个元素if (position + 1 != end())copy(position + 1, finish, position); //全局函数--finish;destroy(finish);return position;}//移除半开半闭区间[first, last)之间的所有元素,last指向的元素不被移除iterator erase(iterator first, iterator last) {iterator i = copy(last, finish, first);//如果区间内元素的析构函数是trivial的,则什么也不做//如果区间内元素的析构函数是non-trivial的,则依序调⽤其析构函数destroy(i, finish);finish = finish - (last - first); //重新调整finishreturn first;}void resize(size_type new_size, const T& x) {if (new_size < size())erase(begin() + new_size, end());elseinsert(end(), new_size - size(), x);}void resize(size_type new_size) { resize(new_size, T()); }void clear() { erase(begin(), end()); }protected://配置空间并填满内容iterator allocate_and_fill(size_type n, const T& x) {iterator result = data_allocator::allocate(n);__STL_TRY{uninitialized_fill_n(result, n, x);return result;}__STL_UNWIND(data_allocator::deallocate(result, n));}template <class ForwardIterator>iterator allocate_and_copy(size_type n,ForwardIterator first, ForwardIterator last) {iterator result = data_allocator::allocate(n);__STL_TRY {uninitialized_copy(first, last, result);return result;}__STL_UNWIND(data_allocator::deallocate(result, n));}/***********************后⾯还有********************************/vector 迭代器vector 维护的是⼀个连续空间所以⽆论其元素的型别为何,普通指针就可以作为 vector 的迭代器⽽满⾜所有必要条件,因为 vector 迭代器所需要的操作⾏为,如 operator*,operator++,operator--,operator+,operator-,operator+=,operator-=,普通指针就具备,从上⾯的源码就可以看出,vector ⽤的迭代器就是普通指针。
侯捷的c++课程内容
侯捷老师的C++课程内容非常丰富,涵盖了C++的基础知识、面向对象编程、STL标准库和泛型编程、设计模式、新标准C++11&14、内存管理机制等多个方面。
具体来说,侯捷老师的C++课程包括:
1.C++编程简介:介绍C++的基本语法和编程思想,包括变量、数据类型、运算符、
控制结构等。
2.面向对象编程:介绍面向对象的基本概念和C++中的类、对象、继承、多态等
概念,以及如何使用面向对象的方法进行程序设计。
3.STL标准库和泛型编程:介绍STL标准库中的容器、算法、迭代器等,以及泛
型编程的概念和实现方法。
4.设计模式:介绍常见的面向对象设计模式,如单例模式、工厂模式、观察者模
式等,以及如何使用设计模式来提高代码的可维护性和可重用性。
5.新标准C++11&14:介绍C++11和C++14的新特性,如智能指针、lambda
表达式、范围for循环等,以及如何使用这些新特性来提高代码的效率和可读性。
6.内存管理机制:介绍C++中的内存管理机制,包括动态内存分配、内存泄漏检
测、垃圾回收等,以及如何避免内存泄漏和优化内存使用。
此外,侯捷老师的C++课程还包括一些进阶内容,如多线程编程、网络编程等,以及一些实用的编程技巧和经验分享。
总的来说,侯捷老师的C++课程内容非常全面,从基础到进阶,从理论到实践,涵盖了C++编程的各个方面。
通过学习侯捷老师的C++课程,可以深入了解C++编程语言的特点和应用,提高编程能力和水平。
C++顺序容器基础知识总结
C++顺序容器基础知识总结0.前⾔本⽂简单地总结了STL的顺序容器的知识点。
⽂中并不涉及具体的实现技巧,对于细节的东西也没有提及。
⼀来不同的标准库有着不同的实现,⼆来关于具体实现《STL源码剖析》已经展⽰得全⾯细致。
所以本⽂仅仅是对容器基础知识的归纳。
⾄于容器提供的接⼝与使⽤实例,建议查取官⽅⽂档。
⽂章难免有错漏,希望指出。
1.容器概论容器,置物之所也。
像桶可装⽔,碗可盛汤,C++的容器,可以存储对象。
容器有多种,⽤来处理不同的元素操作诉求。
按照元素存储到容器中以及访问⽅式的差异,容器分为顺序容器与关联容器。
顺序容器也称为序列式容器。
序列式容器按元素插⼊的顺序存储元素,这些元素可以进⾏排序,但未必是有序的。
C++本⾝内置了⼀个序列式容器array(数组),STL另外提供了vector,list,forward_list,deque,stack,queue,priority-queue,string等等序列式容器。
所有的容器都是基于模板实现的,因为容器必须保证能装得下各种各样的类型。
其中,stack,queue都是基于deque来实现的,priority-queue基于heap来实现,从技术上来说它们属于容器适配器(adapter)。
其中array与forward_list是C++11添加的新容器类型。
2.std::array2.1.底层数据结构array的底层数据结构是固定数组。
与C-style的数组类似,它的⼤⼩在定义后就不能被改变。
由于array具有固定的⼤⼩,它不⽀持添加和删除元素或改变容器⼤⼩等其他容器拥有的操作。
在定义⼀个array容器的时候必须指定⼤⼩:Defined in header <array>template<class T,std::size_t N> struct array;2.2.内存分配策略在内存分配策略上,array也与C-style数组类似。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
<std\> 完整列表 The Annotated STL Sources 1G++ 2.91.57,cygnus\cygwin-b20\include\g++\std\ 完整列表// Member templates for the -*- C++ -*- string classes.// Copyright (C) 1994 Free Software Foundation// This file is part of the GNU ANSI C++ Library. This library is free// software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the// Free Software Foundation ; either version 2, or (at your option)// any later version.// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License// along with this library; see the file COPYING. If not, write to the Free// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.// As a special exception, if you link this library with files// compiled with a GNU compiler to produce an executable, this does not cause // the resulting executable to be covered by the GNU General Public License. // This exception does not however invalidate any other reasons why// the executable file might be covered by the GNU General Public License.// Written by Jason Merrill based upon the specification by Takanori Adachi // in ANSI X3J16/94-0013R2.extern "C++" {template <class charT, class traits, class Allocator>inline void * basic_string <charT, traits, Allocator>::Rep::operator new (size_t s, size_t extra){return Allocator::allocate(s + extra * sizeof (charT));}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::operator delete (void * ptr){Allocator::deallocate(ptr, sizeof(Rep) +reinterpret_cast<Rep *>(ptr)->res *sizeof (charT));}template <class charT, class traits, class Allocator>inline size_t basic_string <charT, traits, Allocator>::Rep::frob_size (size_t s){<std\> 完整列表 The Annotated STL Sources 2 size_t i = 16;while (i < s) i *= 2;return i;}template <class charT, class traits, class Allocator>inline basic_string <charT, traits, Allocator>::Rep *basic_string <charT, traits, Allocator>::Rep::create (size_t extra){extra = frob_size (extra + 1);Rep *p = new (extra) Rep;p->res = extra;p->ref = 1;p->selfish = false;return p;}template <class charT, class traits, class Allocator>charT * basic_string <charT, traits, Allocator>::Rep::clone (){Rep *p = Rep::create (len);p->copy (0, data (), len);p->len = len;return p->data ();}template <class charT, class traits, class Allocator>inline bool basic_string <charT, traits, Allocator>::Rep::excess_slop (size_t s, size_t r){return 2 * (s <= 16 ? 16 : s) < r;}template <class charT, class traits, class Allocator>inline bool basic_string <charT, traits, Allocator>::check_realloc (basic_string::size_type s) const{s += sizeof (charT);rep ()->selfish = false;return (rep ()->ref > 1|| s > capacity ()|| Rep::excess_slop (s, capacity ()));}template <class charT, class traits, class Allocator>void basic_string <charT, traits, Allocator>::alloc (basic_string::size_type size, bool save)<std\> 完整列表 The Annotated STL Sources 3{if (! check_realloc (size))return;Rep *p = Rep::create (size);if (save){p->copy (0, data (), length ());p->len = length ();}elsep->len = 0;repup (p);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>&basic_string <charT, traits, Allocator>::replace (size_type pos1, size_type n1,const basic_string& str, size_type pos2, size_type n2){const size_t len2 = str.length ();if (pos1 == 0 && n1 >= length () && pos2 == 0 && n2 >= len2)return operator= (str);OUTOFRANGE (pos2 > len2);if (n2 > len2 - pos2)n2 = len2 - pos2;return replace (pos1, n1, str.data () + pos2, n2);}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::copy (size_t pos, const charT *s, size_t n){if (n)traits::copy (data () + pos, s, n);}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::move (size_t pos, const charT *s, size_t n){if (n)<std\> 完整列表 The Annotated STL Sources 4 traits::move (data () + pos, s, n);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>&basic_string <charT, traits, Allocator>::replace (size_type pos, size_type n1, const charT* s, size_type n2){const size_type len = length ();OUTOFRANGE (pos > len);if (n1 > len - pos)n1 = len - pos;LENGTHERROR (len - n1 > max_size () - n2);size_t newlen = len - n1 + n2;if (check_realloc (newlen)){Rep *p = Rep::create (newlen);p->copy (0, data (), pos);p->copy (pos + n2, data () + pos + n1, len - (pos + n1));p->copy (pos, s, n2);repup (p);}else{rep ()->move (pos + n2, data () + pos + n1, len - (pos + n1));rep ()->copy (pos, s, n2);}rep ()->len = newlen;return *this;}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::set (size_t pos, const charT c, size_t n){traits::set (data () + pos, c, n);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>& basic_string <charT, traits, Allocator>:: replace (size_type pos, size_type n1, size_type n2, charT c){const size_t len = length ();OUTOFRANGE (pos > len);if (n1 > len - pos)n1 = len - pos;LENGTHERROR (len - n1 > max_size () - n2);<std\> 完整列表 The Annotated STL Sources 5size_t newlen = len - n1 + n2;if (check_realloc (newlen)){Rep *p = Rep::create (newlen);p->copy (0, data (), pos);p->copy (pos + n2, data () + pos + n1, len - (pos + n1));p->set (pos, c, n2);repup (p);}else{rep ()->move (pos + n2, data () + pos + n1, len - (pos + n1));rep ()->set (pos, c, n2);}rep ()->len = newlen;return *this;}template <class charT, class traits, class Allocator>void basic_string <charT, traits, Allocator>::resize (size_type n, charT c){LENGTHERROR (n > max_size ());if (n > length ())append (n - length (), c);elseerase (n);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::copy (charT* s, size_type n, size_type pos) const{OUTOFRANGE (pos > length ());if (n > length () - pos)n = length () - pos;traits::copy (s, data () + pos, n);return n;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::<std\> 完整列表 The Annotated STL Sources 6 find (const charT* s, size_type pos, size_type n) const{size_t xpos = pos;for (; xpos + n <= length (); ++xpos)if (traits::eq (data () [xpos], *s)&& traits::compare (data () + xpos, s, n) == 0)return xpos;return npos;}template <class charT, class traits, class Allocator>inline basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::_find (const charT* ptr, charT c, size_type xpos, size_type len){for (; xpos < len; ++xpos)if (traits::eq (ptr [xpos], c))return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find (charT c, size_type pos) const{return _find (data (), c, pos, length ());}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::rfind (const charT* s, size_type pos, size_type n) const{if (n > length ())return npos;size_t xpos = length () - n;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0; )if (traits::eq (data () [xpos], *s)&& traits::compare (data () + xpos, s, n) == 0)return xpos;return npos;}template <class charT, class traits, class Allocator><std\> 完整列表 The Annotated STL Sources 7basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::rfind (charT c, size_type pos) const{if (1 > length ())return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0; )if (traits::eq (data () [xpos], c))return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_first_of (const charT* s, size_type pos, size_type n) const{size_t xpos = pos;for (; xpos < length (); ++xpos)if (_find (s, data () [xpos], 0, n) != npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_last_of (const charT* s, size_type pos, size_type n) const{if (length() == 0)return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0;)if (_find (s, data () [xpos], 0, n) != npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_first_not_of (const charT* s, size_type pos, size_type n) const<std\> 完整列表 The Annotated STL Sources 8 {size_t xpos = pos;for (; xpos < length (); ++xpos)if (_find (s, data () [xpos], 0, n) == npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_first_not_of (charT c, size_type pos) const{size_t xpos = pos;for (; xpos < length (); ++xpos)if (traits::ne (data () [xpos], c))return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_last_not_of (const charT* s, size_type pos, size_type n) const{if (length() == 0)return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0;)if (_find (s, data () [xpos], 0, n) == npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_last_not_of (charT c, size_type pos) const{if (length() == 0)return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0;)if (traits::ne (data () [xpos], c))return xpos;<std\> 完整列表 The Annotated STL Sources 9return npos;}template <class charT, class traits, class Allocator>int basic_string <charT, traits, Allocator>::compare (const basic_string& str, size_type pos, size_type n) const{OUTOFRANGE (pos > length ());size_t rlen = length () - pos;if (rlen > n)rlen = n;if (rlen > str.length ())rlen = str.length ();int r = traits::compare (data () + pos, str.data (), rlen);if (r != 0)return r;if (rlen == n)return 0;return (length () - pos) - str.length ();}template <class charT, class traits, class Allocator>int basic_string <charT, traits, Allocator>::compare (const charT* s, size_type pos, size_type n) const{OUTOFRANGE (pos > length ());size_t rlen = length () - pos;if (rlen > n)rlen = n;int r = traits::compare (data () + pos, s, rlen);if (r != 0)return r;return (length () - pos) - n;}#include <iostream.h>template <class charT, class traits, class Allocator>istream &operator>> (istream &is, basic_string <charT, traits, Allocator> &s){int w = is.width (0);if (is.ipfx0 ()){register streambuf *sb = is.rdbuf ();s.resize (0);while (1)<std\> 完整列表 The Annotated STL Sources 10 {int ch = sb->sbumpc ();if (ch == EOF){is.setstate (ios::eofbit);break;}else if (traits::is_del (ch)){sb->sungetc ();break;}s += ch;if (--w == 1)break;}}is.isfx ();if (s.length () == 0)is.setstate (ios::failbit);return is;}template <class charT, class traits, class Allocator>ostream &operator<< (ostream &o, const basic_string <charT, traits, Allocator>& s) {return o.write (s.data (), s.length ());}template <class charT, class traits, class Allocator>istream&getline (istream &is, basic_string <charT, traits, Allocator>& s, charT delim) {if (is.ipfx1 ()){_IO_size_t count = 0;streambuf *sb = is.rdbuf ();s.resize (0);while (1){int ch = sb->sbumpc ();if (ch == EOF){is.setstate (count == 0? (ios::failbit|ios::eofbit)<std\> 完整列表 The Annotated STL Sources 11 : ios::eofbit);break;}++count;if (ch == delim)break;s += ch;if (s.length () == s.npos - 1){is.setstate (ios::failbit);break;}}}// We need to be friends with istream to do this.// is._gcount = count;is.isfx ();return is;}// static data member of class basic_string<>template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::Repbasic_string<charT, traits, Allocator>::nilRep = { 0, 0, 1, false };template <class charT, class traits, class Allocator>const basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::npos ;} // extern "C++"。