Main Page | Class Hierarchy | Class List | File List | Class Members

FastVector.h

00001 // FastVector.h -- Interface to fast-erasing vectors.
00002 
00003 /*
00004  * Copyright (C) 1997, 1998, 2003 Tudor Hulubei <tudor@hulubei.net>.
00005  *
00006  * This library is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 2, or (at
00009  * your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA,
00019  * 02111-1307, USA.
00020  */
00021 
00022 /*
00023  * NOTE: This is an interal header file.
00024  * You should not attempt to use it directly.
00025  */
00026 
00027 // $Id: FastVector_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
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 // Local Variables:
00107 // mode: C++
00108 // End:

Generated on Wed May 25 12:21:14 2005 for csp.kdevelop by  doxygen 1.3.9.1