<s>
The	O
Lempel	B-General_Concept
–	I-General_Concept
Ziv	I-General_Concept
–	I-General_Concept
Markov	I-General_Concept
chain	I-General_Concept
algorithm	I-General_Concept
(	O
LZMA	B-General_Concept
)	O
is	O
an	O
algorithm	O
used	O
to	O
perform	O
lossless	B-Algorithm
data	I-Algorithm
compression	I-Algorithm
.	O
</s>
<s>
It	O
has	O
been	O
under	O
development	O
since	O
either	O
1996	O
or	O
1998	O
by	O
Igor	B-Language
Pavlov	I-Language
and	O
was	O
first	O
used	O
in	O
the	O
7z	O
format	O
of	O
the	O
7-Zip	B-Language
archiver	O
.	O
</s>
<s>
This	O
algorithm	O
uses	O
a	O
dictionary	B-Algorithm
compression	I-Algorithm
scheme	O
somewhat	O
similar	O
to	O
the	O
LZ77	O
algorithm	O
published	O
by	O
Abraham	O
Lempel	O
and	O
Jacob	O
Ziv	O
in	O
1977	O
and	O
features	O
a	O
high	O
compression	O
ratio	O
(	O
generally	O
higher	O
than	O
bzip2	B-Application
)	O
and	O
a	O
variable	O
compression-dictionary	O
size	O
(	O
up	O
to	O
4GB	O
)	O
,	O
while	O
still	O
maintaining	O
decompression	O
speed	O
similar	O
to	O
other	O
commonly	O
used	O
compression	O
algorithms	O
.	O
</s>
<s>
LZMA2	O
is	O
a	O
simple	O
container	O
format	O
that	O
can	O
include	O
both	O
uncompressed	O
data	O
and	O
LZMA	B-General_Concept
data	O
,	O
possibly	O
with	O
multiple	O
different	O
LZMA	B-General_Concept
encoding	O
parameters	O
.	O
</s>
<s>
LZMA	B-General_Concept
uses	O
a	O
dictionary	B-Algorithm
compression	I-Algorithm
algorithm	O
(	O
a	O
variant	O
of	O
LZ77	O
with	O
huge	O
dictionary	O
sizes	O
and	O
special	O
support	O
for	O
repeatedly	O
used	O
match	O
distances	O
)	O
,	O
whose	O
output	O
is	O
then	O
encoded	O
with	O
a	O
range	B-Algorithm
encoder	I-Algorithm
,	O
using	O
a	O
complex	O
model	O
to	O
make	O
a	O
probability	O
prediction	O
of	O
each	O
bit	O
.	O
</s>
<s>
The	O
dictionary	O
compressor	O
finds	O
matches	O
using	O
sophisticated	O
dictionary	O
data	O
structures	O
,	O
and	O
produces	O
a	O
stream	O
of	O
literal	O
symbols	O
and	O
phrase	O
references	O
,	O
which	O
is	O
encoded	O
one	O
bit	O
at	O
a	O
time	O
by	O
the	O
range	B-Algorithm
encoder	I-Algorithm
:	O
many	O
encodings	O
are	O
possible	O
,	O
and	O
a	O
dynamic	B-Algorithm
programming	I-Algorithm
algorithm	O
is	O
used	O
to	O
select	O
an	O
optimal	O
one	O
under	O
certain	O
approximations	O
.	O
</s>
<s>
Prior	O
to	O
LZMA	B-General_Concept
,	O
most	O
encoder	O
models	O
were	O
purely	O
byte-based	O
(	O
i.e.	O
</s>
<s>
The	O
main	O
innovation	O
of	O
LZMA	B-General_Concept
is	O
that	O
instead	O
of	O
a	O
generic	O
byte-based	O
model	O
,	O
LZMA	B-General_Concept
's	O
model	O
uses	O
contexts	O
specific	O
to	O
the	O
bitfields	O
in	O
each	O
representation	O
of	O
a	O
literal	O
or	O
phrase	O
:	O
this	O
is	O
nearly	O
as	O
simple	O
as	O
a	O
generic	O
byte-based	O
model	O
,	O
but	O
gives	O
much	O
better	O
compression	O
because	O
it	O
avoids	O
mixing	O
unrelated	O
bits	O
together	O
in	O
the	O
same	O
context	O
.	O
</s>
<s>
Furthermore	O
,	O
compared	O
to	O
classic	O
dictionary	B-Algorithm
compression	I-Algorithm
(	O
such	O
as	O
the	O
one	O
used	O
in	O
zip	B-General_Concept
and	O
gzip	B-Application
formats	O
)	O
,	O
the	O
dictionary	O
sizes	O
can	O
be	O
and	O
usually	O
are	O
much	O
larger	O
,	O
taking	O
advantage	O
of	O
the	O
large	O
amount	O
of	O
memory	O
available	O
on	O
modern	O
systems	O
.	O
</s>
<s>
In	O
LZMA	B-General_Concept
compression	O
,	O
the	O
compressed	O
stream	O
is	O
a	O
stream	O
of	O
bits	O
,	O
encoded	O
using	O
an	O
adaptive	O
binary	O
range	O
coder	O
.	O
</s>
<s>
Both	O
the	O
lzip	B-Application
and	O
the	O
LZMA	B-General_Concept
SDK	O
documentation	O
describes	O
this	O
stream	O
format	O
.	O
</s>
<s>
The	O
description	O
below	O
is	O
based	O
on	O
the	O
compact	O
XZ	B-Language
Embedded	B-Architecture
decoder	O
by	O
Lasse	O
Collin	O
included	O
in	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
source	O
from	O
which	O
the	O
LZMA	B-General_Concept
and	O
LZMA2	O
algorithm	O
details	O
can	O
be	O
relatively	O
easily	O
deduced	O
:	O
thus	O
,	O
while	O
citing	O
source	O
code	O
as	O
reference	O
is	O
not	O
ideal	O
,	O
any	O
programmer	O
should	O
be	O
able	O
to	O
check	O
the	O
claims	O
below	O
with	O
a	O
few	O
hours	O
of	O
work	O
.	O
</s>
<s>
LZMA	B-General_Concept
data	O
is	O
at	O
the	O
lowest	O
level	O
decoded	O
one	O
bit	O
at	O
a	O
time	O
by	O
the	O
range	O
decoder	O
,	O
at	O
the	O
direction	O
of	O
the	O
LZMA	B-General_Concept
decoder	O
.	O
</s>
<s>
Context-based	O
range	O
decoding	O
is	O
invoked	O
by	O
the	O
LZMA	B-General_Concept
algorithm	O
passing	O
it	O
a	O
reference	O
to	O
the	O
"	O
context	O
"	O
,	O
which	O
consists	O
of	O
the	O
unsigned	O
11-bit	O
variable	O
prob	O
(	O
typically	O
implemented	O
using	O
a	O
16-bit	O
data	O
type	O
)	O
representing	O
the	O
predicted	O
probability	O
of	O
the	O
bit	O
being	O
0	O
,	O
which	O
is	O
read	O
and	O
updated	O
by	O
the	O
range	O
decoder	O
(	O
and	O
should	O
be	O
initialized	O
to	O
,	O
representing	O
0.5	O
probability	O
)	O
.	O
</s>
<s>
The	O
Linux	B-Operating_System
kernel	I-Operating_System
implementation	O
of	O
fixed-probability	O
decoding	O
in	O
rc_direct( )	O
,	O
for	O
performance	O
reasons	O
,	O
does	O
not	O
include	O
a	O
conditional	O
branch	O
,	O
but	O
instead	O
subtracts	O
range	O
from	O
code	O
unconditionally	O
.	O
</s>
<s>
Non-reverse	O
bit-tree	O
decoding	O
thus	O
happens	O
from	O
most	O
significant	O
to	O
least	O
significant	O
bit	O
,	O
stopping	O
when	O
only	O
one	O
value	O
in	O
the	O
valid	O
range	O
is	O
possible	O
(	O
this	O
conceptually	O
allows	O
to	O
have	O
range	O
sizes	O
that	O
are	O
not	O
powers	O
of	O
two	O
,	O
even	O
though	O
LZMA	B-General_Concept
does	O
not	O
make	O
use	O
of	O
this	O
)	O
.	O
</s>
<s>
In	O
the	O
function	O
in	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
,	O
integers	O
are	O
actually	O
returned	O
in	O
the	O
range	O
(	O
with	O
limit	O
added	O
to	O
the	O
conceptual	O
value	O
)	O
,	O
and	O
the	O
variable	O
at	O
index	O
0	O
in	O
the	O
array	O
is	O
unused	O
,	O
while	O
the	O
one	O
at	O
index	O
1	O
is	O
the	O
root	O
,	O
and	O
the	O
left	O
and	O
right	O
children	O
indices	O
are	O
computed	O
as	O
2i	O
and	O
2i	O
+	O
1	O
.	O
</s>
<s>
The	O
LZMA	B-General_Concept
decoder	O
is	O
configured	O
by	O
an	O
"	O
properties	O
"	O
byte	O
and	O
a	O
dictionary	O
size	O
.	O
</s>
<s>
In	O
the	O
7-zip	B-Language
LZMA	B-General_Concept
file	O
format	O
,	O
configuration	O
is	O
performed	O
by	O
a	O
header	O
containing	O
the	O
"	O
properties	O
"	O
byte	O
followed	O
by	O
the	O
32-bit	O
little-endian	O
dictionary	O
size	O
in	O
bytes	O
.	O
</s>
<s>
In	O
LZMA2	O
,	O
the	O
properties	O
byte	O
can	O
optionally	O
be	O
changed	O
at	O
the	O
start	O
of	O
LZMA2	O
LZMA	B-General_Concept
packets	O
,	O
while	O
the	O
dictionary	O
size	O
is	O
specified	O
in	O
the	O
LZMA2	O
header	O
as	O
later	O
described	O
.	O
</s>
<s>
The	O
LZMA	B-General_Concept
packet	O
format	O
has	O
already	O
been	O
described	O
,	O
and	O
this	O
section	O
specifies	O
how	O
LZMA	B-General_Concept
statistically	O
models	O
the	O
LZ-encoded	O
streams	O
,	O
or	O
in	O
other	O
words	O
which	O
probability	O
variables	O
are	O
passed	O
to	O
the	O
range	O
decoder	O
to	O
decode	O
each	O
bit	O
.	O
</s>
<s>
The	O
pos_state	O
and	O
literal_pos_state	O
values	O
consist	O
of	O
respectively	O
the	O
pb	O
and	O
lp	O
(	O
up	O
to	O
4	O
,	O
from	O
the	O
LZMA	B-General_Concept
header	O
or	O
LZMA2	O
properties	O
packet	O
)	O
least	O
significant	O
bits	O
of	O
the	O
dictionary	O
position	O
(	O
the	O
number	O
of	O
bytes	O
coded	O
since	O
the	O
last	O
dictionary	O
reset	O
modulo	O
the	O
dictionary	O
size	O
)	O
.	O
</s>
<s>
The	O
prev_byte_lc_msbs	O
value	O
is	O
set	O
to	O
the	O
lc	O
(	O
up	O
to	O
4	O
,	O
from	O
the	O
LZMA	B-General_Concept
header	O
or	O
LZMA2	O
properties	O
packet	O
)	O
most	O
significant	O
bits	O
of	O
the	O
previous	O
uncompressed	O
byte	O
.	O
</s>
<s>
The	O
probability	O
variable	O
groups	O
used	O
in	O
LZMA	B-General_Concept
are	O
those	O
:	O
</s>
<s>
The	O
LZMA2	O
container	O
supports	O
multiple	O
runs	O
of	O
compressed	O
LZMA	B-General_Concept
data	O
and	O
uncompressed	O
data	O
.	O
</s>
<s>
Each	O
LZMA	B-General_Concept
compressed	O
run	O
can	O
have	O
a	O
different	O
LZMA	B-General_Concept
configuration	O
and	O
dictionary	O
.	O
</s>
<s>
Criticism	O
of	O
LZMA2	O
's	O
changes	O
over	O
LZMA	B-General_Concept
include	O
header	O
fields	O
not	O
being	O
covered	O
by	O
CRCs	O
,	O
</s>
<s>
Bits	O
5-6	O
for	O
LZMA	B-General_Concept
chunks	O
can	O
be	O
:	O
</s>
<s>
LZMA	B-General_Concept
state	O
resets	O
cause	O
a	O
reset	O
of	O
all	O
LZMA	B-General_Concept
state	O
except	O
the	O
dictionary	O
,	O
and	O
specifically	O
:	O
</s>
<s>
LZMA	B-General_Concept
chunks	O
consist	O
of	O
:	O
</s>
<s>
The	O
.xz	O
format	O
,	O
which	O
can	O
contain	O
LZMA2	O
data	O
,	O
is	O
documented	O
at	O
tukaani.org,	O
while	O
the	O
.7z	O
file	O
format	O
,	O
which	O
can	O
contain	O
either	O
LZMA	B-General_Concept
or	O
LZMA2	O
data	O
,	O
is	O
documented	O
in	O
the	O
7zformat.txt	O
file	O
contained	O
in	O
the	O
LZMA	B-General_Concept
SDK	O
.	O
</s>
<s>
Similar	O
to	O
the	O
decompression	O
format	O
situation	O
,	O
no	O
complete	O
natural	O
language	O
specification	O
of	O
the	O
encoding	O
techniques	O
in	O
7-zip	B-Language
or	O
xz	B-Language
seems	O
to	O
exist	O
,	O
other	O
than	O
the	O
one	O
attempted	O
in	O
the	O
following	O
text	O
.	O
</s>
<s>
The	O
description	O
below	O
is	O
based	O
on	O
the	O
XZ	B-Language
for	O
Java	B-Language
encoder	O
by	O
Lasse	O
Collin	O
,	O
which	O
appears	O
to	O
be	O
the	O
most	O
readable	O
among	O
several	O
rewrites	O
of	O
the	O
original	O
7-zip	B-Language
using	O
the	O
same	O
algorithms	O
:	O
again	O
,	O
while	O
citing	O
source	O
code	O
as	O
reference	O
is	O
not	O
ideal	O
,	O
any	O
programmer	O
should	O
be	O
able	O
to	O
check	O
the	O
claims	O
below	O
with	O
a	O
few	O
hours	O
of	O
work	O
.	O
</s>
<s>
The	O
range	B-Algorithm
encoder	I-Algorithm
cannot	O
make	O
any	O
interesting	O
choices	O
,	O
and	O
can	O
be	O
readily	O
constructed	O
based	O
on	O
the	O
decoder	O
description	O
.	O
</s>
<s>
Initialization	O
and	O
termination	O
are	O
not	O
fully	O
determined	O
;	O
the	O
xz	B-Language
encoder	O
outputs	O
0	O
as	O
the	O
first	O
byte	O
which	O
is	O
ignored	O
by	O
the	O
decompressor	O
,	O
and	O
encodes	O
the	O
lower	O
bound	O
of	O
the	O
range	O
(	O
which	O
matters	O
for	O
the	O
final	O
bytes	O
)	O
.	O
</s>
<s>
The	O
xz	B-Language
encoder	O
uses	O
an	O
unsigned	O
33-bit	O
variable	O
called	O
low	O
(	O
typically	O
implemented	O
as	O
a	O
64-bit	O
integer	O
,	O
initialized	O
to	O
0	O
)	O
,	O
an	O
unsigned	O
32-bit	O
variable	O
called	O
range	O
(	O
initialized	O
to	O
)	O
,	O
an	O
unsigned	O
8-bit	O
variable	O
called	O
cache	O
(	O
initialized	O
to	O
0	O
)	O
,	O
and	O
an	O
unsigned	O
variable	O
called	O
cache_size	O
which	O
needs	O
to	O
be	O
large	O
enough	O
to	O
store	O
the	O
uncompressed	O
size	O
(	O
initialized	O
to	O
1	O
,	O
typically	O
implemented	O
as	O
a	O
64-bit	O
integer	O
)	O
.	O
</s>
<s>
Note	O
that	O
the	O
first	O
byte	O
output	O
will	O
always	O
be	O
0	O
due	O
to	O
the	O
fact	O
that	O
cache	O
and	O
low	O
are	O
initialized	O
to	O
0	O
,	O
and	O
the	O
encoder	O
implementation	O
;	O
the	O
xz	B-Language
decoder	O
ignores	O
this	O
byte	O
.	O
</s>
<s>
Context-based	O
range	B-Algorithm
encoding	I-Algorithm
of	O
a	O
bit	O
using	O
the	O
prob	O
probability	O
variable	O
proceeds	O
in	O
this	O
way	O
:	O
</s>
<s>
Fixed-probability	O
range	B-Algorithm
encoding	I-Algorithm
of	O
a	O
bit	O
proceeds	O
in	O
this	O
way	O
:	O
</s>
<s>
Since	O
LZMA	B-General_Concept
uses	O
very	O
large	O
dictionaries	O
(	O
potentially	O
on	O
the	O
order	O
of	O
gigabytes	O
)	O
to	O
improve	O
compression	O
,	O
simply	O
scanning	O
the	O
whole	O
dictionary	O
would	O
result	O
in	O
an	O
encoder	O
too	O
slow	O
to	O
be	O
practically	O
usable	O
,	O
so	O
sophisticated	O
data	O
structures	O
are	O
needed	O
to	O
support	O
fast	O
match	O
searches	O
.	O
</s>
<s>
The	O
simplest	O
approach	O
,	O
called	O
"	O
hash	B-Algorithm
chains	I-Algorithm
"	O
,	O
is	O
parameterized	O
by	O
a	O
constant	O
N	O
which	O
can	O
be	O
either	O
2	O
,	O
3	O
or	O
4	O
,	O
which	O
is	O
typically	O
chosen	O
so	O
that	O
is	O
greater	O
than	O
or	O
equal	O
to	O
the	O
dictionary	O
size	O
.	O
</s>
<s>
To	O
find	O
matches	O
of	O
length	O
N	O
or	O
higher	O
,	O
a	O
search	O
is	O
started	O
using	O
the	O
N-sized	O
hash	O
table	O
,	O
and	O
continued	O
using	O
the	O
hash	B-Algorithm
chain	I-Algorithm
array	O
;	O
the	O
search	O
stop	O
after	O
a	O
pre-defined	O
number	O
of	O
hash	B-Algorithm
chain	I-Algorithm
nodes	O
has	O
been	O
traversed	O
,	O
or	O
when	O
the	O
hash	B-Algorithm
chains	I-Algorithm
"	O
wraps	O
around	O
"	O
,	O
indicating	O
that	O
the	O
portion	O
of	O
the	O
input	O
that	O
has	O
been	O
overwritten	O
in	O
the	O
dictionary	O
has	O
been	O
reached	O
.	O
</s>
<s>
LZMA	B-General_Concept
uses	O
Markov	O
chains	O
,	O
as	O
implied	O
by	O
"	O
M	O
"	O
in	O
its	O
name	O
.	O
</s>
<s>
The	O
binary	O
tree	O
approach	O
follows	O
the	O
hash	B-Algorithm
chain	I-Algorithm
approach	O
,	O
except	O
that	O
it	O
logically	O
uses	O
a	O
binary	O
tree	O
instead	O
of	O
a	O
linked	O
list	O
for	O
chaining	O
.	O
</s>
<s>
The	O
binary	O
tree	O
is	O
maintained	O
so	O
that	O
it	O
is	O
always	O
both	O
a	O
search	B-Data_Structure
tree	I-Data_Structure
relative	O
to	O
the	O
suffix	O
lexicographic	O
ordering	O
,	O
and	O
a	O
max-heap	O
for	O
the	O
dictionary	O
position	O
(	O
in	O
other	O
words	O
,	O
the	O
root	O
is	O
always	O
the	O
most	O
recent	O
string	O
,	O
and	O
a	O
child	O
cannot	O
have	O
been	O
added	O
more	O
recently	O
than	O
its	O
parent	O
)	O
:	O
assuming	O
all	O
strings	O
are	O
lexicographically	O
ordered	O
,	O
these	O
conditions	O
clearly	O
uniquely	O
determine	O
the	O
binary	O
tree	O
(	O
this	O
is	O
trivially	O
provable	O
by	O
induction	O
on	O
the	O
size	O
of	O
the	O
tree	O
)	O
.	O
</s>
<s>
Some	O
old	O
LZMA	B-General_Concept
encoders	O
also	O
supported	O
a	O
data	O
structure	O
based	O
on	O
Patricia	O
tries	O
,	O
but	O
such	O
support	O
has	O
since	O
been	O
dropped	O
since	O
it	O
was	O
deemed	O
inferior	O
to	O
the	O
other	O
options	O
.	O
</s>
<s>
LZMA	B-General_Concept
encoders	O
can	O
freely	O
decide	O
which	O
match	O
to	O
output	O
,	O
or	O
whether	O
to	O
ignore	O
the	O
presence	O
of	O
matches	O
and	O
output	O
literals	O
anyway	O
.	O
</s>
<s>
The	O
ability	O
to	O
recall	O
the	O
4	O
most	O
recently	O
used	O
distances	O
means	O
that	O
,	O
in	O
principle	O
,	O
using	O
a	O
match	O
with	O
a	O
distance	O
that	O
will	O
be	O
needed	O
again	O
later	O
may	O
be	O
globally	O
optimal	O
even	O
if	O
it	O
is	O
not	O
locally	O
optimal	O
,	O
and	O
as	O
a	O
result	O
of	O
this	O
,	O
optimal	O
LZMA	B-General_Concept
compression	O
probably	O
requires	O
knowledge	O
of	O
the	O
whole	O
input	O
and	O
might	O
require	O
algorithms	O
too	O
slow	O
to	O
be	O
usable	O
in	O
practice	O
.	O
</s>
<s>
The	O
xz	B-Language
encoders	O
use	O
a	O
value	O
called	O
nice_len	O
(	O
the	O
default	O
is	O
64	O
)	O
:	O
when	O
any	O
match	O
of	O
length	O
at	O
least	O
nice_len	O
is	O
found	O
,	O
the	O
encoder	O
stops	O
the	O
search	O
and	O
outputs	O
it	O
,	O
with	O
the	O
maximum	O
matching	O
length	O
.	O
</s>
<s>
The	O
XZ	B-Language
fast	O
encoder	O
(	O
derived	O
from	O
the	O
7-zip	B-Language
fast	O
encoder	O
)	O
is	O
the	O
shortest	O
LZMA	B-General_Concept
encoder	O
in	O
the	O
xz	B-Language
source	O
tree	O
.	O
</s>
<s>
The	O
XZ	B-Language
normal	O
encoder	O
(	O
derived	O
from	O
the	O
7-zip	B-Language
normal	O
encoder	O
)	O
is	O
the	O
other	O
LZMA	B-General_Concept
encoder	O
in	O
the	O
xz	B-Language
source	O
tree	O
,	O
which	O
adopts	O
a	O
more	O
sophisticated	O
approach	O
that	O
tries	O
to	O
minimize	O
the	O
post-range-encoding	O
size	O
of	O
the	O
generated	O
packets	O
.	O
</s>
<s>
Specifically	O
,	O
it	O
encodes	O
portions	O
of	O
the	O
input	O
using	O
the	O
result	O
of	O
a	O
dynamic	B-Algorithm
programming	I-Algorithm
algorithm	O
,	O
where	O
the	O
subproblems	O
are	O
finding	O
the	O
approximately	O
optimal	O
encoding	O
(	O
the	O
one	O
with	O
minimal	O
post-range-encoding	O
size	O
)	O
of	O
the	O
substring	O
of	O
length	O
L	O
starting	O
at	O
the	O
byte	O
being	O
compressed	O
.	O
</s>
<s>
The	O
size	O
of	O
the	O
portion	O
of	O
the	O
input	O
processed	O
in	O
the	O
dynamic	B-Algorithm
programming	I-Algorithm
algorithm	O
is	O
determined	O
to	O
be	O
the	O
maximum	O
between	O
the	O
longest	O
dictionary	O
match	O
and	O
the	O
longest	O
repeated	O
match	O
found	O
at	O
the	O
start	O
position	O
(	O
which	O
is	O
capped	O
by	O
the	O
maximum	O
LZMA	B-General_Concept
match	O
length	O
,	O
273	O
)	O
;	O
furthermore	O
,	O
if	O
a	O
match	O
longer	O
than	O
nice_len	O
is	O
found	O
at	O
any	O
point	O
in	O
the	O
range	O
just	O
defined	O
,	O
the	O
dynamic	B-Algorithm
programming	I-Algorithm
algorithm	O
stops	O
,	O
the	O
solution	O
for	O
the	O
subproblem	O
up	O
to	O
that	O
point	O
is	O
output	O
,	O
the	O
nice_len-sized	O
match	O
is	O
output	O
,	O
and	O
a	O
new	O
dynamic	B-Algorithm
programming	I-Algorithm
problem	O
instance	O
is	O
started	O
at	O
the	O
byte	O
after	O
the	O
match	O
is	O
output	O
.	O
</s>
<s>
Once	O
the	O
final	O
solution	O
of	O
a	O
subproblem	O
is	O
found	O
,	O
the	O
LZMA	B-General_Concept
state	O
and	O
least	O
used	O
distances	O
for	O
it	O
are	O
computed	O
,	O
and	O
are	O
then	O
used	O
to	O
appropriately	O
compute	O
post-range-encoding	O
sizes	O
of	O
its	O
extensions	O
.	O
</s>
<s>
At	O
the	O
end	O
of	O
the	O
dynamic	B-Algorithm
programming	I-Algorithm
optimization	O
,	O
the	O
whole	O
optimal	O
encoding	O
of	O
the	O
longest	O
substring	O
considered	O
is	O
output	O
,	O
and	O
encoding	O
continues	O
at	O
the	O
first	O
uncompressed	O
byte	O
not	O
already	O
encoded	O
,	O
after	O
updating	O
the	O
LZMA	B-General_Concept
state	O
and	O
least	O
used	O
distances	O
.	O
</s>
<s>
The	O
reason	O
for	O
not	O
only	O
extending	O
with	O
single	O
packets	O
is	O
that	O
subproblems	O
only	O
have	O
the	O
substring	O
length	O
as	O
the	O
parameter	O
for	O
performance	O
and	O
algorithmic	O
complexity	O
reasons	O
,	O
while	O
an	O
optimal	O
dynamic	B-Algorithm
programming	I-Algorithm
approach	O
would	O
also	O
require	O
to	O
have	O
the	O
last	O
used	O
distances	O
and	O
LZMA	B-General_Concept
state	O
as	O
parameter	O
;	O
thus	O
,	O
extending	O
with	O
multiple	O
packets	O
allows	O
to	O
better	O
approximate	O
the	O
optimal	O
solution	O
,	O
and	O
specifically	O
to	O
make	O
better	O
use	O
of	O
LONGREP[0]	O
packets	O
.	O
</s>
<s>
Note	O
that	O
in	O
the	O
XZ	B-Language
for	O
Java	B-Language
implementation	O
,	O
the	O
optPrev	O
and	O
backPrev	O
members	O
are	O
reused	O
to	O
store	O
a	O
forward	O
single-linked	O
list	O
of	O
packets	O
as	O
part	O
of	O
outputting	O
the	O
final	O
solution	O
.	O
</s>
<s>
The	O
XZ	B-Language
LZMA2	O
encoder	O
processes	O
the	O
input	O
in	O
chunks	O
(	O
of	O
up	O
to	O
2	O
MB	O
uncompressed	O
size	O
or	O
64	O
KB	O
compressed	O
size	O
,	O
whichever	O
is	O
lower	O
)	O
,	O
handing	O
each	O
chunk	O
to	O
the	O
LZMA	B-General_Concept
encoder	O
,	O
and	O
then	O
deciding	O
whether	O
to	O
output	O
an	O
LZMA2	O
LZMA	B-General_Concept
chunk	O
including	O
the	O
encoded	O
data	O
,	O
or	O
to	O
output	O
an	O
LZMA2	O
uncompressed	O
chunk	O
,	O
depending	O
on	O
which	O
is	O
shorter	O
(	O
LZMA	B-General_Concept
,	O
like	O
any	O
other	O
compressor	O
,	O
will	O
necessarily	O
expand	O
rather	O
than	O
compress	O
some	O
kinds	O
of	O
data	O
)	O
.	O
</s>
<s>
The	O
LZMA	B-General_Concept
state	O
is	O
reset	O
only	O
in	O
the	O
first	O
block	O
,	O
if	O
the	O
caller	O
requests	O
a	O
change	O
of	O
properties	O
and	O
every	O
time	O
a	O
compressed	O
chunk	O
is	O
output	O
.	O
</s>
<s>
The	O
LZMA	B-General_Concept
properties	O
are	O
changed	O
only	O
in	O
the	O
first	O
block	O
,	O
or	O
if	O
the	O
caller	O
requests	O
a	O
change	O
of	O
properties	O
.	O
</s>
<s>
Before	O
LZMA2	O
encoding	O
,	O
depending	O
on	O
the	O
options	O
provided	O
,	O
xz	B-Language
can	O
apply	O
the	O
BCJ	O
filter	O
,	O
which	O
filters	O
executable	O
code	O
to	O
replace	O
relative	O
offsets	O
with	O
absolute	O
ones	O
that	O
are	O
more	O
repetitive	O
,	O
or	O
the	O
delta	O
filter	O
,	O
which	O
replaces	O
each	O
byte	O
with	O
the	O
difference	O
between	O
it	O
and	O
the	O
byte	O
bytes	O
before	O
it	O
.	O
</s>
<s>
Parallel	O
encoding	O
is	O
performed	O
by	O
dividing	O
the	O
file	O
in	O
chunks	O
which	O
are	O
distributed	O
to	O
threads	O
,	O
and	O
ultimately	O
each	O
encoded	O
(	O
using	O
,	O
for	O
instance	O
,	O
xz	B-Language
block	O
encoding	O
)	O
separately	O
,	O
resulting	O
in	O
a	O
dictionary	O
reset	O
between	O
chunks	O
in	O
the	O
output	O
file	O
.	O
</s>
<s>
The	O
LZMA	B-General_Concept
implementation	O
extracted	O
from	O
7-Zip	B-Language
is	O
available	O
as	O
LZMA	B-General_Concept
SDK	O
.	O
</s>
<s>
It	O
was	O
originally	O
dual-licensed	O
under	O
both	O
the	O
GNU	B-Application
LGPL	I-Application
and	O
Common	O
Public	O
License	O
,	O
with	O
an	O
additional	O
special	O
exception	O
for	O
linked	O
binaries	O
,	O
but	O
was	O
placed	O
by	O
Igor	B-Language
Pavlov	I-Language
in	O
the	O
public	O
domain	O
on	O
December	O
2	O
,	O
2008	O
,	O
with	O
the	O
release	O
of	O
version	O
4.62	O
.	O
</s>
<s>
LZMA2	O
compression	O
,	O
which	O
is	O
an	O
improved	O
version	O
of	O
LZMA	B-General_Concept
,	O
is	O
now	O
the	O
default	O
compression	O
method	O
for	O
the	O
.7z	O
format	O
,	O
starting	O
with	O
version	O
9.30	O
on	O
October	O
26	O
,	O
2012	O
.	O
</s>
<s>
The	O
reference	O
open	O
source	O
LZMA	B-General_Concept
compression	O
library	O
was	O
originally	O
written	O
in	O
C++	B-Language
but	O
has	O
been	O
ported	O
to	O
ANSI	B-Language
C	I-Language
,	O
C#	B-Application
,	O
and	O
Java	B-Language
.	O
</s>
<s>
There	O
are	O
also	O
third-party	O
Python	B-Language
bindings	O
for	O
the	O
C++	B-Language
library	O
,	O
as	O
well	O
as	O
ports	O
of	O
LZMA	B-General_Concept
to	O
Pascal	B-Application
,	O
Go	B-Application
and	O
Ada	B-Language
.	O
</s>
<s>
The	O
7-Zip	B-Language
implementation	O
uses	O
several	O
variants	O
of	O
hash	B-Algorithm
chains	I-Algorithm
,	O
binary	O
trees	O
and	O
Patricia	O
trees	O
as	O
the	O
basis	O
for	O
its	O
dictionary	O
search	O
algorithm	O
.	O
</s>
<s>
In	O
addition	O
to	O
LZMA	B-General_Concept
,	O
the	O
SDK	O
and	O
7-Zip	B-Language
also	O
implements	O
multiple	O
preprocessing	O
filters	O
intended	O
to	O
improve	O
compression	O
,	O
ranging	O
from	O
simple	O
delta	B-Algorithm
encoding	I-Algorithm
(	O
for	O
images	O
)	O
and	O
BCJ	O
for	O
executable	O
code	O
.	O
</s>
<s>
Decompression-only	O
code	O
for	O
LZMA	B-General_Concept
generally	O
compiles	O
to	O
around	O
5KB	O
,	O
and	O
the	O
amount	O
of	O
RAM	O
required	O
during	O
decompression	O
is	O
principally	O
determined	O
by	O
the	O
size	O
of	O
the	O
sliding	O
window	O
used	O
during	O
compression	O
.	O
</s>
<s>
Small	O
code	O
size	O
and	O
relatively	O
low	O
memory	O
overhead	O
,	O
particularly	O
with	O
smaller	O
dictionary	O
lengths	O
,	O
and	O
free	O
source	O
code	O
make	O
the	O
LZMA	B-General_Concept
decompression	O
algorithm	O
well-suited	O
to	O
embedded	B-Architecture
applications	O
.	O
</s>
<s>
In	O
addition	O
to	O
the	O
7-Zip	B-Language
reference	O
implementation	O
,	O
the	O
following	O
support	O
the	O
LZMA	B-General_Concept
format	O
.	O
</s>
<s>
xz	B-Language
:	O
a	O
streaming	O
implementation	O
that	O
contains	O
a	O
gzip-like	O
command	O
line	O
tool	O
,	O
supporting	O
both	O
LZMA	B-General_Concept
and	O
LZMA2	O
in	O
its	O
xz	B-Language
file	O
format	O
.	O
</s>
<s>
It	O
made	O
its	O
way	O
into	O
several	O
software	O
of	O
the	O
Unix-like	B-Operating_System
world	O
with	O
its	O
high	O
performance	O
(	O
compared	O
to	O
bzip2	B-Application
)	O
and	O
small	O
size	O
(	O
compared	O
to	O
gzip	B-Application
)	O
.	O
</s>
<s>
The	O
Linux	B-Operating_System
kernel	I-Operating_System
,	O
dpkg	B-Language
and	O
RPM	B-Application
systems	O
contains	O
xz	B-Language
code	O
,	O
and	O
many	O
software	O
distributors	O
like	O
kernel.org,	O
Debian	O
and	O
Fedora	O
now	O
use	O
xz	B-Language
for	O
compressing	O
their	O
releases	O
.	O
</s>
<s>
lzip	B-Application
:	O
another	O
LZMA	B-General_Concept
implementation	O
mostly	O
for	O
Unix-like	B-Operating_System
systems	I-Operating_System
to	O
be	O
directly	O
competing	O
with	O
xz	B-Language
.	O
</s>
<s>
ZIPX	B-General_Concept
:	O
an	O
extension	O
to	O
the	O
ZIP	B-General_Concept
compressions	O
format	O
that	O
was	O
created	O
by	O
WinZip	B-Application
starting	O
with	O
version	O
12.1	O
.	O
</s>
<s>
It	O
also	O
can	O
use	O
various	O
other	O
compression	O
methods	O
such	O
as	O
BZip	B-Application
and	O
PPMd	B-Algorithm
.	O
</s>
<s>
LZHAM	O
(	O
LZ	O
,	O
Huffman	O
,	O
Arithmetic	O
,	O
Markov	O
)	O
,	O
is	O
an	O
LZMA-like	O
implementation	O
that	O
trades	O
compression	O
throughput	O
for	O
very	O
high	O
ratios	O
and	O
higher	O
decompression	O
throughput	O
.	O
</s>
