mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:57:44 +00:00
LibUnicode: Define traits for a vector of integral/enum types
Any generator which defines a unique storage instance for a list of numbers will need this.
This commit is contained in:
parent
6bf50bc40b
commit
415763b1b3
2 changed files with 22 additions and 14 deletions
|
@ -130,20 +130,6 @@ struct AK::Traits<NumberFormat> : public GenericTraits<NumberFormat> {
|
||||||
};
|
};
|
||||||
|
|
||||||
using NumberFormatList = Vector<NumberFormatIndexType>;
|
using NumberFormatList = Vector<NumberFormatIndexType>;
|
||||||
|
|
||||||
template<>
|
|
||||||
struct AK::Traits<NumberFormatList> : public GenericTraits<NumberFormatList> {
|
|
||||||
static unsigned hash(NumberFormatList const& formats)
|
|
||||||
{
|
|
||||||
auto hash = int_hash(static_cast<u32>(formats.size()));
|
|
||||||
|
|
||||||
for (auto format : formats)
|
|
||||||
hash = pair_int_hash(hash, format);
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
using NumericSymbolList = Vector<StringIndexType>;
|
using NumericSymbolList = Vector<StringIndexType>;
|
||||||
|
|
||||||
struct NumberSystem {
|
struct NumberSystem {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
|
#include <AK/HashFunctions.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
#include <AK/SourceGenerator.h>
|
#include <AK/SourceGenerator.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
#include <AK/Traits.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibCore/DirIterator.h>
|
#include <LibCore/DirIterator.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
|
@ -25,6 +27,26 @@ inline constexpr bool StorageTypeIsList = false;
|
||||||
template<class T>
|
template<class T>
|
||||||
inline constexpr bool StorageTypeIsList<Vector<T>> = true;
|
inline constexpr bool StorageTypeIsList<Vector<T>> = true;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept IntegralOrEnum = Integral<T> || Enum<T>;
|
||||||
|
|
||||||
|
template<IntegralOrEnum T>
|
||||||
|
struct AK::Traits<Vector<T>> : public GenericTraits<Vector<T>> {
|
||||||
|
static unsigned hash(Vector<T> const& list)
|
||||||
|
{
|
||||||
|
auto hash = int_hash(static_cast<u32>(list.size()));
|
||||||
|
|
||||||
|
for (auto value : list) {
|
||||||
|
if constexpr (Enum<T>)
|
||||||
|
hash = pair_int_hash(hash, to_underlying(value));
|
||||||
|
else
|
||||||
|
hash = pair_int_hash(hash, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename StorageType, typename IndexType>
|
template<typename StorageType, typename IndexType>
|
||||||
class UniqueStorage {
|
class UniqueStorage {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue