[Assorted-commits] SF.net SVN: assorted: [359] cpp-commons/trunk/src/commons/deque.h
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-11 04:53:44
|
Revision: 359 http://assorted.svn.sourceforge.net/assorted/?rev=359&view=rev Author: yangzhang Date: 2008-02-10 20:53:49 -0800 (Sun, 10 Feb 2008) Log Message: ----------- added beginnings of lightweight deque Added Paths: ----------- cpp-commons/trunk/src/commons/deque.h Added: cpp-commons/trunk/src/commons/deque.h =================================================================== --- cpp-commons/trunk/src/commons/deque.h (rev 0) +++ cpp-commons/trunk/src/commons/deque.h 2008-02-11 04:53:49 UTC (rev 359) @@ -0,0 +1,39 @@ +#ifndef _COMMONS_DEQUE_H +#define _COMMONS_DEQUE_H + +#include <list> +#include <vector> + +namespace commons +{ + using namespace std; + + template <typename T> + class deque + { + private: + class chunk + { + public: + chunk() : xs(node_size) {} + private: + vector<T> xs; + }; + + list<chunk> chunks; + size_t node_size; + public: + deque(size_t node_size = 8192) : node_size(node_size) {} + + void push_back(const T& x) + { + chunk& last = chunks.back(); + if (last.xs.size() == last.xs.capacity()) { + chunks.push_back(chunk()); + } + last.push_back(x); + } + }; +} + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |