使用类似BOOST.PP技巧,自动生成代码,效率上小胜stl,主要抽象出一般的(sort/heap/search)算法中的compare,按成员类型、偏移、类尺寸分派至不同函数;性能比stl相应算法还略高,用法更简单:
#include <febird/c/algorithm.h>
using namespace std;
struct A { int x, y; }; // x, y can be all base type: char/float/double/ptr etc...
struct Compare_A_x // only needed by std algorithm, maybe cause code explosion
{
bool operator()(const A& x, const A& y) const { return x.x < y.x; }
bool operator()(const A* x, const A* y) const { return x->x < y->x; }
};
void foo(std::vector<A>& va, std::vector<A*>& vpa)
{
// febird_sort_xxx is macro, called a C function, will not cause code explosion
// more fast 15% than std::sort
febird_sort_field(&*va.begin(), va.size(), x); // in cpp, auto deduce type of x
febird_sort_field_c(&*va.begin(), va.size(), x, tev_int); // in C, can not deduce type of x
std::sort(va.begin(), va.end(), Compare_A_x());
febird_sort_field_p(&*vpa.begin(), vpa.size(), x); // in cpp, auto deduce type of x
febird_sort_field_pc(&*vpa.begin(), vpa.size(), x, tev_int); // in C, can not deduce type of x
std::sort(vpa.begin(), vpa.end(), Compare_A_x());
}
项目地址:http://code.google.com/p/febird
分享到:
相关推荐
C++ STL--数据结构与算法实现(余文溪)示例程序代码.rar
由大连理工资深教授讲解有关c++语言中STL - 算法部分的内容,讲解到位,非常有参考价值
The tree.hh library for C++ provides an STL-like container class for n-ary trees, templated over the data stored at the nodes. Various types of iterators are provided (post-order, pre-order, and ...
numpy_stl-2.16.0-cp38-cp38-win32
02C STL总结-基于算法竞赛.pdf
# The following STL containers are currently supported: # # std::vector<T> -- via pvector command # std::list<T> -- via plist or plist_member command # std::map,T> -- via pmap or pmap_member command #...
Stl-thumb是用于STL文件的快速轻量级缩略图生成器。 它可以在Linux和Windows的文件管理器中显示STL文件的预览。 它是用Rust编写的,并使用OpenGL。 安装 视窗 Stl-thumb需要64位Windows 7或更高版本。 最新版本并...
三十分钟掌握STL三十分钟掌握STL三十分钟掌握STL三十分钟掌握STL三十分钟掌握STL三十分钟掌握STL三十分钟掌握STL
走近STL 简单的STL入门 STL用法
黄土时间序列的季节性分解 Seasonal-Trend-Loess(STL)算法将时间序列分解为季节,趋势和残差成分。 该算法使用( 为原始论文)来平滑循环子序列(例如,下例中所示的CO 2数据中的所有January值)。 从信号中去除...
X-CUBE-STL-H7 safety manual 安全手册
unity STL读取插件
数据结构与STL-肖波,徐雅静.高清版,挺不错的...
由大连理工资深教授讲解有关c++语言中STL - 迭代器部分,讲解深入透彻,非常有参考价值
可以打印map,vector等 只要 source stl-views-1.0.3.gdb
STL源码剖析对应的全部源码 与书上的东西是对应的,可以用来学习。新手上传5个积分意思意思就行,希望可以帮助到需要的人。
由大连理工资深教授讲解有关c++语言中STL - 概要及容器部分,讲解深入透彻,很有参考价值
numpy_stl-2.16.0-cp37-cp37m-win_amd64
numpy_stl-2.10.1-cp27-cp27m-win_amd64
python库。 资源全名:numpy-stl-1.3.4.tar.gz