Bitwise XOR Monoid
(monoid/xor.hpp)
- View this file on GitHub
- Last update: 2026-07-21 20:17:47+09:00
- Include:
#include "monoid/xor.hpp"
Overview
A monoid representing the bitwise XOR operation.
Template Parameters
-
T: The underlying integer data type.
Properties
- Operation: Bitwise XOR ($a \ \text{\textasciicircum} \ b$)
- Identity Element: $0$
Interface and Complexity
This is a stateless algebra tag. Generic data structures use its public
value_type, id(), and op(a, b) members. If the type also provides helpers
such as make(...) or inv(x), they are described above or in the documented
properties.
Each static operation runs in the cost of the underlying operation shown in the
properties. Scalar monoids are $O(1)$; monoids whose value_type stores several
items, permutations, or matrices scale with that stored size.
Verified with
verify/ds/dsu/persistent_potentialized_dsu.test.cpp
verify/ds/dsu/potentialized_dsu.test.cpp
verify/graph/tree/vertex_add_range_contour_sum_on_tree.test.cpp
verify/graph/tree/vertex_get_range_contour_add_on_tree.test.cpp
verify/monoid/commutative_flags.test.cpp
Code
#ifndef M1UNE_MONOID_XOR_HPP
#define M1UNE_MONOID_XOR_HPP 1
namespace m1une {
namespace monoid {
// Monoid for bitwise XOR (Range XOR).
template <typename T>
struct Xor {
using value_type = T;
static constexpr bool commutative = true;
// Returns the identity element for bitwise XOR, which is 0.
static constexpr T id() {
return T(0);
}
// Returns the bitwise XOR of a and b.
static constexpr T op(const T& a, const T& b) {
return a ^ b;
}
static constexpr T inv(const T& x) {
return x;
}
};
} // namespace monoid
} // namespace m1une
#endif // M1UNE_MONOID_XOR_HPP#line 1 "monoid/xor.hpp"
namespace m1une {
namespace monoid {
// Monoid for bitwise XOR (Range XOR).
template <typename T>
struct Xor {
using value_type = T;
static constexpr bool commutative = true;
// Returns the identity element for bitwise XOR, which is 0.
static constexpr T id() {
return T(0);
}
// Returns the bitwise XOR of a and b.
static constexpr T op(const T& a, const T& b) {
return a ^ b;
}
static constexpr T inv(const T& x) {
return x;
}
};
} // namespace monoid
} // namespace m1une