Skip to content

Instantly share code, notes, and snippets.

@loganek
Created May 27, 2018 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loganek/2692742098dad0cd3dceb0fb43406ddb to your computer and use it in GitHub Desktop.
Save loganek/2692742098dad0cd3dceb0fb43406ddb to your computer and use it in GitHub Desktop.
struct Font
{
std::string name;
uint16_t size;
bool is_bold;
bool is_italic;
};
bool operator==(const Font& f1, const Font& f2)
{
return
f1.name == f2.name &&
f1.size == f2.size &&
f1.is_bold == f2.is_bold &&
f1.is_italic == f2.is_italic;
}
uint32_t djb2(const std::string& text) { return 0 /* TODO */; }
namespace std {
template <>
struct hash<Font>
{
std::size_t operator()(const Font& font) const
{
int64_t hash = djb2(font.name);
hash |= (static_cast<uint64_t>(font.size) << 32);
hash |= (static_cast<uint64_t>(font.is_bold)) << 48;
hash |= (static_cast<uint64_t>(font.is_bold)) << 56;
return static_cast<std::size_t>(hash);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment