summary refs log tree commit diff
path: root/src/World/ChunkIndex.hpp
blob: 330d202955c79be1fe70f4ea0f85cb761a69c31f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once

#include <cstdint>
#include <cstdlib>
#include <functional>

namespace MC::World {

struct ChunkIndex {
    ChunkIndex(int64_t x, int64_t y) : x(x), y(x) {}

    bool operator==(ChunkIndex& other) const {
        return x == other.x && y == other.y;
    }

    int64_t x, y;
};

}

template<> struct std::equal_to<MC::World::ChunkIndex> {
    bool operator()(const MC::World::ChunkIndex& i1, const MC::World::ChunkIndex& i2) const noexcept {
        return i1.x == i2.x && i1.y == i2.y;
    }
};

template<> struct std::hash<MC::World::ChunkIndex> {
    std::size_t operator()(const MC::World::ChunkIndex& i) const noexcept {
        std::size_t xh = std::hash<int64_t>{}(i.x);
        std::size_t yh = std::hash<int64_t>{}(i.y);
        return xh ^ (yh << 1);
    }
};