From 3256b7fe1100e02e3ebbc6831b9640df2b7779ab Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 12 Oct 2011 03:47:34 +0200 Subject: [PATCH] implementing the hash functions for the buffer metadata content fields --- src/proc/engine/buffer-metadata.hpp | 47 ++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/src/proc/engine/buffer-metadata.hpp b/src/proc/engine/buffer-metadata.hpp index a257f6a8c..024343ea2 100644 --- a/src/proc/engine/buffer-metadata.hpp +++ b/src/proc/engine/buffer-metadata.hpp @@ -57,6 +57,7 @@ #include "lib/error.hpp" #include "lib/symbol.hpp" +#include #include #include @@ -64,6 +65,7 @@ namespace engine { using lib::Literal; + using std::tr1::function; namespace error = lumiera::error; @@ -98,27 +100,57 @@ namespace engine { { } operator uint64_t() const { return privateID_; } + + friend size_t + hash_value (LocalKey const& lkey) + { + boost::hash hashFunction; + return hashFunction(lkey.privateID_); + } }; + template + void + buildIntoBuffer (void* storageBuffer) + { + new(storageBuffer) X(); + } + + template + void + destroyInBuffer (void* storageBuffer) + { + X* embedded = static_cast (storageBuffer); + embedded->~X(); + } struct TypeHandler { - typedef void (*Ctor) (void*); - typedef void (*Dtor) (void*); + typedef function Ctor; + typedef function Dtor; Ctor createAttached; Dtor destroyAttached; TypeHandler() - : createAttached (0) - , destroyAttached (0) + : createAttached() + , destroyAttached() { } template TypeHandler() - : createAttached (0) /////////TODO: how to attach the ctor function??? Maybe better use a class with virtual functions? - , destroyAttached (0) + : createAttached (buildIntoBuffer) + , destroyAttached (destroyInBuffer) { } + + friend size_t + hash_value (TypeHandler handler) + { + boost::hash ctorHash; +// return boost::hash_combine(ctorHash(handler.createAttached), handler.destroyAttached.); + ////////////////TODO how to calculate the hash of an function object + return 0; + } }; namespace { // internal constants to mark the default case @@ -140,7 +172,8 @@ namespace engine { HashVal chainedHash(HashVal accumulatedHash, VAL changedValue) { - UNIMPLEMENTED ("calculate a new hash value, based on parent hash"); + boost::hash_combine (accumulatedHash, changedValue); + return accumulatedHash; } }