Page 1 of 1

Hashmap and NodeId

Posted: 10 Jan 2013, 11:02
by dy_100000
Hello, support team:

I'm implementing an index table class that can map the UaNodeId(principally String format) to integer ID, this index table is used to find the ID of a historian server tag or an IO server tag. And I prefer to use a hash table(boost unordered_map) instead of STL map. Because it is much more fast.

For a hash table, I need to implement the hash algorithm for the class UaNodeId, and the best way is to get the native OpcUa_NodeId inside the UaNodeId and hash it accord it's identity type(String, Integer or ByteString).

But I'm a little confused when I hash the struct type OpcUa_String:

typedef struct _OpcUa_String
{
OpcUa_UInt16 uReserved1;
OpcUa_UInt32 uReserved2;
OpcUa_Void* uReserved4;
} OpcUa_String, *OpcUa_pString;

What does each variable means?

And if you have some code to do this, can you please give me a hint?

Thanks a lot.

Re:Hashmap and NodeId

Posted: 10 Jan 2013, 12:30
by cacamille3
I think the OpcUa_String structure is as following

#ifdef _DEBUG
typedef struct _OpcUa_String
{
OpcUa_UInt16 flags;
OpcUa_UInt32 uLength;
OpcUa_Char* strContent;
}OpcUa_String, *OpcUa_pString;
#else
typedef struct
_OpcUa_String
{
OpcUa_UInt16 uReserved1;
OpcUa_UInt32 uReserved2;
OpcUa_Void* uReserved4;
} OpcUa_String, *OpcUa_pString;
#endif

So just define _DEBUG to 1 and you could use it a bit easily...

Regards.

CG

Re:Hashmap and NodeId

Posted: 10 Jan 2013, 16:37
by Support Team
Hello,

first of all, the members of an OpcUa_String should never be used directly, this is why the definition of the OpcUa_String is different in Debug and Release. Instead, only the string manipulation functions from 'opcua_string.h' should be used for working with OpcUa_String structures.

The different naming of the members in a debug configuration is for debugging purposes only. The _DEBUG define is set by the projects delivered with the SDK and should not be set in release configuration.

The SDK already includes a HashTable class (src/uabase/uabasecpp/hashtable.h) which is especially designed for hashing UaNodeIds. This should be the class you are looking for.

If the HashTable class does not meet your requirements you can retreive the string content of the OpcUa_String using the function 'OpcUa_String_GetRawString()'. Please note that a OpcUa_String is not guaranteed to be null-terminated, hence you must take the string length into account.

Best regards,
Unified Automation Support Team

Re: Hashmap and NodeId

Posted: 23 Aug 2019, 11:34
by kahydo
thanks

Re: Hashmap and NodeId

Posted: 14 Oct 2023, 15:22
by JasonHernandez
thanks forpsoting