Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an hts_crc32 function to use zlib or libdeflate. #1850

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bgzf.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ BGZF *bgzf_hopen(hFILE *hfp, const char *mode)
}

#ifdef HAVE_LIBDEFLATE
uint32_t hts_crc32(uint32_t crc, const void *buf, size_t len) {
return libdeflate_crc32(crc, buf, len);
}

int bgzf_compress(void *_dst, size_t *dlen, const void *src, size_t slen, int level)
{
if (slen == 0) {
Expand Down Expand Up @@ -607,6 +611,10 @@ int bgzf_compress(void *_dst, size_t *dlen, const void *src, size_t slen, int le

#else

uint32_t hts_crc32(uint32_t crc, const void *buf, size_t len) {
return crc32(crc, buf, len);
}

int bgzf_compress(void *_dst, size_t *dlen, const void *src, size_t slen, int level)
{
uint32_t crc;
Expand Down
8 changes: 8 additions & 0 deletions htslib/hts.h
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,14 @@ static inline int hts_bin_level(int bin) {
return l;
}

/**************************************
* Exposing the CRC32 implementation *
* Either from zlib or libdeflate. *
*************************************/
HTSLIB_EXPORT
uint32_t hts_crc32(uint32_t crc, const void *buf, size_t len);


//! Compute the corresponding entry into the linear index of a given bin from
//! a binning index
/*!
Expand Down