openjij
Framework for the Ising model and QUBO.
Loading...
Searching...
No Matches
insert_or_assign.hpp
Go to the documentation of this file.
1// Copyright 2023 Jij Inc.
2
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6
7// http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <unordered_map>
18
19namespace openjij {
20namespace utility {
21
33template <class C_key, class C_value, class Hash>
34inline void insert_or_assign(std::unordered_map<C_key, C_value, Hash> &um,
35 const C_key &key, const C_value &val) {
36 // insert
37 if (um.count(key) == 0) {
38 um.insert({{key, val}});
39 }
40 // assign
41 else {
42 um[key] = val;
43 }
44}
45} // namespace utility
46} // namespace openjij
void insert_or_assign(std::unordered_map< C_key, C_value, Hash > &um, const C_key &key, const C_value &val)
Insert or assign a element of unordered_map (for C++14 or C++11)
Definition insert_or_assign.hpp:34
Definition algorithm.hpp:24