https://github.com/awslabs/aws-c-compression

C99 implementation of huffman encoding/decoding

https://github.com/awslabs/aws-c-compression

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.7%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

C99 implementation of huffman encoding/decoding

Basic Info
  • Host: GitHub
  • Owner: awslabs
  • License: apache-2.0
  • Language: C
  • Default Branch: main
  • Homepage:
  • Size: 177 KB
Statistics
  • Stars: 36
  • Watchers: 23
  • Forks: 22
  • Open Issues: 1
  • Releases: 22
Created about 8 years ago · Last pushed 12 months ago
Metadata Files
Readme Contributing License Code of conduct

README.md

AWS C Compression

This is a cross-platform C99 implementation of compression algorithms such as gzip, and huffman encoding/decoding. Currently only huffman is implemented.

License

This library is licensed under the Apache 2.0 License.

Usage

Building

Note that aws-c-compression has a dependency on aws-c-common:

``` git clone git@github.com:awslabs/aws-c-common.git cmake -DCMAKEPREFIXPATH= -DCMAKEINSTALLPREFIX= -S aws-c-common -B aws-c-common/build cmake --build aws-c-common/build --target install

git clone git@github.com:awslabs/aws-c-compression.git cmake -DCMAKEPREFIXPATH= -DCMAKEINSTALLPREFIX= -S aws-c-compression -B aws-c-compression/build cmake --build aws-c-compression/build --target install ```

Huffman

The Huffman implemention in this library is designed around the concept of a generic "symbol coder" object, which defines how each symbol (value between 0 and 255) is encoded and decoded. This object looks like this: ```c typedef struct awshuffmancode (awshuffmansymbolencoder)(uint8t symbol, void *userdata); typedef uint8_t (awshuffmansymboldecoder)(uint32t bits, uint8_t *symbol, void *userdata);

struct awshuffmansymbolcoder { awshuffmansymbolencoder encode; awshuffmansymboldecoder decode; void *userdata; }; These callbacks may be implemented manually, or you may use the included Huffman coder generator to generate one from a table definition file. The generator expects to be called with the following arguments: shell $ aws-c-compression-huffman-generator path/to/table.def path/to/generated.c codername ```

The table definition file should be in the following format: c /* sym bits code len */ HUFFMAN_CODE( 0, "1100101110", 0x32e, 10) HUFFMAN_CODE( 1, "1100101111", 0x32f, 10) /* ... */ The HUFFMAN_CODE macro expects 4 arguments: * sym: the symbol value [0-255] * bits: the bits representing the symbol in string form * code: the bits representing the symbol in numeric form * len: the number of bits used to represent the symbol

Note

This file may also be #included in the following way to generate a static list of codes: ```c /* Provides the HUFFMAN_CODE macro */

include

static struct huffmantestcodepoint codepoints[] = {

include "testhuffmanstatic_table.def"

}; ```

This will emit a c file which exports a function with the following signiture: c struct aws_huffman_symbol_coder *{coder_name}_get_coder(); Note that this function does not allocate, but maintains a static instance of the coder.

An example implementation of this file is provided in tests/test_huffman_static_table.def.

To use the coder, forward declare that function, and pass the result as the second argument to aws_huffman_encoder_init and aws_huffman_decoder_init. ```c struct awshuffmanencoder encoder; awshuffmanencoderinit(&encoder, {codername}getcoder());

struct awshuffmandecoder decoder; awshuffmandecoderinit(&decoder, {codername}getcoder()) ```

Encoding

c /** * Encode a symbol buffer into the output buffer. * * \param[in] encoder The encoder object to use * \param[in] to_encode The symbol buffer to encode * \param[in,out] length In: The length of to_decode. Out: The number of bytes read from to_encode * \param[in] output The buffer to write encoded bytes to * \param[in,out] output_size In: The size of output. Out: The number of bytes written to output * * \return AWS_OP_SUCCESS if encoding is successful, AWS_OP_ERR the code for the error that occured */ int aws_huffman_encode(struct aws_huffman_encoder *encoder, const char *to_encode, size_t *length, uint8_t *output, size_t *output_size); The encoder is built to support partial encoding. This means that if there isn't enough space in output, the encoder will encode as much as possible, update length to indicate how much was consumed, output_size won't change, and AWS_ERROR_SHORT_BUFFER will be raised. aws_huffman_encode may then be called again like the following pseudo-code: ```c void encodeandsend(const char toencode, sizet size) { while (size > 0) { uint8t output[somechunksize]; sizet outputsize = sizeof(output); sizet bytesread = size; awshuffmanencode(encoder, toencode, &bytesread, output, &outputsize); / AWSERRORSHORTBUFFER was raised... */ sendoutputtosomeoneelse(output, outputsize);

    to_encode += bytes_read;
    size -= bytes_read;
}
/* Be sure to reset the encoder after use */
aws_huffman_encoder_reset(encoder);

} ```

aws_huffman_encoder also has a uint8_t field called eos_padding that defines how any unwritten bits in the last byte of output are filled. The most significant bits will used. For example, if the last byte contains only 3 bits and eos_padding is 0b01010101, 01010 will be appended to the byte.

Decoding

c /** * Decodes a byte buffer into the provided symbol array. * * \param[in] decoder The decoder object to use * \param[in] to_decode The encoded byte buffer to read from * \param[in,out] length In: The length of to_decode. Out: The number of bytes read from to_decode * \param[in] output The buffer to write decoded symbols to * \param[in,out] output_size In: The size of output. Out: The number of bytes written to output * * \return AWS_OP_SUCCESS if encoding is successful, AWS_OP_ERR the code for the error that occured */ int aws_huffman_decode(struct aws_huffman_decoder *decoder, const uint8_t *to_decode, size_t *length, char *output, size_t *output_size); The decoder is built to support partial encoding. This means that if there isn't enough space in output, the decoder will decode as much as possible, update length to indicate how much was consumed, output_size won't change, and AWS_ERROR_SHORT_BUFFER will be raised. aws_huffman_decode may then be called again like the following pseudo-code: ```c void decodeandsend(const char todecode, sizet size) { while (size > 0) { uint8t output[somechunksize]; sizet outputsize = sizeof(output); sizet bytesread = size; awshuffmandecode(decoder, todecode, &bytesread, output, &outputsize); / AWSERRORSHORTBUFFER was raised... */ sendoutputtosomeoneelse(output, outputsize);

    to_decode += bytes_read;
    size -= bytes_read;
}
/* Be sure to reset the decoder after use */
aws_huffman_decoder_reset(decoder);

} ```

Upon completion of a decode, the most significant bits of decoder->working_bits will contain the final bits of to_decode that could not match a symbol. This is useful for verifying the padding bits of a stream. For example, to validate that a stream ends in all 1's (like HPACK requires), you could do the following: c AWS_ASSERT(decoder->working_bits == UINT64_MAX << (64 - decoder->num_bits));

Owner

  • Name: Amazon Web Services - Labs
  • Login: awslabs
  • Kind: organization
  • Location: Seattle, WA

AWS Labs

GitHub Events

Total
  • Release event: 2
  • Watch event: 2
  • Delete event: 6
  • Push event: 12
  • Pull request review comment event: 5
  • Pull request event: 11
  • Pull request review event: 11
  • Fork event: 2
  • Create event: 9
Last Year
  • Release event: 2
  • Watch event: 2
  • Delete event: 6
  • Push event: 12
  • Pull request review comment event: 5
  • Pull request event: 11
  • Pull request review event: 11
  • Fork event: 2
  • Create event: 9

Committers

Last synced: over 3 years ago

All Time
  • Total Commits: 69
  • Total Committers: 14
  • Avg Commits per committer: 4.929
  • Development Distribution Score (DDS): 0.797
Past Year
  • Commits: 5
  • Committers: 4
  • Avg Commits per committer: 1.25
  • Development Distribution Score (DDS): 0.6
Top Committers
Name Email Commits
Colden Cullen c****n@a****m 14
Michael Graeb g****m@a****m 12
Bret Ambrose b****e@g****m 9
Colden Cullen C****n@G****m 7
Jacob Peddicord j****d@u****m 7
Justin Boswell b****j@a****m 7
Jonathan M. Henson h****o@a****m 3
Colden Cullen c****n@c****m 2
Dengke Tang 8****5@q****m 2
Dengke Tang d****t@a****m 2
rccarper 5****r@u****m 1
Waqar Ahmed Khan w****7@g****m 1
TwistedTwigleg t****g@g****m 1
Andrew Tang t****1@1****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 0
  • Total pull requests: 78
  • Average time to close issues: N/A
  • Average time to close pull requests: 23 days
  • Total issue authors: 0
  • Total pull request authors: 17
  • Average comments per issue: 0
  • Average comments per pull request: 0.1
  • Merged pull requests: 70
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 10
  • Average time to close issues: N/A
  • Average time to close pull requests: 13 days
  • Issue authors: 0
  • Pull request authors: 5
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • graebm (19)
  • ColdenCullen (15)
  • bretambrose (10)
  • justinboswell (7)
  • waahm7 (6)
  • TingDaoK (6)
  • JonathanHenson (5)
  • DmitriyMusatkin (4)
  • jmklix (2)
  • ashishdhingra (2)
  • singku-china (1)
  • lucasmt (1)
  • rccarper (1)
  • TwistedTwigleg (1)
  • jonahharris (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 15
  • Total downloads:
    • homebrew 2,407 last-month
  • Total dependent packages: 5
    (may contain duplicates)
  • Total dependent repositories: 23
    (may contain duplicates)
  • Total versions: 40
  • Total maintainers: 3
alpine-v3.18: aws-c-compression-dev

C99 implementation of huffman encoding/decoding (development files)

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 11.8%
Forks count: 22.9%
Stargazers count: 24.5%
Maintainers (1)
Last synced: 11 months ago
alpine-v3.18: aws-c-compression

C99 implementation of huffman encoding/decoding

  • Versions: 1
  • Dependent Packages: 2
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 11.8%
Forks count: 22.9%
Stargazers count: 24.5%
Maintainers (1)
Last synced: 11 months ago
alpine-edge: aws-c-compression-dev

C99 implementation of huffman encoding/decoding (development files)

  • Versions: 10
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 14.6%
Average: 16.2%
Forks count: 23.9%
Stargazers count: 26.2%
Maintainers (1)
Last synced: 11 months ago
alpine-edge: aws-c-compression

C99 implementation of huffman encoding/decoding

  • Versions: 10
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 14.6%
Average: 16.2%
Forks count: 23.9%
Stargazers count: 26.2%
Maintainers (1)
Last synced: 11 months ago
conda-forge.org: aws-c-compression
  • Versions: 6
  • Dependent Packages: 1
  • Dependent Repositories: 23
Rankings
Dependent repos count: 7.6%
Dependent packages count: 29.0%
Average: 30.9%
Forks count: 40.2%
Stargazers count: 47.1%
Last synced: 11 months ago
formulae.brew.sh: aws-c-compression

C99 implementation of huffman encoding/decoding

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 2,407 Last month
Rankings
Dependent packages count: 17.9%
Average: 45.5%
Dependent repos count: 52.0%
Downloads: 66.5%
Last synced: 11 months ago
anaconda.org: aws-c-compression

This is a cross-platform C99 implementation of compression algorithms such as gzip, and huffman encoding/decoding. Currently only huffman is implemented.

  • Versions: 2
  • Dependent Packages: 2
  • Dependent Repositories: 0
Rankings
Dependent packages count: 50.7%
Average: 55.2%
Dependent repos count: 59.6%
Last synced: 11 months ago
alpine-v3.22: aws-c-compression-dev

C99 implementation of huffman encoding/decoding (development files)

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 11 months ago
alpine-v3.19: aws-c-compression-dev

C99 implementation of huffman encoding/decoding (development files)

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Last synced: 11 months ago
alpine-v3.19: aws-c-compression

C99 implementation of huffman encoding/decoding

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Last synced: 11 months ago
alpine-v3.21: aws-c-compression-dev

C99 implementation of huffman encoding/decoding (development files)

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 11 months ago
alpine-v3.20: aws-c-compression-dev

C99 implementation of huffman encoding/decoding (development files)

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Last synced: 12 months ago
alpine-v3.20: aws-c-compression

C99 implementation of huffman encoding/decoding

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Last synced: 12 months ago
alpine-v3.22: aws-c-compression

C99 implementation of huffman encoding/decoding

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 11 months ago
alpine-v3.21: aws-c-compression

C99 implementation of huffman encoding/decoding

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Dependent packages count: 0.0%
Average: 100%
Maintainers (1)
Last synced: 11 months ago

Dependencies

.github/workflows/ci.yml actions
.github/workflows/clang-format.yml actions
  • DoozyX/clang-format-lint-action v0.3.1 composite
  • actions/checkout v1 composite
.github/workflows/closed-issue-message.yml actions
  • aws-actions/closed-issue-message v1 composite
.github/workflows/handle-stale-discussions.yml actions
  • aws-github-ops/handle-stale-discussions v1 composite
.github/workflows/stale_issue.yml actions
  • aws-actions/stale-issue-cleanup v3 composite
.github/workflows/issue-regression-labeler.yml actions
  • actions/github-script v7 composite