#include "ehs/Type.h" namespace ehs { Type::Type() : size(0), id(nullptr), hashId(0) { } Type::Type(const Char_8* const id) : size(CalcSize(id)), id(id), hashId(GenHash(id, size)) { } Type::Type(Type&& type) noexcept : size(type.size), id(type.id), hashId(type.hashId) { type.size = 0; type.id = nullptr; type.hashId = 0; } Type::Type(const Type& type) : size(type.size), id(type.id), hashId(type.hashId) { } Type& Type::operator=(Type&& type) noexcept { if (this == &type) return *this; size = type.size; id = type.id; hashId = type.hashId; type.size = 0; type.id = nullptr; type.hashId = 0; return *this; } Type& Type::operator=(const Type& type) { if (this == &type) return *this; size = type.size; id = type.id; hashId = type.hashId; return *this; } bool Type::operator==(const Type& type) const { return hashId == type.hashId; } bool Type::operator!=(const Type& type) const { return hashId != type.hashId; } bool Type::operator==(const UInt_64 inHashId) const { return hashId == inHashId; } bool Type::operator!=(const UInt_64 inHashId) const { return hashId != inHashId; } bool Type::operator==(const Char_8* const inStr) const { if (size != CalcSize(inStr)) return false; return Util::Compare(id, inStr, size); } bool Type::operator!=(const Char_8* const inStr) const { if (size != CalcSize(inStr)) return true; return !Util::Compare(id, inStr, size); } UInt_64 Type::GetSize() const { return size; } const Char_8* Type::GetId() const { return id; } UInt_64 Type::GetHashId() const { return hashId; } bool Type::IsValid() const { return size; } UInt_64 Type::CalcSize(const Char_8* const id) { UInt_64 result = 0; while (id[result]) result++; return result; } UInt_64 Type::GenHash(const Char_8* const id, const UInt_64 size) { if (!size) return 0; const Byte* const bytes = (Byte*)id; UInt_64 hash = 14695981039346656037ull; for (UInt_64 i = 0; i < size; ++i) hash = (hash ^ bytes[i]) * 1099511628211; return hash; } }