OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_DJB2_H_ | 5 #ifndef MEDIA_BASE_DJB2_H_ |
6 #define MEDIA_BASE_DJB2_H_ | 6 #define MEDIA_BASE_DJB2_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
9 #include "media/base/media_export.h" | 11 #include "media/base/media_export.h" |
10 | 12 |
11 // DJB2 is a hash algorithm with excellent distribution and speed | 13 // DJB2 is a hash algorithm with excellent distribution and speed |
12 // on many different sets. | 14 // on many different sets. |
13 // It has marginally more collisions than FNV1, but makes up for it in | 15 // It has marginally more collisions than FNV1, but makes up for it in |
14 // performance. | 16 // performance. |
15 // The return value is suitable for table lookups. | 17 // The return value is suitable for table lookups. |
16 // For small fixed sizes (ie a pixel), it has low overhead and inlines well. | 18 // For small fixed sizes (ie a pixel), it has low overhead and inlines well. |
17 // For large data sets, it optimizes into assembly/simd and is appropriate | 19 // For large data sets, it optimizes into assembly/simd and is appropriate |
18 // for realtime applications. | 20 // for realtime applications. |
19 // See Also: | 21 // See Also: |
20 // http://www.cse.yorku.ca/~oz/hash.html | 22 // http://www.cse.yorku.ca/~oz/hash.html |
21 | 23 |
22 static const uint32 kDJB2HashSeed = 5381u; | 24 static const uint32_t kDJB2HashSeed = 5381u; |
23 | 25 |
24 // These functions perform DJB2 hash. The simplest call is DJB2Hash() to | 26 // These functions perform DJB2 hash. The simplest call is DJB2Hash() to |
25 // generate the DJB2 hash of the given data: | 27 // generate the DJB2 hash of the given data: |
26 // uint32 hash = DJB2Hash(data1, length1, kDJB2HashSeed); | 28 // uint32_t hash = DJB2Hash(data1, length1, kDJB2HashSeed); |
27 // | 29 // |
28 // You can also compute the DJB2 hash of data incrementally by making multiple | 30 // You can also compute the DJB2 hash of data incrementally by making multiple |
29 // calls to DJB2Hash(): | 31 // calls to DJB2Hash(): |
30 // uint32 hash_value = kDJB2HashSeed; // Initial seed for DJB2. | 32 // uint32_t hash_value = kDJB2HashSeed; // Initial seed for DJB2. |
31 // for (size_t i = 0; i < copy_lines; ++i) { | 33 // for (size_t i = 0; i < copy_lines; ++i) { |
32 // hash_value = DJB2Hash(source, bytes_per_line, hash_value); | 34 // hash_value = DJB2Hash(source, bytes_per_line, hash_value); |
33 // source += source_stride; | 35 // source += source_stride; |
34 // } | 36 // } |
35 | 37 |
36 // For the given buffer of data, compute the DJB2 hash of | 38 // For the given buffer of data, compute the DJB2 hash of |
37 // the data. You can call this any number of times during the computation. | 39 // the data. You can call this any number of times during the computation. |
38 MEDIA_EXPORT uint32 DJB2Hash(const void* buf, size_t len, uint32 seed); | 40 MEDIA_EXPORT uint32_t DJB2Hash(const void* buf, size_t len, uint32_t seed); |
39 | 41 |
40 #endif // MEDIA_BASE_DJB2_H_ | 42 #endif // MEDIA_BASE_DJB2_H_ |
41 | 43 |
OLD | NEW |