SHOGUN  3.2.1
 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/lib/config.h>
36 
37 #include <shogun/base/SGObject.h>
38 #include <shogun/lib/common.h>
39 
40 namespace shogun
41 {
42 struct substring;
43 
50 class CHash : public CSGObject
51 {
52  public:
54  CHash() {}
56  virtual ~CHash() {}
57 
63  static uint32_t crc32(uint8_t *data, int32_t len);
64 
72  static void MD5(unsigned char *x, unsigned l, unsigned char *buf);
73 
83  static uint32_t MurmurHash3(uint8_t* data, int32_t len, uint32_t seed);
84 
96  static void IncrementalMurmurHash3(uint32_t *hash, uint32_t *carry,
97  uint8_t* data, int32_t len);
98 
109  static uint32_t FinalizeIncrementalMurmurHash3(uint32_t h,
110  uint32_t carry, uint32_t total_length);
111 
122  static uint32_t MurmurHashString(substring s, uint32_t h);
123 
125  virtual const char* get_name() const { return "Hash"; }
126 
127  protected:
128 
129 #ifndef DOXYGEN_SHOULD_SKIP_THIS
130 
131  struct MD5Context {
133  uint32_t buf[4];
135  uint32_t bits[2];
136  union
137  {
139  unsigned char in[64];
141  uint32_t uin[16];
142  };
143  };
144 #endif // DOXYGEN_SHOULD_SKIP_THIS
145 
152  static void MD5Init(struct MD5Context *context);
153 
162  static void MD5Update(struct MD5Context *context,
163  unsigned char const *buf, unsigned len);
164 
172  static void MD5Final(unsigned char digest[16],
173  struct MD5Context *context);
182  static void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
183 };
184 }
185 #endif

SHOGUN Machine Learning Toolbox - Documentation