libdragon
Loading...
Searching...
No Matches
Functions
ringbuf.c File Reference

Functions

void __ringbuf_init (decompress_ringbuf_t *ringbuf, uint8_t *buf, int size)
 Initialize a ring buffer for streaming decompression.
 
void __ringbuf_write (decompress_ringbuf_t *ringbuf, uint8_t *src, int count)
 Write an array of bytes into the ring buffer.
 
void __ringbuf_copy (decompress_ringbuf_t *ringbuf, int copy_offset, uint8_t *dst, int count)
 Extract data from the ring buffer, updating it at the same time.
 

Detailed Description

Author
Giovanni Bajo giova.nosp@m.nnib.nosp@m.ajo@g.nosp@m.mail.nosp@m..com

Function Documentation

◆ __ringbuf_init()

void __ringbuf_init ( decompress_ringbuf_t ringbuf,
uint8_t *  buf,
int  winsize 
)

Initialize a ring buffer for streaming decompression.

Parameters
ringbufPointer to the ring buffer structure to initialize.
bufBuffer to use as the ring buffer storage.
winsizeWindow size (must be a power of 2).

◆ __ringbuf_write()

void __ringbuf_write ( decompress_ringbuf_t ringbuf,
uint8_t *  src,
int  count 
)

Write an array of bytes into the ring buffer.

Parameters
ringbufThe ring buffer to write to.
srcThe source array to write from.
countThe number of bytes to write.

◆ __ringbuf_copy()

void __ringbuf_copy ( decompress_ringbuf_t ringbuf,
int  copy_offset,
uint8_t *  dst,
int  count 
)

Extract data from the ring buffer, updating it at the same time.

This function is used to implement a typical match-copy of LZ algorithms. Given the ring buffer and the position to copy from, it will copy the specified number of bytes into the destination buffer, while also updating the ring buffer with the copied data.

It correctly handles overlaps, so if copy_offset is 1 and count is 100, the last character in the ring buffer will be copied 100 times to the output (and to the ring buffer itself).

Parameters
ringbufThe ring buffer
copy_offsetOffset to copy from, relative to the current position.
dstDestination buffer
countNumber of bytes to copy