dlvhex  2.5.0
include/dlvhex2/DynamicVector.h
Go to the documentation of this file.
00001 /* dlvhex -- Answer-Set Programming with external interfaces.
00002  * Copyright (C) 2005-2007 Roman Schindlauer
00003  * Copyright (C) 2006-2015 Thomas Krennwallner
00004  * Copyright (C) 2009-2016 Peter Schüller
00005  * Copyright (C) 2011-2016 Christoph Redl
00006  * Copyright (C) 2015-2016 Tobias Kaminski
00007  * Copyright (C) 2015-2016 Antonius Weinzierl
00008  *
00009  * This file is part of dlvhex.
00010  *
00011  * dlvhex is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU Lesser General Public License as
00013  * published by the Free Software Foundation; either version 2.1 of
00014  * the License, or (at your option) any later version.
00015  *
00016  * dlvhex is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with dlvhex; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00034 #ifndef DYNAMICVECTOR_HPP_INCLUDED__23122011
00035 #define DYNAMICVECTOR_HPP_INCLUDED__23122011
00036 
00037 #include <iterator>
00038 #include <boost/foreach.hpp>
00039 #include <utility>
00040 #include <iostream>
00041 #include <bm/bm.h>
00042 #include <boost/numeric/ublas/vector.hpp>
00043 
00045 template<typename K, typename T>
00046 class DynamicVector : public std::vector<T>
00047 {
00048     private:
00050         bm::bvector<> stored;
00051     public:
00055         typename std::vector<T>::iterator find(K index) {
00056             if (stored.get_bit(index))  return std::vector<T>::begin() + index;
00057             else        return std::vector<T>::end();
00058         }
00059 
00062         void erase(K index) {
00063             stored.clear_bit(index);
00064         }
00065 
00069         inline T& operator[](K index) {
00070             if (index >= (K)this->size()) {
00071                 this->resize(index + 1);
00072             }
00073             stored.set_bit(index);
00074             return std::vector<T>::operator[](index);
00075         }
00076 };
00077 #endif
00078 
00079 // vim:expandtab:ts=4:sw=4:
00080 // mode: C++
00081 // End: