>From b0d0783d0be7d4964e1f4df66b8bddbbff677397 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lebel Date: Fri, 20 Feb 2015 16:05:34 -0500 Subject: [PATCH 2/4] added implementation to the HASH function for the HLA1516e handles --- libRTI/ieee1516-2010/HandleImplementation.cpp | 17 +++++++++++++++++ libRTI/ieee1516-2010/HandleImplementation.h | 4 +++- 2 files changed, 20 insertions(+), 1 deletions(-) diff --git a/libRTI/ieee1516-2010/HandleImplementation.cpp b/libRTI/ieee1516-2010/HandleImplementation.cpp index e5c80a3..21e89d3 100644 --- a/libRTI/ieee1516-2010/HandleImplementation.cpp +++ b/libRTI/ieee1516-2010/HandleImplementation.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "HandleImplementation.h" #include "RTIvariableLengthDataImplementation.h" @@ -82,6 +83,22 @@ bool HandleImplementation::isValid() const return true; } +/* Generate a hash value for use in storing handles in a */ +/* in a hash table. */ +/* Note: The hash value may not be unique across two */ +/* separate handle values but it will be equal given two */ +/* separate instances of the same handle value. */ +/* H1 == H2 implies H1.hash() == H2.hash() */ +/* H1 != H2 does not imply H1.hash() != H2.hash() */ +long HandleImplementation::hash () const +{ + //from + // more details at http://www.cplusplus.com/reference/functional/hash/ + //should think about a non-c++11 approch if needed + std::hash localhash; + return localhash(toString()); +} + /* Generate an encoded value that can be used to send */ /* handles to other federates in updates or interactions. */ VariableLengthData HandleImplementation::encode() const diff --git a/libRTI/ieee1516-2010/HandleImplementation.h b/libRTI/ieee1516-2010/HandleImplementation.h index e10376c..d2c604d 100644 --- a/libRTI/ieee1516-2010/HandleImplementation.h +++ b/libRTI/ieee1516-2010/HandleImplementation.h @@ -65,7 +65,9 @@ namespace rti1516e /* Generate an encoded value that can be used to send */ /* handles to other federates in updates or interactions. */ virtual VariableLengthData encode() const; - + + long HandleImplementation::hash () const ; + /* Alternate encode for directly filling a buffer */ virtual unsigned long encodedLength() const; virtual unsigned long encode( -- 1.7.8