Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkStructHashFunction.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkStructHashFunction.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/12/21 16:50:20 $
00007   Version:   $Revision: 1.5 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef itkStructHashFunction_h
00018 #define itkStructHashFunction_h
00019 
00020 namespace itk
00021 {
00022 
00035 template< class TInput >
00036 class StructHashFunction
00037 {
00038 public:
00039 
00041   typedef StructHashFunction Self;
00042 
00044   typedef TInput InputType;
00045 
00046   unsigned int operator()( const InputType& key ) const;
00047 
00048 };
00049 
00050 template< class TInput >
00051 inline unsigned int
00052 StructHashFunction< TInput >
00053 ::operator()( const InputType& key ) const
00054 {
00055   ::size_t len = sizeof( InputType );
00056   const char* p = reinterpret_cast< const char* >( &key );
00057   unsigned int hash = 0;
00058   while( len-- )
00059     {
00060     hash = hash * 65 + *p++;
00061     }
00062   hash += (hash >> 5);
00063   return hash;
00064 }
00065 
00066 }
00067 
00068 #endif  // ndef itkStructHashFunction_h
00069 

Generated at Thu Nov 6 00:21:16 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000