ArticleslgStudy

computer science

Liblzg

Liblzg is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Liblzg rather than just read about it. In short: liblzg is a compression library for performing lossless data compression. It implements an algorithm that is a variation of the LZ77 algorithm, called the LZG algorithm, with the primary focus of providing a very simple and fast decoding method.

Key takeaways

  • Liblzg belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Liblzg to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Liblzg from memory before moving on to harder problems.

Reference excerpt

liblzg is a compression library for performing lossless data compression. It implements an algorithm that is a variation of the LZ77 algorithm, called the LZG algorithm, with the primary focus of providing a very simple and fast decoding method. One of the key features of the algorithm is that it requires no memory during decompression. The software library is free software, distributed under the zlib license.

Algorithm

If a duplicate series of bytes (a repeated string) is spotted in the uncompressed data stream, then a back-reference is inserted, linking to the previous location of that identical string instead. An encoded match to an earlier string consists of a length (3–128 bytes) and a distance (1–526,341 bytes). The level of compression can be controlled by specifying the maximum distance for which duplicated strings will be searched (this is the size of the sliding window).

Data format The data format consists of a header, followed by the compressed data. The header contains an identifier and house keeping information, such as compressed and decompressed data sizes and a 32-bit checksum (a variant of the Fletcher checksum). The compressed data starts with four bytes, identifying four unique 8-bit marker symbols (m1, m2, m3 and m4). These are used to separate literal data bytes from various forms of length-distance pair encodings. Any symbol that is not a marker byte is considered a literal byte, and will be copied as is to the decompressed data buffer. However, if the decoder encounters any of the four marker bytes, it will decode a length-distance pair that is used as a back reference into the previously decompressed data. The marker bytes are interpreted as follows (% denotes a binary number):

General copy (m1) m1 represents the most general form of a copy operation, and it occupies four bytes in the compressed data stream:

...where length=DECODELENGTH(%lllll+2), and offset=%ooommmmmmmmnnnnnnnn + 2056.

Medium copy (m2) m2 is a shorter form of a copy operation, occupying three bytes in the compressed data stream:

...where length=DECODELENGTH(%lllll+2), and offset=%ooommmmmmmm + 8.

Short copy (m3) m3 requires only two bytes, and is used for short lengths, close to the marker:

...where length=%ll+3, and offset=%oooooo + 8.

Near copy (m4) m4 requires only two bytes, and is used for nearby copies (including RLE, when the offset is 1):

...where length=DECODELENGTH(%lllll+2), and offset=%ooo + 1.

Literal copy As a special case, if any of the marker symbols are followed by a zero byte (0), the marker symbol itself is written to the decompressed buffer.

Non-linear length encoding The DECODELENGTH function implements a non-linear mapping of a number in the range 3-33 to a number in the range 3-128, according to the following table:

Worst case data growth As the marker symbols are chosen as the four least common symbols in the uncompressed data stream (with a probability of at most 1 256 {\displaystyle {\tfrac {1}{256}}} each), and a single occurrence of a marker symbol requires two bytes to encode, the compressed data may grow by at most 4 256 {\displaystyle {\tfrac {4}{256}}} < 1.6% compared to the decompressed data (worst case). The liblzg library compensates for this by using a plain 1:1 copy mode if the encoder identifies that the compressed data will be larger than the original uncompressed data. Hence, in practice, the maximum data growth is 0% (plus the size of the data header, which is 16 bytes).

Implementations Both the compression and the decompression algorithms are implemented in an open source library, written in the C programming language. There are also several alternate implementations of the decompression algorithm available (for instance in JavaScript and 8-bit assembly language).

See also

LZ77 and LZ78 Run-length encoding

External links liblzg home page

Worked examples

Example 1 — a first encounter with Liblzg

Start with the simplest possible case. Write down what Liblzg claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Liblzg before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Liblzg ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Liblzg

In research
Liblzg appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Liblzg in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Liblzg is common in secondary-school and first-year university syllabi. It links to neighbouring topics Data compression, Free data compression software, Lossless compression algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Liblzg outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Liblzg in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Liblzg means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Liblzg out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Liblzg in simple terms?

liblzg is a compression library for performing lossless data compression. It implements an algorithm that is a variation of the LZ77 algorithm, called the LZG algorithm, with the primary focus of providing a very simple and fast decoding method.

Why does Liblzg matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Liblzg?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Liblzg.

Tags

  • Data compression
  • Free data compression software
  • Lossless compression algorithms
  • Software using the zlib license

Keep exploring