| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2006-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 DLVHASH_H |
| 21 | #define DLVHASH_H |
| 22 | |
| 23 | #include <map> |
| 24 | #include <list> |
| 25 | #include "dlVertex.h" |
| 26 | #include "tRole.h" |
| 27 | |
| 28 | /// naive and simple hash table for DL Vertices |
| 29 | class dlVHashTable |
| 30 | { |
| 31 | protected: // types |
| 32 | /// hashed IDs of the DL vertices |
| 33 | typedef std::list<BipolarPointer> HashLeaf; |
| 34 | /// hash table by itself |
| 35 | typedef std::map<BipolarPointer, HashLeaf> HashTable; |
| 36 | |
| 37 | protected: // members |
| 38 | /// host DAG that contains actual nodes; |
| 39 | const DLDag& host; |
| 40 | /// HT for nodes |
| 41 | HashTable Table; |
| 42 | |
| 43 | protected: // methods |
| 44 | /// get a (very simple) hash of the vertex |
| 45 | static BipolarPointer hash ( const DLVertex& v ) |
| 46 | { |
| 47 | BipolarPointer sum = 0; |
| 48 | if ( v.getRole() != nullptr ) |
| 49 | sum += v.getRole()->getId(); |
| 50 | if ( v.getProjRole() != nullptr ) |
| 51 | sum += v.getProjRole()->getId(); |
| 52 | sum += v.getC(); |
| 53 | sum += v.getNumberLE(); |
| 54 | for ( const auto& arg: v ) |
| 55 | sum += arg; |
| 56 | return sum; |
| 57 | } |
| 58 | |
| 59 | /// insert new POSition into a given LEAF |
| 60 | static void insert ( HashLeaf& leaf, BipolarPointer pos ) { leaf.push_back(pos); } |
| 61 | /// locate vertex V in a given LEAF |
| 62 | BipolarPointer locate ( const HashLeaf& leaf, const DLVertex& v ) const; |
| 63 | |
| 64 | public: // interface |
| 65 | /// empty c'tor |
| 66 | explicit dlVHashTable ( const DLDag& dag ) : host(dag) {} |
| 67 | |
| 68 | /// add an element (given by a POSition) to hash |
| 69 | void addElement ( BipolarPointer pos ); |
| 70 | /// locate given vertex in the hash |
| 71 | BipolarPointer locate ( const DLVertex& v ) const; |
| 72 | }; // dlVHashTable |
| 73 | |
| 74 | #endif |