[Feat] 增加容器 List, Map, 以及对应Hash

[Impl] Addressable/Unaddressable Error现在内部存储FString而非View
This commit is contained in:
2025-12-25 17:10:12 +08:00
parent ab4024c2bf
commit f056b0ffbe
18 changed files with 583 additions and 179 deletions

View File

@@ -25,6 +25,50 @@ namespace Fig
}
}
size_t ValueKeyHash::operator()(const ValueKey &key) const
{
{
ObjectPtr value = key.value;
const TypeInfo &type = value->getTypeInfo();
if (type == ValueType::Int)
{
return std::hash<ValueType::IntClass>{}(value->as<ValueType::IntClass>());
}
if (type == ValueType::Double)
{
return std::hash<ValueType::DoubleClass>{}(value->as<ValueType::DoubleClass>());
}
if (type == ValueType::String)
{
return std::hash<ValueType::StringClass>{}(value->as<ValueType::StringClass>());
}
if (type == ValueType::Bool)
{
return std::hash<ValueType::BoolClass>{}(value->as<ValueType::BoolClass>());
}
if (type == ValueType::StructType)
{
auto HashFields = [](std::vector<Field> fields) {
size_t r = 0;
for (auto &f : fields)
{
r += std::hash<Field>{}(f);
}
return r;
};
const StructType &st = value->as<StructType>();
return std::hash<std::size_t>{}(st.id) + HashFields(st.fields);
}
if (type == ValueType::StructInstance)
{
const StructInstance &si = value->as<StructInstance>();
return std::hash<std::size_t>{}(si.parentId) + std::hash<uint64_t>{}(reinterpret_cast<uint64_t>(std::addressof(*si.localContext)));
}
assert(false);
}
}
const TypeInfo ValueType::Any(FString(u8"Any"), true); // id: 1
const TypeInfo ValueType::Null(FString(u8"Null"), true); // id: 2
const TypeInfo ValueType::Int(FString(u8"Int"), true); // id: 3
@@ -36,5 +80,5 @@ namespace Fig
const TypeInfo ValueType::StructInstance(FString(u8"StructInstance"), true); // id: 9
const TypeInfo ValueType::List(FString(u8"List"), true); // id: 10
const TypeInfo ValueType::Map(FString(u8"Map"), true); // id: 11
const TypeInfo ValueType::Tuple(FString(u8"Tuple"), true); // id: 12
// const TypeInfo ValueType::Tuple(FString(u8"Tuple"), true); // id: 12
} // namespace Fig