1 // 2 // BAGEL - Brilliantly Advanced General Electronic Structure Library 3 // Filename: block_key.h 4 // Copyright (C) 2014 Toru Shiozaki 5 // 6 // Author: Shane Parker <shane.parker@u.northwestern.edu> 7 // Maintainer: Shiozaki Group 8 // 9 // This file is part of the BAGEL package. 10 // 11 // This program is free software: you can redistribute it and/or modify 12 // it under the terms of the GNU General Public License as published by 13 // the Free Software Foundation, either version 3 of the License, or 14 // (at your option) any later version. 15 // 16 // This program is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with this program. If not, see <http://www.gnu.org/licenses/>. 23 // 24 25 #ifndef BAGEL_ASD_DMRG_BLOCK_KEY_H 26 #define BAGEL_ASD_DMRG_BLOCK_KEY_H 27 28 namespace bagel { 29 30 /// Convenient key for organizing blocks in ASD. Only holds nelea and neleb. 31 /// Useful in maps. 32 struct BlockKey { 33 int nelea; 34 int neleb; 35 BlockKeyBlockKey36 BlockKey(const int na, const int nb) : nelea(na), neleb(nb) {} 37 38 bool operator<(const BlockKey& o) const { 39 if (nelea+neleb==o.nelea+o.neleb) 40 return std::make_pair(nelea,neleb) < std::make_pair(o.nelea, o.neleb); 41 else 42 return nelea+neleb < o.nelea+o.neleb; 43 } 44 bool operator==(const BlockKey& o) const { return std::make_pair(nelea, neleb) == std::make_pair(o.nelea, o.neleb); } 45 }; 46 47 /// Extends BlockKey to also include the number of states. 48 /// Use primarily as a store of information, NOT to organize data such as in a map 49 struct BlockInfo : public BlockKey { 50 int nstates; BlockInfoBlockInfo51 BlockInfo(const int na, const int nb, const int ns) : BlockKey(na,nb), nstates(ns) {} keyBlockInfo52 BlockKey key() const { return BlockKey(nelea,neleb); } 53 54 bool operator==(const BlockInfo& o) const { return (key()==o.key() && nstates==o.nstates); } 55 }; 56 57 } 58 59 namespace std { 60 template <> struct hash<bagel::BlockKey> { 61 typedef bagel::BlockKey argument_type; 62 typedef std::size_t result_type; 63 64 result_type operator()(const argument_type& k) const { return k.nelea + (k.neleb << 16); } 65 }; 66 67 } 68 69 #endif 70