refactor use of HashVal typedef (#722)

This commit is contained in:
Fischlurch 2012-12-02 23:03:37 +01:00
parent 5292b19dd6
commit a79ba2c507
25 changed files with 232 additions and 133 deletions

View file

@ -77,6 +77,7 @@
#include "lib/error.hpp"
#include "lib/symbol.hpp"
#include "lib/hash-value.h"
#include "common/query.hpp"
#include <iostream>
@ -88,8 +89,7 @@ namespace advice {
using lib::Literal;
using std::string;
typedef size_t HashVal;
using lib::HashVal;
LUMIERA_ERROR_DECLARE (BINDING_PATTERN_SYNTAX); ///< Unable to parse the given binding pattern definition

View file

@ -37,15 +37,13 @@
#ifndef FUNCTOR_UTIL_H_
#define FUNCTOR_UTIL_H_
#include "lib/hash-value.h"
#include <tr1/functional>
#include <boost/functional/hash.hpp>
namespace lib {
typedef size_t HashVal;
}
namespace util { ////////////TODO: refactor namespace. But probably not directly into namespace lib. Needs some more consideration though
using std::tr1::function;

View file

@ -1,48 +1,33 @@
/*
hash_fnv.c - FNV hash functions
HashFNV - FNV hash functions
Copyright (C)
2010, 2011, Christian Thaeter <ct@pipapo.org>
adapted by Lumiera.org
2010, 2011 Christian Thaeter <ct@pipapo.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
original by chongo <Landon Curt Noll> /\oo/\
http://www.isthe.com/chongo/
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Please do not copyright this code. This code is in the public domain.
You should have received a copy of the GNU General Public License
along with this program; if not, contact Christian Thaeter <ct@pipapo.org>.
LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
The actual fnv functions are taken from Landon Curt Noll's original code,
slightly modified and adapted to C99; no copyright applies:
***
*
* Please do not copyright this code. This code is in the public domain.
*
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
* EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* By:
* chongo <Landon Curt Noll> /\oo/\
* http://www.isthe.com/chongo/
*
* Share and Enjoy! :-)
*/
Share and Enjoy! :-)
* *****************************************************/
#include "lib/hash-fnv.h"
#include <nobug.h>
uint64_t
hash_fnv64a_buf (const void *buf, size_t len, uint64_t hval)
{

View file

@ -1,45 +1,31 @@
/*
HASH-FNV.h - FNV hash functions
HASH-FNV.h - FNV hash functions
Copyright (C)
2010, 2011, Christian Thaeter <ct@pipapo.org>
adapted by Lumiera.org
2010, 2011 Christian Thaeter <ct@pipapo.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
original by chongo <Landon Curt Noll> /\oo/\
http://www.isthe.com/chongo/
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Please do not copyright this code. This code is in the public domain.
You should have received a copy of the GNU General Public License
along with this program; if not, contact Christian Thaeter <ct@pipapo.org>.
LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
Share and Enjoy! :-)
The actual fnv functions are taken from Landon Curt Noll's original code, no copyright applies:
***
*
* Please do not copyright this code. This code is in the public domain.
*
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
* EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* By:
* chongo <Landon Curt Noll> /\oo/\
* http://www.isthe.com/chongo/
*
* Share and Enjoy! :-)
*/
/**
* @file
* Fowler / Noll / Vo (FNV) Hashes
* @file hash-fnv.h
* Fowler-Noll-Vo Hashes.
* is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Phong Vo.
*/

View file

@ -54,9 +54,12 @@
#ifndef LIB_HASH_INDEXED_H
#define LIB_HASH_INDEXED_H
#include "lib/hash-value.h"
extern "C" {
#include "lib/luid.h"
}
#include <functional>
@ -73,10 +76,10 @@ namespace lib {
*/
class Plain
{
const size_t hash_;
const HashVal hash_;
public:
Plain (size_t val)
Plain (HashVal val)
: hash_(val)
{ }
@ -85,7 +88,7 @@ namespace lib {
: hash_(hash_value (something)) // ADL
{ }
operator size_t() const { return hash_; }
operator HashVal() const { return hash_; }
};
/**
@ -103,9 +106,7 @@ namespace lib {
ENSURE (0 < lumiera_uid_hash(&luid_));
}
typedef lumiera_uid* LUID;
operator size_t () const { return lumiera_uid_hash (get()); }
operator HashVal() const { return lumiera_uid_hash (get()); }
bool operator== (LuidH const& o) const { return lumiera_uid_eq (get(), o.get()); }
bool operator!= (LuidH const& o) const { return !operator== (o); }
@ -115,8 +116,8 @@ namespace lib {
/* === for use within unordered_map === */
inline size_t hash_value (Plain const& plainHash) { return plainHash; }
inline size_t hash_value (LuidH const& luid_Hash) { return luid_Hash; }
inline HashVal hash_value (Plain const& plainHash) { return plainHash; }
inline HashVal hash_value (LuidH const& luid_Hash) { return luid_Hash; }
} // namespace "hash"
@ -155,16 +156,16 @@ namespace lib {
/** enables use of BA objects as keys within tr1::unordered_map */
struct UseEmbeddedHash
: public std::unary_function<BA, size_t>
: public std::unary_function<BA, HashVal>
{
size_t operator() (BA const& obj) const { return obj.getID(); }
HashVal operator() (BA const& obj) const { return obj.getID(); }
};
/** trivial hash functor using the ID as hash */
struct UseHashID
: public std::unary_function<ID, size_t>
: public std::unary_function<ID, HashVal>
{
size_t operator() (ID const& id) const { return id; }
HashVal operator() (ID const& id) const { return id; }
};

89
src/lib/hash-value.h Normal file
View file

@ -0,0 +1,89 @@
/*
HASH-UTIL.hpp - collection of tools and definitions for working with hashes
Copyright (C) Lumiera.org
2012, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file hash-util.h
** Hash value types and utilities.
** This header defines the basic hash value types and provides some simple
** utilities to support working with hash valuesWhile the actual storage is assumed to be based on a POD, the type info is crucial
** to circumvent the problems with an "object" base class. Frequently, the need to
** manage some objects in a central facility drives us to rely on a common base class,
** irrespective of an actual common denominator in the semantics of the objects to
** be managed within this collection. Typically this results in this common base class
** being almost worthless as an API or interface, causing lots of type casts when using
** such a common object management facility. Passing additional context or API information
** on a metaprogramming level through the management interface helps avoiding these
** shortcomings.
**
** Here we build an ID facility with the following properties:
** - based on a configurable storage/implementation of the actual hash or index code.
** - tied to a specific hierarchy of objects (template parameter "BA")
** - providing an additional template parameter to pass the desired type info
** - establishing an type hierarchy relation between ID related to the base class
** and the IDs denoting specific subclasses, such that the latter can stand-in
** for the generic ID.
** - providing a Mixin, which allows any hierarchy to use this facility without
** much code duplication, including an adapter for tr1::unordered_map
** - equality comparison
**
** @see HashIndexed_test
** @see Placement usage example
**
*/
#ifndef LIB_HASH_UTIL_H
#define LIB_HASH_UTIL_H
/**
* storage for a Lumiera unique ID,
* based on a 128bit random number
*/
typedef unsigned char lumiera_uid[16];
typedef lumiera_uid* LumieraUid;
#ifdef __cplusplus /* =========== C++ definitions ====================== */
namespace lib {
/** a STL compatible hash value */
typedef size_t HashVal;
/** a Lumiera UID */
typedef lumiera_uid* LUID;
namespace hash {
// WIP more utils to come here....
}
} // namespace lib
#endif /* C++ */
#endif /*LIB_HASH_UTIL_H*/

View file

@ -1,5 +1,5 @@
/*
luid - Lumiera unique identifiers
LUID - Lumiera unique identifiers
Copyright (C) Lumiera.org
2008, Christian Thaeter <ct@pipapo.org>
@ -17,7 +17,9 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
* *****************************************************/
#include "lib/luid.h"
@ -29,6 +31,8 @@
#include <string.h>
#include <stdint.h>
void
lumiera_uid_set_ptr (lumiera_uid* luid, void* ptr)
{
@ -79,8 +83,9 @@ lumiera_uid_gen (lumiera_uid* luid)
abort ();
}
}
/* we identify generic pointers by having some zeros in the luid,
* this happens very unlikely to be in a random luid, just regenerate it then */
/* we identify generic pointers by having some zeros in the LUID,
* Accidentally, but very unlikely this might happen within a random LUID;
* just regenerate in this case */
while (!*(((intptr_t*)luid)+1));
}

View file

@ -1,5 +1,5 @@
/*
luid - Lumiera unique identifiers
LUID.h - Lumiera unique identifiers
Copyright (C) Lumiera.org
2008, Christian Thaeter <ct@pipapo.org>
@ -18,20 +18,46 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef LUMIERA_LUID_H
#define LUMIERA_LUID_H
/** @file luid.h
** Lumiera unique object identifier.
** Lumiera unique identifiers are 128 byte random values. Unlike standard uuid's
** we don't tag a version within them and we may store generic pointers within the
** storage space occupied by an LUID.
**
** Due to the extremely huge number space, LUID values can be used as unique identifiers
** without the need to check for duplicates or collisions. At various places, LUIDs are
** thus used right away on creation of new object instances or elements, in case a
** distinguishable <i>object identity</i> is required, e.g.
** - any new attachment of an object into the session ("placement")
** - unique output designation discovered during the translation into a low-level
** node graph ("builder")
** - interface slots for external binding and plug-ins
**
** Moreover, there is a \link luidgen.c Luidgen \endlink tool to generate fixed LUIDs
** to be included into source code. It works by replacing the token \c LUIDGEN in the
** source code text by a newly generated (random) LUID in octal representation.
**
** LUIDs can also be used to generate hash values for hash table storage.
**
** @see HashIndexed Adapter for including a LUID into an object
** @see Placement usage example
** @see luidgen.c
** @see hash-util.h hash type definitions
**
*/
#ifndef LIB_LUID_H
#define LIB_LUID_H
#include "lib/hash-value.h" /* Types lumiera_uid and LumieraUid */
#include <stdlib.h>
/**
* @file
* Lumiera unique identifiers are 128 byte random value. Unlike standard uuid's we
* don't tag a version within them and we may store generic pointers in the space
* occupied by an luid.
*/
typedef unsigned char lumiera_uid[16];
typedef lumiera_uid* LumieraUid;
/*
C++ can't initialize arrays from string literals with the trailing \0 cropped
@ -103,16 +129,9 @@ lumiera_uid_eq (lumiera_uid* luida, lumiera_uid* luidb);
/**
* Generate a hashsum over an luid
* Generate a hash sum over an luid
*/
size_t
lumiera_uid_hash (lumiera_uid* luid);
#endif
/*
// Local Variables:
// mode: C
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
*/
#endif /*LIB_LUID_H*/

View file

@ -58,6 +58,7 @@
#include "lib/error.hpp"
#include "include/logging.h"
#include "proc/asset/category.hpp"
#include "lib/hash-value.h"
#include "lib/p.hpp"
#include <boost/type_traits/is_base_of.hpp>
@ -83,11 +84,11 @@ namespace asset {
using std::size_t;
using std::tr1::shared_ptr;
using std::tr1::static_pointer_cast;
using lib::HashVal;
using lib::P;
typedef size_t HashVal; /////////////////TICKET #722
/**
* thin wrapper around a size_t hash ID

View file

@ -65,7 +65,7 @@ namespace asset {
namespace idi {
using lib::hash::LuidH;
typedef size_t HashVal;
using lib::HashVal;
/** build up a hash value, packaged as LUID.

View file

@ -27,8 +27,6 @@
#include "proc/asset/media.hpp"
#include "proc/asset/clip.hpp"
#include "proc/asset/unknown.hpp"
#include "proc/mobject/session/clip.hpp"
#include "proc/mobject/session/mobjectfactory.hpp"
#include "backend/media-access-facade.hpp"
#include "lib/time/timevalue.hpp"
#include "lib/util.hpp"

View file

@ -26,14 +26,11 @@
#include "lib/error.hpp"
#include "lib/hash-value.h"
#include <boost/functional/hash.hpp>
namespace lib {
typedef size_t HashVal;
}
namespace proc {
namespace engine {

View file

@ -56,6 +56,7 @@
#include "lib/error.hpp"
#include "lib/symbol.hpp"
#include "lib/hash-value.h"
#include "lib/util-foreach.hpp"
#include "include/logging.h"
#include "proc/engine/type-handler.hpp"

View file

@ -44,6 +44,7 @@
#include "lib/error.hpp"
#include "lib/symbol.hpp"
#include "lib/hash-value.h"
#include "proc/engine/buffhandle.hpp"
#include "proc/engine/type-handler.hpp"
#include "proc/engine/buffer-local-key.hpp"

View file

@ -52,6 +52,7 @@
#include "lib/error.hpp"
#include "lib/hash-value.h"
#include "proc/streamtype.hpp"
#include "lib/bool-checkable.hpp"
@ -62,7 +63,7 @@ namespace engine {
namespace error = lumiera::error;
using error::LUMIERA_ERROR_LIFECYCLE;
typedef size_t HashVal; ////////////TICKET #722
using lib::HashVal;
class BuffHandle;
class BufferProvider;

View file

@ -37,6 +37,7 @@
#include "lib/error.hpp"
#include "lib/hash-value.h"
#include "proc/streamtype.hpp"
#include "lib/bool-checkable.hpp"
@ -47,7 +48,7 @@ namespace engine {
namespace error = lumiera::error;
using error::LUMIERA_ERROR_LIFECYCLE;
typedef size_t HashVal; ////////////TICKET #722
using lib::HashVal;
class BuffHandle;
class BufferProvider;

View file

@ -44,6 +44,7 @@
#include "lib/error.hpp"
#include "lib/hash-value.h"
#include "proc/engine/buffer-provider.hpp"
#include "lib/scoped-ptrvect.hpp"
@ -58,6 +59,7 @@ namespace engine {
namespace error = lumiera::error;
using lib::ScopedPtrVect;
using lib::HashVal;
namespace diagn {

View file

@ -43,6 +43,7 @@
#include "lib/error.hpp"
#include "lib/hash-value.h"
#include "lib/functor-util.hpp"
#include <tr1/functional>

View file

@ -53,6 +53,7 @@ using lumiera::query::QueryHandler;
using lumiera::query::removeTerm;
using lumiera::query::extractID;
using proc::ConfigResolver;
using lib::HashVal;
namespace proc {
namespace mobject {

View file

@ -25,12 +25,10 @@
#define PROC_MOBJECT_OUTPUT_DESIGNATION_H
#include "proc/asset/pipe.hpp"
#include "lib/hash-value.h"
#include "lib/opaque-holder.hpp"
#include "lib/meta/typelist-manip.hpp"
extern "C" {
#include "lib/luid.h"
}
namespace proc {
namespace mobject {

View file

@ -54,6 +54,7 @@
#include "lib/error.hpp"
#include "lib/util.hpp"
#include "lib/hash-value.h"
#include "proc/asset/pipe.hpp"
#include "lib/bool-checkable.hpp"
#include "common/query.hpp"
@ -97,7 +98,7 @@ namespace mobject {
namespace error = lumiera::error;
using lumiera::Query;
using asset::HashVal;
using lib::HashVal;

View file

@ -1,8 +1,8 @@
/*
luidgen.c - generate a lumiera uuid
Luidgen - generate and replace Lumiera UIDs for source files
Copyright (C) Lumiera.org
2008 Christian Thaeter <ct@pipapo.org>
2008, Christian Thaeter <ct@pipapo.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@ -17,7 +17,24 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
* *****************************************************/
/** @file luidgen.c
** Generate a fixed LUID to be hard-wired into source code.
** This Helper generates and prints a Lumiera UID as octal escaped string
** or processes a file, replacing the token \c LUIDGEN with the octal representation
** of a newly generated LUID. This can be used to fill in some LUID values into
** new source code prior to compiling it for the first time.
**
** The Lumiera build system generates stand-alone executable from this source file.
**
** @see luid.h
** @see interface.h
**
*/
#include "lib/tmpbuf.h"
#include "lib/luid.h"
@ -29,11 +46,6 @@
#include <string.h>
#include <nobug.h>
/**
* @file
* Generate amd print a Lumiera uid as octal escaped string
* or process a file replaceing 'LUIDGEN' with a octal escaped string
*/
int

View file

@ -22,6 +22,7 @@
#include "lib/test/run.hpp"
#include "lib/hash-value.h"
#include "common/advice/index.hpp"
#include <vector>

View file

@ -23,14 +23,12 @@
#include "lib/test/run.hpp"
//#include "lib/util.hpp"
#include "lib/functor-util.hpp"
#include <tr1/functional>
#include <boost/functional/hash.hpp>
#include <iostream>
//using util::isnil;
using lib::HashVal;
using std::cout;
using std::tr1::function;

View file

@ -159,6 +159,8 @@ namespace test{
/**********************************************************************************
* @test build a bunch of PolymorphicValue objects. Handle them like copyable
* value objects, without knowing the exact implementation type; moreover