x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How To Use TMap?

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. https://docs.unrealengine.com/latest/INT/API/Runtime/Core/Containers/TMap/index.html

Product Version: Not Selected
Tags:
more ▼

asked Sep 21 '14 at 01:31 AM in C++ Programming

avatar image

MJ_01
827 38 40 242

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Sep 21 '14 at 08:49 AM

avatar image

Pierdek
2.6k 73 49 131

avatar image MJ_01 Sep 21 '14 at 04:51 PM

You are correct! I did not have the == operator implemented correctly.

avatar image j_zeitler Oct 17 '16 at 03:43 PM

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;
     }
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question