| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2005-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifndef GROWINGARRAYP_H |
| 21 | #define GROWINGARRAYP_Hcxx . . $ `Kernel/growingArrayP.h:21:9`! |
| 22 | |
| 23 | #include <vector> |
| 24 | |
| 25 | using stdcxx . . $ std/::size_tcxx . . $ size_t#; |
| 26 | |
| 27 | /** |
| 28 | * Generic class for structures which creates elements (by pointers) and re-use |
| 29 | * them (does not delete things). Derived types may add operations. |
| 30 | */ |
| 31 | template <typename T> |
| 32 | class growingArrayPcxx . . $ growingArrayP# |
| 33 | { |
| 34 | protected: // typedefs |
| 35 | /// type of the heap |
| 36 | typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<T*> baseTypecxx . . $ growingArrayP#baseType#; |
| 37 | |
| 38 | public: // typedefs |
| 39 | /// heap's iterator |
| 40 | typedef typename baseTypecxx . . $ growingArrayP#baseType#::iterator iteratorcxx . . $ growingArrayP#iterator#; |
| 41 | |
| 42 | protected: // members |
| 43 | /// heap itself |
| 44 | baseTypecxx . . $ growingArrayP#baseType# Basecxx . . $ growingArrayP#Base.; |
| 45 | /// index of the next unallocated entry |
| 46 | size_tcxx . . $ size_t# lastcxx . . $ growingArrayP#last. = 0; |
| 47 | |
| 48 | protected: // methods |
| 49 | /// tunable method for creating new object |
| 50 | virtual T* createNewcxx . . $ growingArrayP#createNew(155dc7f103cdb9db). ( void ) { return new T; } |
| 51 | /// init vector [B,E) with new objects T |
| 52 | void initArraycxx . . $ growingArrayP#initArray(51019c0eee066d6a). ( iteratorcxx . . $ growingArrayP#iterator# b, iteratorcxx . . $ growingArrayP#iterator# e ) |
| 53 | { |
| 54 | for ( iteratorcxx . . $ growingArrayP#iterator# p = b; p != e; ++p ) |
| 55 | *p = createNewcxx . . $ growingArrayP#createNew(155dc7f103cdb9db).(); |
| 56 | } |
| 57 | /// increase heap size |
| 58 | void growcxx . . $ growingArrayP#grow(49f6e7a06ebc5aa8). ( void ) |
| 59 | { |
| 60 | size_tcxx . . $ size_t# size = Basecxx . . $ growingArrayP#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); |
| 61 | Basecxx . . $ growingArrayP#Base..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(size?size*2:1); |
| 62 | initArraycxx . . $ growingArrayP#initArray(51019c0eee066d6a). ( Basecxx . . $ growingArrayP#Base..begincxx . . $ std/vector#begin(359ca5030082c9f).()+(long)size, Basecxx . . $ growingArrayP#Base..endcxx . . $ std/vector#end(359ca5030082c9f).() ); |
| 63 | } |
| 64 | /// ensure that size of vector is enough to fit the last element |
| 65 | void ensureHeapSizecxx . . $ growingArrayP#ensureHeapSize(49f6e7a06ebc5aa8). ( void ) |
| 66 | { |
| 67 | if ( lastcxx . . $ growingArrayP#last. >= Basecxx . . $ growingArrayP#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() ) |
| 68 | growcxx . . $ growingArrayP#grow(49f6e7a06ebc5aa8).(); |
| 69 | } |
| 70 | /// ensure that size of vector is enough to keep N elements |
| 71 | void ensureHeapSizecxx . . $ growingArrayP#ensureHeapSize(2c44cd906ae4e829). ( size_tcxx . . $ size_t# n ) |
| 72 | { |
| 73 | while ( n >= Basecxx . . $ growingArrayP#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() ) |
| 74 | growcxx . . $ growingArrayP#grow(49f6e7a06ebc5aa8).(); |
| 75 | } |
| 76 | |
| 77 | public: // interface |
| 78 | /// c'tor: make SIZE objects |
| 79 | explicit growingArrayPcxx . . $ growingArrayP#`growingArrayP<T>`(2c44cd906ae4e829). ( size_tcxx . . $ size_t# size = 0 ) : Basecxx . . $ growingArrayP#Base.(size) |
| 80 | { |
| 81 | initArraycxx . . $ growingArrayP#initArray(51019c0eee066d6a). ( Basecxx . . $ growingArrayP#Base..begincxx . . $ std/vector#begin(33b10a496a38335b).(), Basecxx . . $ growingArrayP#Base..endcxx . . $ std/vector#end(359ca5030082c9f).() ); |
| 82 | } |
| 83 | /// no copy c'tor |
| 84 | growingArrayPcxx . . $ growingArrayP#`growingArrayP<T>`(83700682ede49de9). ( const growingArrayP& ) = delete; |
| 85 | /// no assignment |
| 86 | growingArrayP& operatorcxx . . $ growingArrayP#`operator=`(51a58cacbbe82586).= ( const growingArrayP& ) = delete; |
| 87 | /// d'tor: delete all allocated objects |
| 88 | virtual ~cxx . . $ growingArrayP#`~growingArrayP<T>`(49f6e7a06ebc5aa8).growingArrayP() |
| 89 | { |
| 90 | for ( auto p = Basecxx . . $ growingArrayP#Base..rbegincxx . . $ std/vector#rbegin(93c341aad09a535d).(), p_end = Basecxx . . $ growingArrayP#Base..rendcxx . . $ std/vector#rend(93c341aad09a535d).(); p != p_end; ++p ) |
| 91 | delete *p; |
| 92 | } |
| 93 | |
| 94 | /// resize an array |
| 95 | void resizecxx . . $ growingArrayP#resize(2c44cd906ae4e829). ( size_tcxx . . $ size_t# n ) { ensureHeapSizecxx . . $ growingArrayP#ensureHeapSize(2c44cd906ae4e829).(n); lastcxx . . $ growingArrayP#last. = n; } |
| 96 | /// get the number of elements |
| 97 | size_tcxx . . $ size_t# sizecxx . . $ growingArrayP#size(fe4d2d262d4164a8). ( void ) const { return lastcxx . . $ growingArrayP#last.; } |
| 98 | /// check if heap is empty |
| 99 | bool emptycxx . . $ growingArrayP#empty(50ce9a9e25b4a850). ( void ) const { return lastcxx . . $ growingArrayP#last. == 0; } |
| 100 | /// mark all array elements as unused |
| 101 | virtual void clearcxx . . $ growingArrayP#clear(49f6e7a06ebc5aa8). ( void ) { lastcxx . . $ growingArrayP#last. = 0; } |
| 102 | }; // growingArrayP |
| 103 | |
| 104 | #endif |