Hash.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2009 Soeren Sonnenburg
00008  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  *
00010  * The MD5 and Murmur hashing functions were integrated from public sources.
00011  * Their respective copyrights follow.
00012  *
00013  * MD5
00014  *
00015  * This code implements the MD5 message-digest algorithm.
00016  * The algorithm is due to Ron Rivest.  This code was
00017  * written by Colin Plumb in 1993, no copyright is claimed.
00018  * This code is in the public domain; do with it what you wish.
00019  *
00020  * Equivalent code is available from RSA Data Security, Inc.
00021  * This code has been tested against that, and is equivalent,
00022  * except that you don't need to include two pages of legalese
00023  * with every copy.
00024  *
00025  * To compute the message digest of a chunk of bytes, declare an
00026  * MD5Context structure, pass it to MD5Init, call MD5Update as
00027  * needed on buffers full of bytes, and then call MD5Final, which
00028  * will fill a supplied 16-byte array with the digest.
00029  *
00030  * MurmurHash2
00031  *
00032  * (C) Austin Appleby, released under the MIT License
00033  * 
00034  *  Note - This code makes a few assumptions about how your machine behaves -
00035  * 
00036  *  1. We can read a 4-byte value from any address without crashing
00037  *  2. It will not produce the same results on little-endian and big-endian
00038  *     machines.
00039  */
00040 
00041 #ifndef HASH_H
00042 #define HASH_H
00043 
00044 #include <shogun/base/SGObject.h>
00045 #include <shogun/lib/common.h>
00046 
00047 namespace shogun
00048 {
00055 class CHash : public CSGObject
00056 {
00057     public:
00059         CHash() {}
00061         virtual ~CHash() {}
00062 
00068         static uint32_t crc32(uint8_t *data, int32_t len);
00069 
00077         static void MD5(unsigned char *x, unsigned l, unsigned char *buf);
00078 
00087         static uint32_t MurmurHash2(uint8_t* data, int32_t len, uint32_t seed);
00088 
00096         static uint32_t IncrementalMurmurHash2(uint8_t data, uint32_t h);
00097 
00108         static uint32_t MurmurHashString(substring s, uint32_t h);
00109 
00111         inline virtual const char* get_name() const { return "Hash"; }
00112 
00113     protected:
00114 
00115 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00116 
00117         struct MD5Context {
00119             uint32_t buf[4];
00121             uint32_t bits[2];
00123             unsigned char in[64];
00124         };
00125 #endif // DOXYGEN_SHOULD_SKIP_THIS
00126 
00133         static void MD5Init(struct MD5Context *context);
00134 
00143         static void MD5Update(struct MD5Context *context,
00144                 unsigned char const *buf, unsigned len);
00145 
00153         static void MD5Final(unsigned char digest[16],
00154                 struct MD5Context *context);
00163         static void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
00164 };
00165 }
00166 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation