cp-documentation

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub zawa-tin/cp-documentation

:heavy_check_mark: Test/My/Utility/U32Pair.test.cpp

Depends on

Code

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/1/ITP1_1_A"

#include "../../../Src/Utility/U32Pair.hpp"

#include <cassert>
#include <iostream>
#include <unordered_set>
#include <limits>

int main() {
    using namespace zawa;
    std::unordered_set<U32Pair, U32PairHash> set;
    U32Pair a{ 1, 1 }, b{ 2, 0 }, c{ 0, 1 };
    assert(a.first() == 1);
    assert(a.second() == 1);
    assert(b.first() == 2);
    assert(b.second() == 0);
    assert(c.first() == 0);
    assert(c.second() == 1);
    set.insert(a);
    set.insert(b);
    set.insert(c);
    assert(set.find(a) != set.end());
    assert(set.find(b) != set.end());
    assert(set.find(c) != set.end());
    assert(set.find(U32Pair{ 99, 99 }) == set.end());
    u32 max{std::numeric_limits<u32>::max()};
    U32Pair maxPair{max, max};
    assert(maxPair.first() == max);
    assert(maxPair.second() == max);
    std::cout << "Hello World" << '\n';
}
#line 1 "Test/My/Utility/U32Pair.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/1/ITP1_1_A"

#line 2 "Src/Utility/U32Pair.hpp"

#line 2 "Src/Template/TypeAlias.hpp"

#include <cstdint>
#include <cstddef>

namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa
#line 4 "Src/Utility/U32Pair.hpp"

#include <functional>
#include <iostream>

namespace zawa {

class U32Pair {
private:
    static constexpr u32 SHIFT{32};
    static constexpr u32 MASK{static_cast<u32>((1LL << SHIFT) - 1)};
    u64 value_{};
public:
    constexpr U32Pair() {}
    constexpr U32Pair(u32 first, u32 second) {
        value_ = (static_cast<u64>(first) << SHIFT) | second;
    }
    constexpr u32 first() const noexcept {
        return static_cast<u32>(value_ >> SHIFT);
    }
    constexpr u32 second() const noexcept {
        return static_cast<u32>(value_ & MASK);
    }
    constexpr u64 combined() const noexcept {
        return value_;
    }
    constexpr U32Pair& operator=(const U32Pair& rhs) {
        value_ = rhs.value_;
        return *this;
    }
    friend constexpr bool operator==(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ == rhs.value_;
    }
    friend constexpr bool operator!=(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ != rhs.value_;
    }
    friend constexpr bool operator<(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ < rhs.value_;
    }
    friend constexpr bool operator<=(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ <= rhs.value_;
    }
    friend constexpr bool operator>(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ > rhs.value_;
    }
    friend constexpr bool operator>=(const U32Pair& lhs, const U32Pair& rhs) {
        return lhs.value_ >= rhs.value_;
    }
    friend std::ostream& operator<<(std::ostream& os, const U32Pair& pair) {
        os << '(' << pair.first() << ',' << pair.second() << ')';
        return os;
    }
};

struct U32PairHash {
    usize operator()(const U32Pair& pair) const noexcept {
        return std::hash<u64>{}(pair.combined());
    }
};

} // namespace zawa
#line 4 "Test/My/Utility/U32Pair.test.cpp"

#include <cassert>
#line 7 "Test/My/Utility/U32Pair.test.cpp"
#include <unordered_set>
#include <limits>

int main() {
    using namespace zawa;
    std::unordered_set<U32Pair, U32PairHash> set;
    U32Pair a{ 1, 1 }, b{ 2, 0 }, c{ 0, 1 };
    assert(a.first() == 1);
    assert(a.second() == 1);
    assert(b.first() == 2);
    assert(b.second() == 0);
    assert(c.first() == 0);
    assert(c.second() == 1);
    set.insert(a);
    set.insert(b);
    set.insert(c);
    assert(set.find(a) != set.end());
    assert(set.find(b) != set.end());
    assert(set.find(c) != set.end());
    assert(set.find(U32Pair{ 99, 99 }) == set.end());
    u32 max{std::numeric_limits<u32>::max()};
    U32Pair maxPair{max, max};
    assert(maxPair.first() == max);
    assert(maxPair.second() == max);
    std::cout << "Hello World" << '\n';
}
Back to top page