Skip to content

Latest commit

 

History

History
53 lines (43 loc) · 2.28 KB

README.md

File metadata and controls

53 lines (43 loc) · 2.28 KB

LZ78 compressing algorithm GoDoc

The package LZ78 can be used to compress and decompress strings into something nice: emojis.

LZ78 is a lossless data compression algorithm, which form the basis of several ubiquitous compression schemes, including GIF and the DEFLATE algorithm used in PNG and ZIP. It has a simple algorithm which consist of finding repeating phrases (sequences of characters) and storing them in a tree like dictionary.

Demo

We have built a full working demo at emoji-compress.com

How

  • Compress function will iterate a string (slice of byte) character by character and create a dictionary embedded in the output.
  • Decompress function will use the embedded dictionary to recompose original string.

Limitations:

  • the emojis database has only around 1000 unique emojis, so the maximum length of a source text is limited
  • the output length of the text could be bigger than the origina, if no sequences of characters repeat

Example

  // Compress
	in := "Play with emojis!"
	out, err := CompressString(in)
	if err != nil {
		log.Panic(err)
	}
	fmt.Printf("%s", out)
	// Output: 😀P😀l😀a😀y😀 😀w😀i😀t😀h😃e😀m😀o😀j😅s😀!

  // Decompress
	in := "😀P😀l😀a😀y😀 😀w😀i😀t😀h😃e😀m😀o😀j😅s😀!"
	out, err := DecompressString(in)
	if err != nil {
		log.Panic(err)
	}
	fmt.Printf("%s", out)
	// Output: Play with emojis!

This package has unit tests, GoDoc and Examples.

Resources:

About

This package is part of a group of emoji-related encoding and compression algorithms built for fun and academic purposes in Go.

Copyright (c) 2017 B.G.Adrian & @Davidescus