| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-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 CWDARRAY_H |
| 21 | #define CWDARRAY_Hcxx . . $ `Kernel/CWDArray.h:21:9`! |
| 22 | |
| 23 | #include <ostream> |
| 24 | #include <algorithm> // find |
| 25 | |
| 26 | #include "globaldef.h"cxx . . $ `<file>/Kernel/globaldef.h`/ |
| 27 | #include "ConceptWithDep.h"cxx . . $ `<file>/Kernel/ConceptWithDep.h`/ |
| 28 | |
| 29 | enum addConceptResultcxx . . $ addConceptResult# { acrClashcxx . . $ acrClash., acrExistcxx . . $ acrExist., acrDonecxx . . $ acrDone. }; |
| 30 | |
| 31 | class TRestorercxx . . $ TRestorer#; |
| 32 | |
| 33 | /// array of concepts with dep-set, which may be viewed as a label of a completion-graph |
| 34 | class CWDArraycxx . . $ CWDArray# |
| 35 | { |
| 36 | protected: // internal typedefs |
| 37 | /// base type |
| 38 | typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<ConceptWDepcxx . . $ ConceptWDep#> ConceptSetcxx . . $ CWDArray#ConceptSet#; |
| 39 | /// RW iterator |
| 40 | typedef ConceptSetcxx . . $ CWDArray#ConceptSet#::iteratorcxx . . $ std/vector#iterator# iteratorcxx . . $ CWDArray#iterator#; |
| 41 | |
| 42 | /// restorer for the merge |
| 43 | friend class UnMergecxx . . $ UnMerge#; |
| 44 | |
| 45 | public: // type interface |
| 46 | /// class for saving one label |
| 47 | class SaveStatecxx . . $ CWDArray#SaveState# |
| 48 | { |
| 49 | public: |
| 50 | /// end pointer of the label |
| 51 | size_tcxx . . $ std/size_t# epcxx . . $ CWDArray#SaveState#ep. = 0; |
| 52 | }; // SaveState |
| 53 | |
| 54 | /// const iterator on label |
| 55 | typedef ConceptSetcxx . . $ CWDArray#ConceptSet#::const_iteratorcxx . . $ std/vector#const_iterator# const_iteratorcxx . . $ CWDArray#const_iterator#; |
| 56 | |
| 57 | protected: // members |
| 58 | /// array of concepts together with dep-sets |
| 59 | ConceptSetcxx . . $ CWDArray#ConceptSet# Basecxx . . $ CWDArray#Base.; |
| 60 | |
| 61 | public: // interface |
| 62 | /// init/clear label with given size |
| 63 | void initcxx . . $ CWDArray#init(2c44cd906ae4e829). ( size_tcxx . . $ size_t# size ) |
| 64 | { |
| 65 | Basecxx . . $ CWDArray#Base..reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(size); |
| 66 | Basecxx . . $ CWDArray#Base..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); |
| 67 | } |
| 68 | |
| 69 | //---------------------------------------------- |
| 70 | // Label access interface |
| 71 | //---------------------------------------------- |
| 72 | |
| 73 | // label iterators |
| 74 | |
| 75 | /// begin RO iterator |
| 76 | const_iteratorcxx . . $ CWDArray#const_iterator# begincxx . . $ CWDArray#begin(e55d760a93e9f197). ( void ) const { return Basecxx . . $ CWDArray#Base..begincxx . . $ std/vector#begin(359ca5030082c9f).(); } |
| 77 | /// end RO iterator |
| 78 | const_iteratorcxx . . $ CWDArray#const_iterator# endcxx . . $ CWDArray#end(e55d760a93e9f197). ( void ) const { return Basecxx . . $ CWDArray#Base..endcxx . . $ std/vector#end(359ca5030082c9f).(); } |
| 79 | |
| 80 | // add concept |
| 81 | |
| 82 | /// adds concept P to a label |
| 83 | void addcxx . . $ CWDArray#add(ae2a9648ed5e6860). ( const ConceptWDepcxx . . $ ConceptWDep#& p ) { Basecxx . . $ CWDArray#Base..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(p); } |
| 84 | /// update concept BP with a dep-set DEP; @return the appropriate restorer |
| 85 | TRestorercxx . . $ TRestorer#* updateDepSetcxx . . $ CWDArray#updateDepSet(a14715da98a4ac7b). ( BipolarPointercxx . . $ BipolarPointer# bp, const DepSetcxx . . $ DepSet#& dep ); |
| 86 | |
| 87 | // access concepts |
| 88 | |
| 89 | /// check whether label contains BP (ignoring dep-set) |
| 90 | bool containscxx . . $ CWDArray#contains(4a668f6de69bf818). ( BipolarPointercxx . . $ BipolarPointer# bp ) const { return stdcxx . . $ std/::findcxx . . $ std/find(a92da12e15934614). ( begincxx . . $ CWDArray#begin(e55d760a93e9f197).(), endcxx . . $ CWDArray#end(e55d760a93e9f197).(), bp ) !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). endcxx . . $ CWDArray#end(e55d760a93e9f197).(); } |
| 91 | /// get the concept by given index in the node's label |
| 92 | const ConceptWDepcxx . . $ ConceptWDep#& getConceptcxx . . $ CWDArray#getConcept(220b2e4a19f0cb4f). ( size_tcxx . . $ size_t# n ) const { return Basecxx . . $ CWDArray#Base.[cxx . . $ std/vector#`operator[]`(b61e45a10b63f40a).n]; } |
| 93 | |
| 94 | //---------------------------------------------- |
| 95 | // Blocking support |
| 96 | //---------------------------------------------- |
| 97 | |
| 98 | /// check whether LABEL is a superset of a current one |
| 99 | bool operatorcxx . . $ CWDArray#`operator<=`(eccb636064975658). <= ( const CWDArraycxx . . $ CWDArray#& label ) const |
| 100 | { |
| 101 | for ( const_iteratorcxx . . $ CWDArray#const_iterator# p = begincxx . . $ CWDArray#begin(e55d760a93e9f197).(), p_end = endcxx . . $ CWDArray#end(e55d760a93e9f197).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 102 | if ( !label.containscxx . . $ CWDArray#contains(4a668f6de69bf818).(p->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(a68f0626e749d9f6).bpcxx . . $ ConceptWDep#bp(455f465bc33b4cdf).()) ) |
| 103 | return false; |
| 104 | |
| 105 | return true; |
| 106 | } |
| 107 | /// check whether LABEL is a subset of a current one |
| 108 | bool operatorcxx . . $ CWDArray#`operator>=`(eccb636064975658). >= ( const CWDArraycxx . . $ CWDArray#& label ) const { return label <=cxx . . $ CWDArray#`operator<=`(eccb636064975658). *this; } |
| 109 | /// check whether LABEL is the same as a current one |
| 110 | bool operatorcxx . . $ CWDArray#`operator==`(eccb636064975658). == ( const CWDArraycxx . . $ CWDArray#& label ) const |
| 111 | { return (*this <=cxx . . $ CWDArray#`operator<=`(eccb636064975658). label) && (label <=cxx . . $ CWDArray#`operator<=`(eccb636064975658). *this); } |
| 112 | |
| 113 | //---------------------------------------------- |
| 114 | // Save/restore interface |
| 115 | //---------------------------------------------- |
| 116 | |
| 117 | /// save label using given SS |
| 118 | void savecxx . . $ CWDArray#save(a4a380d2389ee4f2). ( SaveStatecxx . . $ CWDArray#SaveState#& ss ) const { ss.epcxx . . $ CWDArray#SaveState#ep. = Basecxx . . $ CWDArray#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); } |
| 119 | /// restore label to given LEVEL using given SS |
| 120 | void restorecxx . . $ CWDArray#restore(5b817809b2ca3f56). ( const SaveStatecxx . . $ CWDArray#SaveState#& ss, unsigned int level ); |
| 121 | |
| 122 | //---------------------------------------------- |
| 123 | // Output |
| 124 | //---------------------------------------------- |
| 125 | |
| 126 | /// print the whole label |
| 127 | void printcxx . . $ CWDArray#print(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const; |
| 128 | }; // CWDArray |
| 129 | |
| 130 | #endif |