Ticket #11015: bgl_csr_edge_hash_fix.h

File bgl_csr_edge_hash_fix.h, 825 bytes (added by djh, 7 years ago)

Hashable Edge POC for Compressed Sparse Row Graph

Line 
1#pragma once
2
3#include <cstddef>
4#include <type_traits>
5#include <limits>
6
7
8// Specializing hash<> for user-defined type in std namespace, this is standard conforming.
9namespace std {
10
11template <typename Vertex, typename EdgeIndex>
12struct hash<boost::detail::csr_edge_descriptor<Vertex, EdgeIndex>> {
13 std::size_t operator()(const boost::detail::csr_edge_descriptor<Vertex, EdgeIndex>& edge_descriptor) const noexcept {
14
15 static_assert(std::is_unsigned<EdgeIndex>(),
16 "An unsigned EdgeIndex is required for simple hashing returning the edge descriptor's index");
17 static_assert(std::numeric_limits<EdgeIndex>::max() <= std::numeric_limits<std::size_t>::max(),
18 "EdgeIndex too large for simple hashing returning the edge descriptor's index");
19
20 return edge_descriptor.idx;
21 }
22};
23}