// Copyright (c) 2022 Johannes Stoelp #ifndef UTILS_H #define UTILS_H #include // Convert from an underlying enum type into an enum variant. template constexpr E from_raw(std::underlying_type_t u) { static_assert(std::is_enum_v); return static_cast(u); } // Convert from an enum variant into an underlying enum type. template constexpr std::underlying_type_t into_raw(E e) { static_assert(std::is_enum_v); return static_cast>(e); } // Simple cyclic rotation hash function. constexpr u32 hash(const u8* data, usize len) { u32 hash = 0xa5a55a5a /* seed */; for (usize i = 0; i < len; ++i) { hash += ((hash << 25) | (hash >> 7) /* rrot(7) */) ^ data[i]; } return hash; } #endif