• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef TC3_STD_STRING_IMPORT
18 #define TC3_STD_STRING_IMPORT
19 #include <string>
20 
21 namespace libtextclassifier3 {
22 using string = std::string;
23 template <class CharT, class Traits = std::char_traits<CharT>,
24           class Allocator = std::allocator<CharT> >
25 using basic_string = std::basic_string<CharT, Traits, Allocator>;
26 }  // namespace libtextclassifier3
27 #endif
28 #ifndef NLP_SAFT_COMPONENTS_COMMON_MOBILE_MATH_HASH_H_
29 #define NLP_SAFT_COMPONENTS_COMMON_MOBILE_MATH_HASH_H_
30 
31 #include <string>
32 
33 #include "lang_id/common/lite_base/integral-types.h"
34 
35 namespace libtextclassifier3 {
36 namespace mobile {
37 namespace utils {
38 
39 // Returns a 32 bit hash of the |n| bytes that start at |data|, using |seed| for
40 // internal initialization.  By changing the seed, one effectively gets
41 // different hash functions.
42 //
43 // NOTE: this function is guaranteed not to change in the future.
44 //
45 // IMPORTANT: for speed reasons, this method does not check its parameters
46 // |data| and |n|.  The caller should ensure that n >= 0 and that one can read
47 // from the memory area [data, data + n).
48 uint32 Hash32(const char *data, size_t n, uint32 seed);
49 
Hash32WithDefaultSeed(const char * data,size_t n)50 static inline uint32 Hash32WithDefaultSeed(const char *data, size_t n) {
51   return Hash32(data, n, 0xBEEF);
52 }
53 
Hash32WithDefaultSeed(const std::string & input)54 static inline uint32 Hash32WithDefaultSeed(const std::string &input) {
55   return Hash32WithDefaultSeed(input.data(), input.size());
56 }
57 
58 }  // namespace utils
59 }  // namespace mobile
60 }  // namespace nlp_saft
61 
62 #endif  // NLP_SAFT_COMPONENTS_COMMON_MOBILE_MATH_HASH_H_
63