CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418425
1
/*
2
* Normaliz
3
* Copyright (C) 2007-2014 Winfried Bruns, Bogdan Ichim, Christof Soeger
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*
17
* As an exception, when this program is distributed through (i) the App Store
18
* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play
19
* by Google Inc., then that store may impose any digital rights management,
20
* device limits and/or redistribution restrictions that are required by its
21
* terms of service.
22
*/
23
24
//---------------------------------------------------------------------------
25
26
#ifndef MAP_OPERATIONS_H
27
#define MAP_OPERATIONS_H
28
29
//---------------------------------------------------------------------------
30
31
#include <map>
32
#include <ostream>
33
34
namespace libQnormaliz {
35
using std::map;
36
using std::vector;
37
38
template<typename key, typename T>
39
std::ostream& operator<< (std::ostream& out, const map<key, T> M) {
40
typename map<key, T>::const_iterator it;
41
for (it = M.begin(); it != M.end(); ++it) {
42
out << it->first << ": " << it-> second << " ";
43
}
44
out << std::endl;
45
return out;
46
}
47
48
//---------------------------------------------------------------------------
49
50
template<typename key, typename T>
51
bool exists_element(const map<key, T>& m, const key& k){
52
return (m.find(k) != m.end());
53
}
54
55
//---------------------------------------------------------------------------
56
57
template<typename key, typename T>
58
map<key, T> count_in_map (const vector<key> v) {
59
map<key, T> m;
60
T size = v.size();
61
for (T i = 0; i < size; ++i) {
62
m[v[i]]++;
63
}
64
return m;
65
}
66
67
template<typename key, typename T>
68
vector<key> to_vector (const map<key, T> M) {
69
vector<key> v;
70
typename map<key, T>::const_iterator it;
71
for (it = M.begin(); it != M.end(); ++it) {
72
for (T i = 0; i < it->second; i++) {
73
v.push_back(it->first);
74
}
75
}
76
return v;
77
}
78
79
} //end namespace
80
81
//---------------------------------------------------------------------------
82
#endif
83
//---------------------------------------------------------------------------
84
85