TMap is exactly what I need considering it works similar to the stl::map. The issue is that it seemes to work a bit differently. I get that it sorts based on hashes. What do I need to implement for my custom struct to be used as a key? The documentation is less than helpful. TMap | Unreal Engine Documentation
Here you go:
TMap<struct FBoneIndexPair, TArray<uint32> > VertexInfluenceMapping;
/**
* A pair of bone indices
*/
struct FBoneIndexPair
{
int32 BoneIdx[2];
bool operator==(const FBoneIndexPair& Src) const
{
return (BoneIdx[0] == Src.BoneIdx[0]) && (BoneIdx[1] == Src.BoneIdx[1]);
}
friend FORCEINLINE uint32 GetTypeHash( const FBoneIndexPair& BonePair )
{
return FCrc::MemCrc_DEPRECATED(&BonePair, sizeof(FBoneIndexPair));
}
/**
* Serialize to Archive
*/
friend FArchive& operator<<( FArchive& Ar, FBoneIndexPair& W )
{
return Ar << W.BoneIdx[0] << W.BoneIdx[1];
}
};
I think the most important part of this struct is == operator.
You are correct! I did not have the == operator implemented correctly.
Exactly what I needed! Made a version based on Cantor pairs without the deprecated cyclic redundancy thing. Perhaps a tiny bit less performant, but should work well for bounded indices like the ones above:
friend FORCEINLINE uint32 GetTypeHash(const IndexPair& indexPair)
{
return (indexPair.key + indexPair.value) * (indexPair.key + indexPair.value + 1) / 2 + indexPair.value;
}