SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 and Murmur hashing functions were integrated from public sources.
11  * Their respective copyrights follow.
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  * MurmurHash2
31  *
32  * (C) Austin Appleby, released under the MIT License
33  *
34  * Note - This code makes a few assumptions about how your machine behaves -
35  *
36  * 1. We can read a 4-byte value from any address without crashing
37  * 2. It will not produce the same results on little-endian and big-endian
38  * machines.
39  */
40 
41 #ifndef HASH_H
42 #define HASH_H
43 
44 #include <shogun/base/SGObject.h>
45 #include <shogun/lib/common.h>
46 
47 namespace shogun
48 {
55 class CHash : public CSGObject
56 {
57  public:
59  CHash() {}
61  virtual ~CHash() {}
62 
68  static uint32_t crc32(uint8_t *data, int32_t len);
69 
77  static void MD5(unsigned char *x, unsigned l, unsigned char *buf);
78 
87  static uint32_t MurmurHash2(uint8_t* data, int32_t len, uint32_t seed);
88 
96  static uint32_t IncrementalMurmurHash2(uint8_t data, uint32_t h);
97 
108  static uint32_t MurmurHashString(substring s, uint32_t h);
109 
111  inline virtual const char* get_name() const { return "Hash"; }
112 
113  protected:
114 
115 #ifndef DOXYGEN_SHOULD_SKIP_THIS
116 
117  struct MD5Context {
119  uint32_t buf[4];
121  uint32_t bits[2];
123  unsigned char in[64];
124  };
125 #endif // DOXYGEN_SHOULD_SKIP_THIS
126 
133  static void MD5Init(struct MD5Context *context);
134 
143  static void MD5Update(struct MD5Context *context,
144  unsigned char const *buf, unsigned len);
145 
153  static void MD5Final(unsigned char digest[16],
154  struct MD5Context *context);
163  static void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
164 };
165 }
166 #endif

SHOGUN Machine Learning Toolbox - Documentation