CbmRoot
Loading...
Searching...
No Matches
L1AlgoFunctions.h
Go to the documentation of this file.
1/* Copyright (C) 2016-2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov, Sergei Zharko [committer] */
4
5/************************************************************************************************************
6 * @file L1AlgoFunctions.h
7 * @brief File contains some general purpose functions
8 * @since 12.01.2022
9 ***********************************************************************************************************/
10
11#include <iomanip>
12#include <map>
13#include <sstream>
14#include <string>
15#include <unordered_map>
16
21template<class Key, class T, class Hash = std::hash<Key>>
22void SetSingleValueToMap(Key key, T value, std::unordered_map<Key, T, Hash>& aMap)
23{
24 aMap[key] = value;
25}
26
30template<class Key, class T, class Hash = std::hash<Key>>
31void SetSameValueToMap(T value, std::unordered_map<Key, T, Hash>& aMap)
32{
33 for (auto it = aMap.begin(); it != aMap.end(); ++it) {
34 it->second = value;
35 }
36}
37
41template<class Key, class T, class Hash = std::hash<Key>>
42void SetMappedValuesToMap(const std::unordered_map<Key, T, Hash>& inMap, std::unordered_map<Key, T, Hash>& aMap)
43{
44 for (auto it = aMap.begin(); it != aMap.end(); ++it) {
45 if (inMap.find(it->first) != inMap.end()) {
46 it->second = inMap.at(it->first);
47 }
48 }
49}
50
53template<class Key, class T, class Hash = std::hash<Key>>
54std::string RepresentMapWithString(const std::unordered_map<Key, T, Hash>& aMap, int entryWidth = 15)
55{
56 std::stringstream token;
57 for (auto it = aMap.begin(); it != aMap.end(); ++it) {
58 token << std::setw(entryWidth) << std::setfill(' ') << it->second << ' ';
59 }
60 return token.str();
61}
std::string RepresentMapWithString(const std::unordered_map< Key, T, Hash > &aMap, int entryWidth=15)
void SetSingleValueToMap(Key key, T value, std::unordered_map< Key, T, Hash > &aMap)
void SetSameValueToMap(T value, std::unordered_map< Key, T, Hash > &aMap)
void SetMappedValuesToMap(const std::unordered_map< Key, T, Hash > &inMap, std::unordered_map< Key, T, Hash > &aMap)