/root/doris/be/src/util/crc32c.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | // the following code are modified from RocksDB: |
19 | | // https://github.com/facebook/rocksdb/blob/master/util/crc32c.h |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include <stddef.h> |
24 | | #include <stdint.h> |
25 | | |
26 | | #include <vector> |
27 | | |
28 | | #include "util/slice.h" |
29 | | |
30 | | namespace doris { |
31 | | namespace crc32c { |
32 | | |
33 | | // Return the crc32c of concat(A, data[0,n-1]) where init_crc is the |
34 | | // crc32c of some string A. Extend() is often used to maintain the |
35 | | // crc32c of a stream of data. |
36 | | extern uint32_t Extend(uint32_t init_crc, const char* data, size_t n); |
37 | | |
38 | | // Return the crc32c of data[0,n-1] |
39 | 25.4k | inline uint32_t Value(const char* data, size_t n) { |
40 | 25.4k | return Extend(0, data, n); |
41 | 25.4k | } |
42 | | |
43 | | // Return the crc32c of data content in all slices |
44 | 26.1k | inline uint32_t Value(const std::vector<Slice>& slices) { |
45 | 26.1k | uint32_t crc = 0; |
46 | 63.1k | for (auto& slice : slices) { |
47 | 63.1k | crc = Extend(crc, slice.get_data(), slice.get_size()); |
48 | 63.1k | } |
49 | 26.1k | return crc; |
50 | 26.1k | } |
51 | | |
52 | | } // namespace crc32c |
53 | | } // namespace doris |