摘要: 想必每一位程序员都对设计模式中的单例模式非常的熟悉吧,以往我们用C++实现一个单例模式需要写以下代码: 1 class CSingleton 2 { 3 private: 4 CSingleton() //构造函数是私有的 5 { 6 } 7 static CSi... 阅读全文
posted @ 2014-12-11 12:06 老司机 阅读(9571) 评论(27) 推荐(6) 编辑
摘要: https://github.com/zouxiaohang 阅读全文
posted @ 2014-10-16 21:13 老司机 阅读(658) 评论(0) 推荐(0) 编辑
摘要: 1 //@author: Zou Xiaohang 2 //@describe: this class is like AtomicMarkableReference which is in java concurrent package. 3 // remember th... 阅读全文
posted @ 2014-05-11 10:56 老司机 阅读(554) 评论(0) 推荐(0) 编辑
摘要: 1 template 2 class Lock_guard{ 3 private: 4 Lock lock; 5 public: 6 explicit Lock_guard(Lock& lock){ 7 this->lock = lock; 8 th... 阅读全文
posted @ 2014-05-05 16:32 老司机 阅读(719) 评论(0) 推荐(0) 编辑
摘要: 暴雪公司有个经典的字符串的hash公式 先提一个简单的问题,假如有一个庞大的字符串数组,然后给你一个单独的字符串,让你从这个数组中查找是否有这个字符串并找到它,你会怎么做? 有一个方法最简单,老老实实从头查到尾,一个一个比较,直到找到为止,我想只要学过程序设计的人都能把这样一个程序作出来,但要是有... 阅读全文
posted @ 2014-04-19 15:42 老司机 阅读(3170) 评论(12) 推荐(1) 编辑
摘要: 不能分词八进制和数字类型加前/后缀的情况拿这个词法分析器跑了一遍整个Nginx源码,基本都能正确的分出结果,后面有测试例子~ 1 #ifndef _STATES_H_ 2 #define _STATES_H_ 3 4 #include "log_config.h" 5 6 __LOG_BEGIN_NAMESPACE 7 8 enum _states 9 {10 IN_NONE,11 IN_NUM,12 IN_0XNUM,13 IN_INT,14 IN_FLOAT,15 IN_E,16 IN_ALPHA,17 IN_MINUS... 阅读全文
posted @ 2014-03-24 19:57 老司机 阅读(908) 评论(2) 推荐(0) 编辑
摘要: 其中有一个函数调用了std::copy,本来想自己实现这个copy函数的,不过为了能先用上这些内存辅助函数来实现我的容器类和算法,只好过一段时间来实现一个自己的高效的实现copy函数 1 #ifndef _STL_UNINITIALIZED_H_ 2 #define _STL_UNINITIALIZED_H_ 3 4 #include "stl_algobase.h" 5 #include "stl_iterator.h" 6 #include "type_traits.h" 7 8 //#include 9 10 namespace 阅读全文
posted @ 2014-02-28 21:37 老司机 阅读(602) 评论(0) 推荐(0) 编辑
摘要: 首先是iterator traits,这个是用来萃取迭代器的特性的 1 #ifndef _STL_ITERATOR_H_ 2 #define _STL_ITERATOR_H_ 3 4 5 #include 6 /* 7 ** iterator_traits ----> 负责萃取迭代器的特性 8 */ 9 namespace zstd10 {11 struct inpt_iterator_tag{};12 struct outpt_iterator_tag{};13 struct forward_iterator_tag :public inpt_itera... 阅读全文
posted @ 2014-02-24 19:07 老司机 阅读(641) 评论(0) 推荐(0) 编辑
摘要: 1 #ifndef _KD_TREE_H_ 2 #define _KD_TREE_H_ 3 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 15 namespace zstd 16 { 17 struct threeD_node 18 { 19 double value[3];//value[0] = x, value[1] = y, ... 阅读全文
posted @ 2013-12-25 18:59 老司机 阅读(1277) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 10 using namespace std; 11 12 //IP层数据包格式 13 typedef struct 14 { 15 int header_len:4; 16 int version:4; 17 u_char tos:8; 18 int total_len:16; 19 int ident:16; 20 int ... 阅读全文
posted @ 2013-11-15 15:25 老司机 阅读(902) 评论(0) 推荐(1) 编辑