sprint 1-alpha
sprint/container/unordered_set.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 *   sprint::unordered_set
00003 *
00004 *   Copyright (C) 2005-2011  Paolo Medici <www.pmx.it>
00005 *
00006 *  This library is free software; you can redistribute it and/or
00007 *  modify it under the terms of the GNU Lesser General Public
00008 *  License as published by the Free Software Foundation; either
00009 *  version 2.1 of the License, or (at 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 GNU
00014 *  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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 *
00020 *******************************************************************************/
00021 
00028 #ifndef _SPRINT_UNORDERED_SET_H
00029 #define _SPRINT_UNORDERED_SET_H
00030 
00031 #include <vector>
00032 
00033 namespace sprint {
00034 
00037 template <typename _Key>
00038 class unordered_set: public std::vector< _Key > {
00039         public:
00040     typedef _Key                                                                key_type;
00041         typedef typename std::vector< _Key >    parent;
00042         public:
00043         typedef typename parent::iterator               iterator;
00044     typedef typename parent::const_iterator         const_iterator;    
00045         public:
00046     
00048                 iterator find(const key_type & __x)     {
00049                         for(iterator i = parent::begin(); i!= parent::end(); i++)
00050                                 if( *i == __x)
00051                                         return i;
00052                         return parent::end();
00053                         }
00055                 const_iterator find(const key_type & __x)       const {
00056                         for(const_iterator i = parent::begin(); i!= parent::end(); i++)
00057                                 if( *i == __x)
00058                                                 return i;
00059                         return parent::end();
00060                 }       
00061                 
00063                 bool insert(const key_type & __x)
00064                 {
00065          if(find(__x) == parent::end())
00066             {
00067             parent::push_back(__x);
00068             return true;
00069             }
00070             else
00071             return false;
00072         }
00073 };
00074 
00075 }
00076 
00077 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines