git / moonbite-core / src/crc32c/README.md · raw

# CRC32C[![Build Status](https://travis-ci.org/google/crc32c.svg?branch=master)](https://travis-ci.org/google/crc32c)[![Build Status](https://ci.appveyor.com/api/projects/status/moiq7331pett4xuj/branch/master?svg=true)](https://ci.appveyor.com/project/pwnall/crc32c)New file format authors should consider[HighwayHash](https://github.com/google/highwayhash). The initial version ofthis code was extracted from [LevelDB](https://github.com/google/leveldb), whichis a stable key-value store that is widely used at Google.This project collects a few CRC32C implementations under an umbrella thatdispatches to a suitable implementation based on the host computer's hardwarecapabilities.CRC32C is specified as the CRC that uses the iSCSI polynomial in[RFC 3720](https://tools.ietf.org/html/rfc3720#section-12.1). The polynomial wasintroduced by G. Castagnoli, S. Braeuer and M. Herrmann. CRC32C is used insoftware such as Btrfs, ext4, Ceph and leveldb.## Usage```cpp#include "crc32c/crc32c.h"int main() {  const std::uint8_t buffer[] = {0, 0, 0, 0};  std::uint32_t result;  // Process a raw buffer.  result = crc32c::Crc32c(buffer, 4);  // Process a std::string.  std::string string;  string.resize(4);  result = crc32c::Crc32c(string);  // If you have C++17 support, process a std::string_view.  std::string_view string_view(string);  result = crc32c::Crc32c(string_view);  return 0;}```## PrerequisitesThis project uses [CMake](https://cmake.org/) for building and testing. CMake isavailable in all popular Linux distributions, as well as in[Homebrew](https://brew.sh/).This project uses submodules for dependency management.```bashgit submodule update --init --recursive```If you're using [Atom](https://atom.io/), the following packages can help.```bashapm install autocomplete-clang build build-cmake clang-format language-cmake \    linter linter-clang```If you don't mind more setup in return for more speed, replace`autocomplete-clang` and `linter-clang` with `you-complete-me`. This requires[setting up ycmd](https://github.com/Valloric/ycmd#building).```bashapm install autocomplete-plus build build-cmake clang-format language-cmake \    linter you-complete-me```## BuildingThe following commands build and install the project.```bashmkdir buildcd buildcmake -DCRC32C_BUILD_TESTS=0 -DCRC32C_BUILD_BENCHMARKS=0 .. && make all install```## DevelopmentThe following command (when executed from `build/`) (re)builds the project andruns the tests.```bashcmake .. && cmake --build . && ctest --output-on-failure```### Android testingThe following command builds the project against the Android NDK, which isuseful for benchmarking against ARM processors.```bashcmake .. -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \    -DCMAKE_ANDROID_NDK=$HOME/Library/Android/sdk/ndk-bundle \    -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \    -DCMAKE_ANDROID_STL_TYPE=c++_static -DCRC32C_USE_GLOG=0 \    -DCMAKE_BUILD_TYPE=Release && cmake --build .```The following commands install and run the benchmarks.```bashadb push crc32c_bench /data/local/tmpadb shell chmod +x /data/local/tmp/crc32c_benchadb shell 'cd /data/local/tmp && ./crc32c_bench'adb shell rm /data/local/tmp/crc32c_bench```The following commands install and run the tests.```bashadb push crc32c_tests /data/local/tmpadb shell chmod +x /data/local/tmp/crc32c_testsadb shell 'cd /data/local/tmp && ./crc32c_tests'adb shell rm /data/local/tmp/crc32c_tests```