SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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
static void MD5Init(struct MD5Context *context)
Definition: Hash.cpp:96
static void MD5(unsigned char *x, unsigned l, unsigned char *buf)
Definition: Hash.cpp:65
static void MD5Final(unsigned char digest[16], struct MD5Context *context)
Definition: Hash.cpp:152
static uint32_t crc32(uint8_t *data, int32_t len)
Definition: Hash.cpp:38
virtual ~CHash()
Definition: Hash.h:56
virtual const char * get_name() const
Definition: Hash.h:125
static uint32_t FinalizeIncrementalMurmurHash3(uint32_t h, uint32_t carry, uint32_t total_length)
Definition: Hash.cpp:376
struct Substring, specified by start position and end position.
Definition: SGIO.h:229
static uint32_t MurmurHash3(uint8_t *data, int32_t len, uint32_t seed)
Definition: Hash.cpp:366
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
static void MD5Transform(uint32_t buf[4], uint32_t const in[16])
Definition: Hash.cpp:212
static uint32_t MurmurHashString(substring s, uint32_t h)
Definition: Hash.cpp:381
static void IncrementalMurmurHash3(uint32_t *hash, uint32_t *carry, uint8_t *data, int32_t len)
Definition: Hash.cpp:371
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
static void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len)
Definition: Hash.cpp:107
Collection of Hashing Functions.
Definition: Hash.h:50

SHOGUN Machine Learning Toolbox - Documentation