00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _CSP_KERNEL_FastVector_H
00030 #define _CSP_KERNEL_FastVector_H
00031
00032
00033 CSP_NAMESPACE_BEGIN(csp);
00034
00035
00045 template<class T>
00046 class FastVector :
00047 public vector<T>
00048 {
00049 public:
00050 typedef typename vector<T>::iterator iterator;
00051 typedef typename vector<T>::const_iterator const_iterator;
00052
00059 iterator fast_erase(const iterator position)
00060 {
00061 assert(position < vector<T>::end());
00062
00063 if (position + 1 != vector<T>::end())
00064 *position = vector<T>::back();
00065
00066 vector<T>::pop_back();
00067 return position;
00068 }
00069
00071 iterator erase(const iterator position)
00072 {
00073 return g_predictable ?
00074 vector<T>::erase(position) :
00075 fast_erase(position);
00076 }
00077
00084 iterator insert(const T& x)
00085 {
00086 if (g_predictable)
00087 return vector<T>::insert(
00088 lower_bound(vector<T>::begin(),
00089 vector<T>::end(),
00090 x, id_less<T>()),
00091 x);
00092 else
00093 {
00094 vector<T>::push_back(x);
00095 return vector<T>::end();
00096 }
00097 }
00098 };
00099
00100
00101 CSP_NAMESPACE_END(csp);
00102
00103
00104 #endif // _CSP_KERNEL_FastVector_H
00105
00106
00107
00108