SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Hash.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2009 Soeren Sonnenburg
8  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  *
10  * The MD5 hashing function was integrated from public sources.
11  * Its copyright follows.
12  *
13  * MD5
14  *
15  * This code implements the MD5 message-digest algorithm.
16  * The algorithm is due to Ron Rivest. This code was
17  * written by Colin Plumb in 1993, no copyright is claimed.
18  * This code is in the public domain; do with it what you wish.
19  *
20  * Equivalent code is available from RSA Data Security, Inc.
21  * This code has been tested against that, and is equivalent,
22  * except that you don't need to include two pages of legalese
23  * with every copy.
24  *
25  * To compute the message digest of a chunk of bytes, declare an
26  * MD5Context structure, pass it to MD5Init, call MD5Update as
27  * needed on buffers full of bytes, and then call MD5Final, which
28  * will fill a supplied 16-byte array with the digest.
29  *
30  */
31 
32 #ifndef HASH_H
33 #define HASH_H
34 
35 #include <shogun/base/SGObject.h>
36 #include <shogun/lib/common.h>
37 #include <shogun/lib/external/PMurHash.h>
38 
39 namespace shogun
40 {
47 class CHash : public CSGObject
48 {
49  public:
51  CHash() {}
53  virtual ~CHash() {}
54 
60  static uint32_t crc32(uint8_t *data, int32_t len);
61 
69  static void MD5(unsigned char *x, unsigned l, unsigned char *buf);
70 
80  static uint32_t MurmurHash3(uint8_t* data, int32_t len, uint32_t seed);
81 
93  static void IncrementalMurmurHash3(uint32_t *hash, uint32_t *carry,
94  uint8_t* data, int32_t len);
95 
106  static uint32_t FinalizeIncrementalMurmurHash3(uint32_t h,
107  uint32_t carry, uint32_t total_length);
108 
119  static uint32_t MurmurHashString(substring s, uint32_t h);
120 
122  virtual const char* get_name() const { return "Hash"; }
123 
124  protected:
125 
126 #ifndef DOXYGEN_SHOULD_SKIP_THIS
127 
128  struct MD5Context {
130  uint32_t buf[4];
132  uint32_t bits[2];
133  union
134  {
136  unsigned char in[64];
138  uint32_t uin[16];
139  };
140  };
141 #endif // DOXYGEN_SHOULD_SKIP_THIS
142 
149  static void MD5Init(struct MD5Context *context);
150 
159  static void MD5Update(struct MD5Context *context,
160  unsigned char const *buf, unsigned len);
161 
169  static void MD5Final(unsigned char digest[16],
170  struct MD5Context *context);
179  static void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
180 };
181 }
182 #endif

SHOGUN Machine Learning Toolbox - Documentation