Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
hashsum.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_core/hashsum.h
10 //! @brief Hash sum.
11 
12 #ifndef ROC_CORE_HASHSUM_H_
13 #define ROC_CORE_HASHSUM_H_
14 
15 #include "roc_core/stddefs.h"
16 
17 namespace roc {
18 namespace core {
19 
20 //! Hash type.
21 typedef size_t hashsum_t;
22 
23 //! Compute hash of 16-bit integer.
25 
26 //! Compute hash of 16-bit integer.
28 
29 //! Compute hash of 32-bit integer.
31 
32 //! Compute hash of 32-bit integer.
34 
35 //! Compute hash of 64-bit integer.
37 
38 //! Compute hash of 64-bit integer.
40 
41 //! Compute hash of an integer.
42 //! This fallback is needed for the cases when the overloads above
43 //! do not cover all builtin types. E.g. if none of the overloads
44 //! above covers unsigned long or unsigned long long.
45 template <class T> hashsum_t hashsum_int(T t) {
46  switch (sizeof(T)) {
47  case 2:
48  return hashsum_int((uint16_t)t);
49  case 4:
50  return hashsum_int((uint32_t)t);
51  case 8:
52  return hashsum_int((uint64_t)t);
53  }
54 }
55 
56 //! Compute hash of zero-terminated string.
57 hashsum_t hashsum_str(const char* str);
58 
59 //! Compute hash of byte range.
60 hashsum_t hashsum_mem(const void* data, size_t size);
61 
62 } // namespace core
63 } // namespace roc
64 
65 #endif // ROC_CORE_HASHSUM_H_
hashsum_t hashsum_int(int16_t)
Compute hash of 16-bit integer.
hashsum_t hashsum_str(const char *str)
Compute hash of zero-terminated string.
hashsum_t hashsum_mem(const void *data, size_t size)
Compute hash of byte range.
size_t hashsum_t
Hash type.
Definition: hashsum.h:21
Root namespace.
Commonly used types and functions.