上一页 1 2 3 4 5 6 7 8 ··· 18 下一页

2011年11月26日

linux kernel 中的二叉树搜索 与 stl 相应物的对比

摘要: 代码Linux kernel 中也使用并实现了红黑树,但是查找算法没有自己实现,而是希望使用者去实现。如果只是实现一个精确查找的函数,这很简单,几乎每个人都能写出正确的代码:static inline struct page * rb_search_page_cache(struct inode * inode, unsigned long offset){ struct rb_node * n = inode->i_rb_page_cache.rb_node; struct page * page; while (n) { page = rb_entry(n, struct p... 阅读全文

posted @ 2011-11-26 22:11 能发波 阅读(215) 评论(0) 推荐(0)

2011年11月20日

C++ Question: using

摘要: 看看这段代码:#include struct A { void f() { printf("A::f\n"); }};struct B : A { using A::f; // #1 void f() { printf("B::f\n"); } // #2};int main() { B().f(); #3 return 0;}运行结果会如何呢?A. B::fB. #1 编译错C. #2 编译错D. #3编译错 阅读全文

posted @ 2011-11-20 09:49 能发波 阅读(97) 评论(0) 推荐(0)

2011年11月11日

C++ 2-phase lookup

摘要: This 2-phase look up of g++ (gnu C++) seems not inconsistency: builtin types are not treat equivalent with user defined type.#include class A {}; void f(A) { printf("%s\n", __PRETTY_FUNCTION__); }class B {};// now g(T) knew A,B,int,...// phase 1 lookup just success for f(A)template void g( 阅读全文

posted @ 2011-11-11 14:46 能发波 阅读(174) 评论(0) 推荐(0)

2011年10月30日

小技巧,大智慧:%n of sscanf

摘要: scanf 系列中有个函数 sscanf,可能有人用过,它的普通用法,我就不讲了,可以参考这里:man 3 sscanfgnu c 实现了 C 标准的 format specify 的 %n,它的含义是返回从该次 XXscanf 调用开始到此读了多少个字节,我们可以利用这一点,来实现不需要内存分配的%s:假定我们读取一批商品记录,每条记录包含商品ID,商品名称,商品价格,各字段的类型在代码中是自包含的size_t len1 = 0;ssize_t len2 = 0;char* line = NULL;while ((len2 = getline(&line, &len1, fp 阅读全文

posted @ 2011-10-30 21:54 能发波 阅读(275) 评论(0) 推荐(0)

忽悠,也是一种学问

摘要: 我看了一下我最近几个月的博客浏览记录,发现这篇的访问量最高。然而这篇文章里面提到的东西虽然有我这么多年编程生涯中的一些总结,但总体上没有太多实在的东西,缺乏可操作性。而其它的一些文章,比如:对数复杂度的聚集算法将递归转化成迭代的通用技术排列的分解......却几乎无人问津。 就如同在实际工作中,某某某通过调节某个参数,让系统的运行效率提升了20%,太牛逼,太了不起了!而通过优化,甚至重写某些代码,提高了200%的效率,你能保证你的代码一定正确,没 bug 吗?我们的 site up 已经太多了,你还给大家添乱?万幸通过了测试,最终上线也没出问题,不过你这人太“拘泥于细节”,那是没出息的码工干. 阅读全文

posted @ 2011-10-30 14:44 能发波 阅读(156) 评论(0) 推荐(0)

2011年10月29日

缓存与平行数组在 hash_strmap 和 gold_hash_map 中的应用

摘要: 2007 年我写过一篇关于平行数组与CPU缓存文章,最近,我在 hash_strmap 和 gold_hash_map 中应用了这种设计思想。hash value cache 对于一些对象,计算它们的 hash value 很昂贵,而对于另外一些对象,计算它们的 hash value 很廉价;所以,我们是否做 hash 缓存对 hash table 性能很重要。更有意思的是,hash 缓存一般只在 hash table 的增长阶段访问(rehash),而在查找阶段,不需要访问 hash 缓存,于是,可以把 hash cache 从数据结构的结点中提取出来,放到一个分离的平行数组中。所谓平行数. 阅读全文

posted @ 2011-10-29 19:51 能发波 阅读(209) 评论(0) 推荐(0)

gold_hash_map vs google sparse map by google's time_hash_map.cc

摘要: 这个列表由我写的一个 perl 程序抓取 time_hash_map 的结果生成。time_hash_map 是 google 自己实现的 hash table 中的一个性能测试程序,我在其中加入了针对 gold_hash_map 的测试,没有其它任何改动。链接中那个性能测试是 gold_hash_map 优化之前的测试结果(已经超越其它 map 了)。operation(byte=4)gold_hash_mapDENSE_HASH_MAPSPARSE_HASH_MAPSTANDARD HASH_MAPSTANDARD MAPtime:fetch_empty54.570865.5234187c 阅读全文

posted @ 2011-10-29 00:51 能发波 阅读(286) 评论(0) 推荐(0)

2011年10月25日

hash_strmap 最新性能数据

摘要: QPS 达到了35,644,397测试平台: 普通 PCCPU 3G Hz内存 2G500,000 条数据keylen=32 byte迭代20次, 总查询次数 10,000,000 次, 耗时 0.280549 秒相关文章HashMap 能有多快hash_strmap 为什么那么快代码链接测试脚本:run.sh代码链接:hash_strmap.hpp ; hash_strmap_bench.cpp 阅读全文

posted @ 2011-10-25 19:30 能发波 阅读(131) 评论(0) 推荐(0)

2011年10月23日

gold_hash_map design

摘要: 前一段时间写了个 hash_strmap, 效果不错,其中的一些设计思想可以扩展。于是,昨天到今天两天写了一个通用的 hash_map, 起了个名字叫gold_hash_map。hash_strmap 的介绍文章一,介绍文章二内存使用 和 hash_strmap 一样,使用连续的内存块,不过更简单,只需要两块内存( hash_strmap 需要 3 块或 4 块 )。不一样的地方缓存 hash value 一般情况下,hash value 的计算比较昂贵,所有有效的方式就是将这个计算出来的 hash value 缓存起来,但是,缓存是需要空间的!所以,对于简单的 Key,就不缓存它的 ... 阅读全文

posted @ 2011-10-23 18:24 能发波 阅读(135) 评论(0) 推荐(0)

gold_hash_map bench mark with google sparse hash

摘要: This is the testing result with google sparse hash's bench mark (time_hash_map.cc in google sparse hash's tar ball)The only modify totime_hash_map.cc is added the test for gold_hash_map (see diff below)87a88> #include 172a174,178> template> class EasyUse_gold_hash_map : public gold_ 阅读全文

posted @ 2011-10-23 17:23 能发波 阅读(283) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 ··· 18 下一页

导航