LCOV - code coverage report
Current view: top level - src/ket - KetAtom.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 28 28 100.0 %
Date: 2026-10-14 13:16:16 Functions: 8 8 100.0 %

          Line data    Source code
       1             : // SPDX-FileCopyrightText: 2024 PairInteraction Developers
       2             : // SPDX-License-Identifier: LGPL-3.0-or-later
       3             : 
       4             : #include "pairinteraction/ket/KetAtom.hpp"
       5             : 
       6             : #include "pairinteraction/ket/QuantumNumberNotAvailableError.hpp"
       7             : #include "pairinteraction/utils/hash.hpp"
       8             : 
       9             : #include <string>
      10             : #include <vector>
      11             : 
      12             : namespace pairinteraction {
      13             : 
      14       47842 : KetAtom::KetAtom(Private /*unused*/, double energy, std::string species,
      15             :                  std::unordered_map<std::string, double> quantum_numbers,
      16             :                  std::unordered_map<std::string, double> quantum_numbers_std, Database &database,
      17       47842 :                  size_t id_in_database)
      18       47842 :     : Ket(energy, std::move(quantum_numbers)), species(std::move(species)),
      19       47842 :       quantum_numbers_std(std::move(quantum_numbers_std)), database(database),
      20       95684 :       id_in_database(id_in_database) {}
      21             : 
      22         598 : Database &KetAtom::get_database() const { return database; }
      23             : 
      24       51981 : size_t KetAtom::get_id_in_database() const { return id_in_database; }
      25             : 
      26          61 : double KetAtom::get_quantum_number_std(const std::string &name) const {
      27          61 :     if (!has_quantum_number(name)) {
      28           1 :         throw QuantumNumberNotAvailableError(name);
      29             :     }
      30          60 :     auto it = quantum_numbers_std.find(name);
      31          60 :     return it != quantum_numbers_std.end() ? it->second : 0;
      32             : }
      33             : 
      34       20292 : const std::string &KetAtom::get_species() const { return species; }
      35             : 
      36       40600 : bool KetAtom::operator==(const KetAtom &other) const {
      37       43081 :     return Ket::operator==(other) && species == other.species &&
      38       43081 :         quantum_numbers_std == other.quantum_numbers_std;
      39             : }
      40             : 
      41           1 : bool KetAtom::operator!=(const KetAtom &other) const { return !(*this == other); }
      42             : 
      43        4420 : size_t KetAtom::hash::operator()(const KetAtom &k) const {
      44        4420 :     size_t seed = typename Ket::hash()(k);
      45        4420 :     utils::hash_combine(seed, k.species);
      46             :     // The standard deviations are stored in an unordered map, so we combine the per-entry hashes in
      47             :     // an order-independent way (via xor) to obtain a deterministic result.
      48        4420 :     size_t quantum_numbers_std_hash = 0;
      49       57460 :     for (const auto &[key, value] : k.quantum_numbers_std) {
      50       53040 :         size_t entry_seed = 0;
      51       53040 :         utils::hash_combine(entry_seed, key);
      52       53040 :         utils::hash_combine(entry_seed, value);
      53       53040 :         quantum_numbers_std_hash ^= entry_seed;
      54             :     }
      55        4420 :     utils::hash_combine(seed, quantum_numbers_std_hash);
      56        4420 :     return seed;
      57             : }
      58             : 
      59             : } // namespace pairinteraction

Generated by: LCOV version 1.16