• 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 #include "lang_id/common/math/checksum.h"
18 
19 // Though we use the same zlib header on all platforms, the implementation used
20 // is from NDK on android and from third_party/zlib on iOS/linux.  See BUILD
21 // rule.
22 #include <zlib.h>
23 
24 namespace libtextclassifier3 {
25 namespace mobile {
26 
27 // static
GetInitialCrc32()28 uint32 Crc32::GetInitialCrc32() {
29   static const uint32 kCrcInitZero = crc32(0L, nullptr, 0);
30   return kCrcInitZero;
31 }
32 
Update(const char * str,int len)33 void Crc32::Update(const char *str, int len) {
34   if (str == nullptr || len == 0) {
35     return;
36   }
37   current_ = crc32(current_,
38                    reinterpret_cast<const unsigned char *>(str),
39                    len);
40 }
41 
42 }  // namespace mobile
43 }  // namespace nlp_saft
44