Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚸 small improvements to Control and Permutation bindings #593

Merged
merged 3 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions include/mqt-core/Permutation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "Definitions.hpp"
#include "operations/Control.hpp"

#include <cstddef>
#include <functional>
#include <map>

namespace qc {
Expand Down Expand Up @@ -30,3 +32,17 @@ class Permutation : public std::map<Qubit, Qubit> {
}
};
} // namespace qc

// define hash function for Permutation
namespace std {
template <> struct hash<qc::Permutation> {
std::size_t operator()(const qc::Permutation& p) const {
std::size_t seed = 0;
for (const auto& [k, v] : p) {
qc::hashCombine(seed, k);
qc::hashCombine(seed, v);
}
return seed;
}
};
} // namespace std
12 changes: 12 additions & 0 deletions include/mqt-core/operations/Control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

#include "Definitions.hpp"

#include <cstddef>
#include <functional>
#include <set>
#include <sstream>
#include <string>

namespace qc {
struct Control {
Expand Down Expand Up @@ -73,3 +76,12 @@ inline Control operator""_nc(unsigned long long int q) {
}
} // namespace literals
} // namespace qc

namespace std {
template <> struct hash<qc::Control> {
std::size_t operator()(const qc::Control& c) const {
return std::hash<qc::Qubit>{}(c.qubit) ^
std::hash<qc::Control::Type>{}(c.type);
}
};
} // namespace std
Loading
Loading