Add forked and optimized copy of LGPL version of Libbsc.
Strip out Sort Transform from Libbsc copy. Reduce Libbsc memory use. Avoid redundant adler32 of data block in Libbsc.
This commit is contained in:
parent
c4c4b47138
commit
fb25e53b4f
37 changed files with 12401 additions and 20 deletions
18
Makefile.in
18
Makefile.in
|
@ -323,10 +323,7 @@ $(KECCAK_OBJS): $(KECCAK_SRCS) $(KECCAK_HDRS)
|
|||
$(KECCAK_OBJS_ASM): $(KECCAK_SRCS_ASM) $(KECCAK_HDRS)
|
||||
$(COMPILE) $(KECCAK_FLAGS) $(@:.o=.s) -o $@
|
||||
|
||||
$(LIBBSCLIB):
|
||||
(cd $(LIBBSCDIR); make)
|
||||
|
||||
$(LIBBSCWRAPOBJ): $(LIBBSCWRAP) $(LIBBSCLIB)
|
||||
$(LIBBSCWRAPOBJ): $(LIBBSCWRAP)
|
||||
$(COMPILE) $(GEN_OPT) $(VEC_FLAGS) $(CPPFLAGS) $(@:.o=.c) -o $@
|
||||
|
||||
$(TRANSP_OBJS): $(TRANSP_SRCS) $(TRANSP_HDRS)
|
||||
|
@ -367,14 +364,18 @@ $(MAINOBJS): $(MAINSRCS) $(MAINHDRS)
|
|||
$(PROGOBJS): $(PROGSRCS) $(PROGHDRS)
|
||||
$(COMPILE) $(GEN_OPT) $(LOOP_OPTFLAGS) $(CPPFLAGS) $(@:.o=.c) -o $@
|
||||
|
||||
$(LIB): $(OBJS)
|
||||
$(LIBBSCLIB):
|
||||
(cd $(LIBBSCDIR); make)
|
||||
|
||||
$(LIB): $(OBJS) $(LIBBSCLIB)
|
||||
$(LINK.LIB) -Wl,-soname,$(LIB).$(LIBVER) -o $(LIB).$(LIBVER) $(OBJS) $(LDLIBS)
|
||||
ln -sf $(LIB).$(LIBVER) $(LIB)
|
||||
|
||||
$(PROG): $(LIB) $(PROGOBJS)
|
||||
$(LINK.PROG) -o $@ $(PROGOBJS) $(LDLIBS) -L. -l$(LINKLIB)
|
||||
./buildtmp/$(PROG):
|
||||
mkdir -p buildtmp
|
||||
cp $@ buildtmp
|
||||
$(LINK.PROG) -o $@ $(PROGOBJS) $(LDLIBS) -L. -l$(LINKLIB)
|
||||
|
||||
$(PROG): $(LIB) $(PROGOBJS) ./buildtmp/$(PROG)
|
||||
cat utils/pcompress.sh | sed "s#<PC_PATH>#`pwd`#" > pcompress
|
||||
chmod +x pcompress
|
||||
|
||||
|
@ -389,6 +390,7 @@ clean:
|
|||
|
||||
distclean: clean
|
||||
$(RM) Makefile
|
||||
(cd $(LIBBSCDIR); make clean)
|
||||
|
||||
install: $(PROG)
|
||||
@mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||
|
|
13
bsc/AUTHORS
Normal file
13
bsc/AUTHORS
Normal file
|
@ -0,0 +1,13 @@
|
|||
-- Authors of bsc and libbsc
|
||||
|
||||
Ilya Grebnov <Ilya.Grebnov@gmail.com>
|
||||
|
||||
-- This program is based on (at least) the work of
|
||||
|
||||
Yuta Mori, Charles Bloom, Julian Seward, Mike Burrows, Matt Mahoney,
|
||||
David Wheeler, Sebastian Deorowicz, Florin Ghido, Peter Fenwick,
|
||||
Michael Schindler, Bulat Ziganshin, Eugene Shelwien, Yann Collet,
|
||||
Dmitry Shkarin, Mark Adler, Przemyslaw Skibinski, Duane Merrill.
|
||||
|
||||
|
||||
|
64
bsc/CHANGES
Normal file
64
bsc/CHANGES
Normal file
|
@ -0,0 +1,64 @@
|
|||
Changes in 3.1.0 (July 8, 2012)
|
||||
- Added Kepler GPU support with CUDA Toolkit 4.2
|
||||
|
||||
Changes in 3.0.0 (August 26, 2011)
|
||||
- NVIDIA GPU acceleration of forward ST algorithms
|
||||
- Added Sort Transform of order 7 & 8 (GPU only)
|
||||
|
||||
Changes in 2.8.0 (August 8, 2011)
|
||||
- Added parallel version of LZP algorithm
|
||||
- Large RAM pages (2 MB) support for Windows
|
||||
- Improved performance of ST and BWT algorithms
|
||||
|
||||
Changes in 2.7.0 (June 5, 2011)
|
||||
- Improved performance of LZP algorithm
|
||||
|
||||
Changes in 2.6.1 (May 4, 2011)
|
||||
- Fixed bug in segmentation algorithm
|
||||
|
||||
Changes in 2.6.0 (April 30, 2011)
|
||||
- Added Sort Transform of order 6
|
||||
|
||||
Changes in 2.5.0 (March 20, 2011)
|
||||
- Some minor performance improvments
|
||||
- CRC32 replaced with Adler32
|
||||
|
||||
Changes in 2.4.5 (January 3, 2011)
|
||||
- Improved performance of reverse BWT and ST algorithms
|
||||
|
||||
Changes in 2.4.0 (October 18, 2010)
|
||||
- Improved performance of reverse BWT and ST algorithms
|
||||
|
||||
Changes in 2.3.0 (August 9, 2010)
|
||||
- Improved performance of QLFC algorithm
|
||||
|
||||
Changes in 2.2.5 (July 5, 2010)
|
||||
- Added parallel version of segmentation algorithm
|
||||
|
||||
Changes in 2.2.0 (June 15, 2010)
|
||||
- Added parallel version of reverse BWT transform
|
||||
- Added parallel version of forward ST transform
|
||||
|
||||
Changes in 2.1.5 (June 1, 2010)
|
||||
- Improved multi-core systems support
|
||||
- Improved segmentation algorithm
|
||||
|
||||
Changes in 2.1.0 (May 17, 2010)
|
||||
- Added GNU C++ compiler support
|
||||
- Added makefile
|
||||
|
||||
Changes in 2.0.0 (May 3, 2010)
|
||||
- Released source code under LGPL license
|
||||
- Added multi-core systems support
|
||||
- Added fast "-f" compression mode
|
||||
- Added Sort Transform of order 3
|
||||
|
||||
Changes in 1.0.3 (April 11, 2010)
|
||||
- Fixed bug in block-sorting algorithm
|
||||
- Added support for large files(>2Gb long)
|
||||
|
||||
Changes in 1.0.1 (April 8, 2010)
|
||||
- Decreased memory usage from 6 to 5 times per block size
|
||||
|
||||
Changes in 1.0.0 (April 7, 2010)
|
||||
- First public version for community technology preview
|
674
bsc/COPYING
Normal file
674
bsc/COPYING
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
165
bsc/COPYING.LIB
Normal file
165
bsc/COPYING.LIB
Normal file
|
@ -0,0 +1,165 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
145
bsc/README
Normal file
145
bsc/README
Normal file
|
@ -0,0 +1,145 @@
|
|||
Introduction:
|
||||
-------------
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bsc is a high performance file compressor based on lossless,
|
||||
block-sorting data compression algorithms.
|
||||
|
||||
libbsc is a library based on bsc, it uses the same algorithms
|
||||
as bsc and enables you to compress memory blocks.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
See the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
Software License:
|
||||
-----------------
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
|
||||
Memory usage:
|
||||
-------------
|
||||
|
||||
bsc compresses large files in blocks. Multiple blocks can be processed in
|
||||
parallel on multiple-core CPU. At decompression time, the block size used
|
||||
for compression is read from the header of the compressed file. The block
|
||||
size and number of blocks processed in parallel affects both the compression
|
||||
ratio achieved, and the amount of memory needed for compression and decompression.
|
||||
Compression and decompression requirements are the same and in bytes, can
|
||||
be estimated as 16Mb + 5 x block size x number of blocks processed in parallel.
|
||||
|
||||
GPU memory usage for NVIDIA CUDA technology is different from CPU memory usage
|
||||
and can be estimated as 20 x block size.
|
||||
|
||||
|
||||
NVIDIA GPU acceleration:
|
||||
------------------------
|
||||
|
||||
1. libbsc uses NVIDIA CUDA technology, resulting in a performance boost on computers
|
||||
with NVIDIA GPU of compute capability 1.1 or higher. Lists of supported GPUs
|
||||
can be found on the NVIDIA website http://developer.nvidia.com/cuda-gpus.
|
||||
You also need to install latest graphics drivers that support CUDA.
|
||||
|
||||
2. Individual kernels are limited to a 2-second runtime by Windows. Kernels that run for
|
||||
longer than 2 seconds will trigger the Timeout Detection and Recovery (TDR) mechanism.
|
||||
Detailed information on disabling the Windows TDR is available at:
|
||||
http://msdn.microsoft.com/en-us/windows/hardware/gg487368.aspx#E2
|
||||
|
||||
|
||||
Sort Transform:
|
||||
---------------
|
||||
|
||||
Sort Transform is patented by Michael Schindler under US patent 6,199,064.
|
||||
However for research purposes this algorithm is included in this software.
|
||||
So if you are of the type who should worry about this (making money) worry away.
|
||||
The author shall have no liability with respect to the infringement of
|
||||
copyrights, trade secrets or any patents by this software. In no event will
|
||||
the author be liable for any lost revenue or profits or other special,
|
||||
indirect and consequential damages.
|
||||
|
||||
Sort Transform is disabled by default and can be enabled by defining the
|
||||
preprocessor macro LIBBSC_SORT_TRANSFORM_SUPPORT at compile time.
|
||||
|
||||
|
||||
Back 40 Computing:
|
||||
------------------
|
||||
|
||||
The Back 40 Computing project is a collection of fast, efficient GPU
|
||||
primitives. This project implements a very fast, efficient radix sorting
|
||||
method for CUDA-capable devices. libbsc uses the Back 40 Computing
|
||||
primitives for constructing Sort Transform for CUDA-capable devices.
|
||||
|
||||
The Back 40 Computing copyright is as follows:
|
||||
|
||||
Copyright 2010-2011 Duane Merrill
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
See also the Back 40 Computing web site:
|
||||
http://code.google.com/p/back40computing/ for more information.
|
||||
|
||||
|
||||
libdivsufsort:
|
||||
--------------
|
||||
|
||||
The libdivsufsort project provides a fast, lightweight, and robust
|
||||
C API library to construct the suffix array and the Burrows-Wheeler
|
||||
transformed string for any input string of a constant-size alphabet.
|
||||
libbsc uses libdivsufsort for constructing Burrows-Wheeler transform.
|
||||
|
||||
The libdivsufsort copyright is as follows:
|
||||
|
||||
Copyright (c) 2003-2008 Yuta Mori All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
See also the libdivsufsort web site:
|
||||
http://libdivsufsort.googlecode.com/ for more information.
|
1
bsc/VERSION
Normal file
1
bsc/VERSION
Normal file
|
@ -0,0 +1 @@
|
|||
3.1.0
|
884
bsc/bsc.cpp
Normal file
884
bsc/bsc.cpp
Normal file
|
@ -0,0 +1,884 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Block Sorting Compressor */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
/*--
|
||||
|
||||
Sort Transform is patented by Michael Schindler under US patent 6,199,064.
|
||||
However for research purposes this algorithm is included in this software.
|
||||
So if you are of the type who should worry about this (making money) worry away.
|
||||
The author shall have no liability with respect to the infringement of
|
||||
copyrights, trade secrets or any patents by this software. In no event will
|
||||
the author be liable for any lost revenue or profits or other special,
|
||||
indirect and consequential damages.
|
||||
|
||||
Sort Transform is disabled by default and can be enabled by defining the
|
||||
preprocessor macro LIBBSC_SORT_TRANSFORM_SUPPORT at compile time.
|
||||
|
||||
--*/
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "libbsc/libbsc.h"
|
||||
#include "libbsc/filters.h"
|
||||
#include "libbsc/platform/platform.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
#define LIBBSC_CONTEXTS_AUTODETECT 3
|
||||
|
||||
unsigned char bscFileSign[4] = {'b', 's', 'c', 0x31};
|
||||
|
||||
typedef struct BSC_BLOCK_HEADER
|
||||
{
|
||||
long long blockOffset;
|
||||
signed char recordSize;
|
||||
signed char sortingContexts;
|
||||
} BSC_BLOCK_HEADER;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
int paramBlockSize = 25 * 1024 * 1024;
|
||||
int paramBlockSorter = LIBBSC_BLOCKSORTER_BWT;
|
||||
int paramCoder = LIBBSC_CODER_QLFC_STATIC;
|
||||
int paramSortingContexts = LIBBSC_CONTEXTS_FOLLOWING;
|
||||
|
||||
int paramEnableParallelProcessing = 1;
|
||||
int paramEnableMultiThreading = 1;
|
||||
int paramEnableFastMode = 1;
|
||||
int paramEnableLargePages = 0;
|
||||
int paramEnableCUDA = 0;
|
||||
int paramEnableSegmentation = 0;
|
||||
int paramEnableReordering = 0;
|
||||
int paramEnableLZP = 1;
|
||||
int paramLZPHashSize = 16;
|
||||
int paramLZPMinLen = 128;
|
||||
|
||||
int paramFeatures()
|
||||
{
|
||||
int features =
|
||||
(paramEnableFastMode ? LIBBSC_FEATURE_FASTMODE : LIBBSC_FEATURE_NONE) |
|
||||
(paramEnableMultiThreading ? LIBBSC_FEATURE_MULTITHREADING : LIBBSC_FEATURE_NONE) |
|
||||
(paramEnableLargePages ? LIBBSC_FEATURE_LARGEPAGES : LIBBSC_FEATURE_NONE) |
|
||||
(paramEnableCUDA ? LIBBSC_FEATURE_CUDA : LIBBSC_FEATURE_NONE)
|
||||
;
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && (defined(_GLIBCXX_USE_LFS) || defined(__MINGW32__))
|
||||
#define BSC_FSEEK fseeko64
|
||||
#define BSC_FTELL ftello64
|
||||
#define BSC_FILEOFFSET off64_t
|
||||
#elif defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
#define BSC_FSEEK _fseeki64
|
||||
#define BSC_FTELL _ftelli64
|
||||
#define BSC_FILEOFFSET __int64
|
||||
#else
|
||||
#define BSC_FSEEK fseek
|
||||
#define BSC_FTELL ftell
|
||||
#define BSC_FILEOFFSET long
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__) || defined(_MSC_VER)
|
||||
#include <windows.h>
|
||||
double BSC_CLOCK() { return 0.001 * GetTickCount(); }
|
||||
#elif defined (__unix) || defined (__linux__) || defined (__QNX__) || defined (_AIX) || defined (__NetBSD__) || defined(macintosh) || defined (_MAC)
|
||||
#include <sys/time.h>
|
||||
double BSC_CLOCK() { timeval tv; gettimeofday(&tv, 0); return tv.tv_sec + tv.tv_usec * 0.000001; }
|
||||
#else
|
||||
double BSC_CLOCK() { return (double)clock() / CLOCKS_PER_SEC; }
|
||||
#endif
|
||||
|
||||
int segmentedBlock[256];
|
||||
|
||||
void Compression(char * argv[])
|
||||
{
|
||||
if (!paramEnableLZP)
|
||||
{
|
||||
paramLZPHashSize = 0;
|
||||
paramLZPMinLen = 0;
|
||||
}
|
||||
|
||||
FILE * fInput = fopen(argv[2], "rb");
|
||||
if (fInput == NULL)
|
||||
{
|
||||
fprintf(stderr, "Can't open input file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
FILE * fOutput = fopen(argv[3], "wb");
|
||||
if (fOutput == NULL)
|
||||
{
|
||||
fprintf(stderr, "Can't create output file: %s!\n", argv[3]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (BSC_FSEEK(fInput, 0, SEEK_END))
|
||||
{
|
||||
fprintf(stderr, "IO error on file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
BSC_FILEOFFSET fileSize = BSC_FTELL(fInput);
|
||||
if (fileSize < 0)
|
||||
{
|
||||
fprintf(stderr, "IO error on file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (BSC_FSEEK(fInput, 0, SEEK_SET))
|
||||
{
|
||||
fprintf(stderr, "IO error on file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (paramBlockSize > fileSize)
|
||||
{
|
||||
paramBlockSize = (int)fileSize;
|
||||
}
|
||||
|
||||
if (fwrite(bscFileSign, sizeof(bscFileSign), 1, fOutput) != 1)
|
||||
{
|
||||
fprintf(stderr, "IO error on file: %s!\n", argv[3]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int nBlocks = paramBlockSize > 0 ? (int)((fileSize + paramBlockSize - 1) / paramBlockSize) : 0;
|
||||
if (fwrite(&nBlocks, sizeof(nBlocks), 1, fOutput) != 1)
|
||||
{
|
||||
fprintf(stderr, "IO error on file: %s!\n", argv[3]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
double startTime = BSC_CLOCK();
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
int numThreads = 1;
|
||||
if (paramEnableParallelProcessing)
|
||||
{
|
||||
numThreads = omp_get_max_threads();
|
||||
if (numThreads <= nBlocks) paramEnableMultiThreading = 0;
|
||||
if (numThreads >= nBlocks) numThreads = nBlocks;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int segmentationStart = 0, segmentationEnd = 0;
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp parallel num_threads(numThreads) if(numThreads > 1)
|
||||
#endif
|
||||
{
|
||||
unsigned char * buffer = (unsigned char *)bsc_malloc(paramBlockSize + LIBBSC_HEADER_SIZE);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(print)
|
||||
#endif
|
||||
{
|
||||
|
||||
fprintf(stderr, "Not enough memory! Please check README file for more information.\n");
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
BSC_FILEOFFSET blockOffset = 0;
|
||||
int dataSize = 0;
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(input)
|
||||
#endif
|
||||
{
|
||||
if ((feof(fInput) == 0) && (BSC_FTELL(fInput) != fileSize))
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp master
|
||||
#endif
|
||||
{
|
||||
double progress = (100.0 * (double)BSC_FTELL(fInput)) / fileSize;
|
||||
fprintf(stdout, "\rCompressing %.55s(%02d%%)", argv[2], (int)progress);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
blockOffset = BSC_FTELL(fInput);
|
||||
|
||||
int currentBlockSize = paramBlockSize;
|
||||
if (paramEnableSegmentation)
|
||||
{
|
||||
if (segmentationEnd - segmentationStart > 1) currentBlockSize = segmentedBlock[segmentationStart];
|
||||
}
|
||||
|
||||
dataSize = (int)fread(buffer, 1, currentBlockSize, fInput);
|
||||
if (dataSize <= 0)
|
||||
{
|
||||
fprintf(stderr, "\nIO error on file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (paramEnableSegmentation)
|
||||
{
|
||||
bool bSegmentation = false;
|
||||
|
||||
if (segmentationStart == segmentationEnd) bSegmentation = true;
|
||||
if ((segmentationEnd - segmentationStart == 1) && (dataSize != segmentedBlock[segmentationStart])) bSegmentation = true;
|
||||
|
||||
if (bSegmentation)
|
||||
{
|
||||
segmentationStart = 0; segmentationEnd = bsc_detect_segments(buffer, dataSize, segmentedBlock, 256, paramFeatures());
|
||||
if (segmentationEnd <= LIBBSC_NO_ERROR)
|
||||
{
|
||||
switch (segmentationEnd)
|
||||
{
|
||||
case LIBBSC_NOT_ENOUGH_MEMORY : fprintf(stderr, "\nNot enough memory! Please check README file for more information.\n"); break;
|
||||
default : fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
}
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
int newDataSize = segmentedBlock[segmentationStart++];
|
||||
if (dataSize != newDataSize)
|
||||
{
|
||||
BSC_FILEOFFSET pos = BSC_FTELL(fInput) - dataSize + newDataSize;
|
||||
BSC_FSEEK(fInput, pos, SEEK_SET);
|
||||
dataSize = newDataSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dataSize == 0) break;
|
||||
|
||||
signed char recordSize = 1;
|
||||
if (paramEnableReordering)
|
||||
{
|
||||
recordSize = bsc_detect_recordsize(buffer, dataSize, paramFeatures());
|
||||
if (recordSize < LIBBSC_NO_ERROR)
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(print)
|
||||
#endif
|
||||
{
|
||||
switch (recordSize)
|
||||
{
|
||||
case LIBBSC_NOT_ENOUGH_MEMORY : fprintf(stderr, "\nNot enough memory! Please check README file for more information.\n"); break;
|
||||
default : fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
}
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
if (recordSize > 1)
|
||||
{
|
||||
int result = bsc_reorder_forward(buffer, dataSize, recordSize, paramFeatures());
|
||||
if (result != LIBBSC_NO_ERROR)
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(print)
|
||||
#endif
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case LIBBSC_NOT_ENOUGH_MEMORY : fprintf(stderr, "\nNot enough memory! Please check README file for more information.\n"); break;
|
||||
default : fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
}
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signed char sortingContexts = paramSortingContexts;
|
||||
if (paramSortingContexts == LIBBSC_CONTEXTS_AUTODETECT)
|
||||
{
|
||||
sortingContexts = bsc_detect_contextsorder(buffer, dataSize, paramFeatures());
|
||||
if (sortingContexts < LIBBSC_NO_ERROR)
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(print)
|
||||
#endif
|
||||
{
|
||||
switch (sortingContexts)
|
||||
{
|
||||
case LIBBSC_NOT_ENOUGH_MEMORY : fprintf(stderr, "\nNot enough memory!\n"); break;
|
||||
default : fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
}
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sortingContexts == LIBBSC_CONTEXTS_PRECEDING)
|
||||
{
|
||||
int result = bsc_reverse_block(buffer, dataSize, paramFeatures());
|
||||
if (result != LIBBSC_NO_ERROR)
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(print)
|
||||
#endif
|
||||
{
|
||||
fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int blockSize = bsc_compress(buffer, buffer, dataSize, paramLZPHashSize, paramLZPMinLen, paramBlockSorter, paramCoder, paramFeatures());
|
||||
if (blockSize == LIBBSC_NOT_COMPRESSIBLE)
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(input)
|
||||
#endif
|
||||
{
|
||||
sortingContexts = LIBBSC_CONTEXTS_FOLLOWING; recordSize = 1;
|
||||
|
||||
BSC_FILEOFFSET pos = BSC_FTELL(fInput);
|
||||
{
|
||||
BSC_FSEEK(fInput, blockOffset, SEEK_SET);
|
||||
if (dataSize != (int)fread(buffer, 1, dataSize, fInput))
|
||||
{
|
||||
fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
BSC_FSEEK(fInput, pos, SEEK_SET);
|
||||
}
|
||||
|
||||
blockSize = bsc_store(buffer, buffer, dataSize, paramFeatures());
|
||||
}
|
||||
if (blockSize < LIBBSC_NO_ERROR)
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(print)
|
||||
#endif
|
||||
{
|
||||
switch (blockSize)
|
||||
{
|
||||
case LIBBSC_NOT_ENOUGH_MEMORY : fprintf(stderr, "\nNot enough memory! Please check README file for more information.\n"); break;
|
||||
case LIBBSC_NOT_SUPPORTED : fprintf(stderr, "\nSpecified compression method is not supported on this platform!\n"); break;
|
||||
case LIBBSC_GPU_ERROR : fprintf(stderr, "\nGeneral GPU failure! Please check README file for more information.\n"); break;
|
||||
case LIBBSC_GPU_NOT_SUPPORTED : fprintf(stderr, "\nYour GPU is not supported! Please check README file for more information.\n"); break;
|
||||
case LIBBSC_GPU_NOT_ENOUGH_MEMORY : fprintf(stderr, "\nNot enough GPU memory! Please check README file for more information.\n"); break;
|
||||
|
||||
default : fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
}
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(output)
|
||||
#endif
|
||||
{
|
||||
BSC_BLOCK_HEADER header = {blockOffset, recordSize, sortingContexts};
|
||||
|
||||
if (fwrite(&header, sizeof(BSC_BLOCK_HEADER), 1, fOutput) != 1)
|
||||
{
|
||||
fprintf(stderr, "\nIO error on file: %s!\n", argv[3]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((int)fwrite(buffer, 1, blockSize, fOutput) != blockSize)
|
||||
{
|
||||
fprintf(stderr, "\nIO error on file: %s!\n", argv[3]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bsc_free(buffer);
|
||||
}
|
||||
|
||||
fprintf(stdout, "\r%.55s compressed %.0f into %.0f in %.3f seconds.\n", argv[2], (double)fileSize, (double)BSC_FTELL(fOutput), BSC_CLOCK() - startTime);
|
||||
|
||||
fclose(fInput); fclose(fOutput);
|
||||
}
|
||||
|
||||
void Decompression(char * argv[])
|
||||
{
|
||||
FILE * fInput = fopen(argv[2], "rb");
|
||||
if (fInput == NULL)
|
||||
{
|
||||
fprintf(stderr, "Can't open input file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
FILE * fOutput = fopen(argv[3], "wb");
|
||||
if (fOutput == NULL)
|
||||
{
|
||||
fprintf(stderr, "Can't create output file: %s!\n", argv[3]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (BSC_FSEEK(fInput, 0, SEEK_END))
|
||||
{
|
||||
fprintf(stderr, "IO error on file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
BSC_FILEOFFSET fileSize = BSC_FTELL(fInput);
|
||||
if (fileSize < 0)
|
||||
{
|
||||
fprintf(stderr, "IO error on file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (BSC_FSEEK(fInput, 0, SEEK_SET))
|
||||
{
|
||||
fprintf(stderr, "IO error on file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
unsigned char inputFileSign[sizeof(bscFileSign)];
|
||||
|
||||
if (fread(inputFileSign, sizeof(bscFileSign), 1, fInput) != 1)
|
||||
{
|
||||
fprintf(stderr, "This is not bsc archive!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (memcmp(inputFileSign, bscFileSign, sizeof(bscFileSign)) != 0)
|
||||
{
|
||||
fprintf(stderr, "This is not bsc archive or invalid compression method!\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
int nBlocks = 0;
|
||||
if (fread(&nBlocks, sizeof(nBlocks), 1, fInput) != 1)
|
||||
{
|
||||
fprintf(stderr, "This is not bsc archive!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
double startTime = BSC_CLOCK();
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
int numThreads = 1;
|
||||
if (paramEnableParallelProcessing)
|
||||
{
|
||||
numThreads = omp_get_max_threads();
|
||||
if (numThreads <= nBlocks) paramEnableMultiThreading = 0;
|
||||
if (numThreads >= nBlocks) numThreads = nBlocks;
|
||||
}
|
||||
|
||||
#pragma omp parallel num_threads(numThreads) if(numThreads > 1)
|
||||
#endif
|
||||
{
|
||||
int bufferSize = -1; unsigned char * buffer = NULL;
|
||||
|
||||
while (true)
|
||||
{
|
||||
BSC_FILEOFFSET blockOffset = 0;
|
||||
|
||||
signed char sortingContexts = 0;
|
||||
signed char recordSize = 0;
|
||||
int blockSize = 0;
|
||||
int dataSize = 0;
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(input)
|
||||
#endif
|
||||
{
|
||||
if ((feof(fInput) == 0) && (BSC_FTELL(fInput) != fileSize))
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp master
|
||||
#endif
|
||||
{
|
||||
double progress = (100.0 * (double)BSC_FTELL(fInput)) / fileSize;
|
||||
fprintf(stdout, "\rDecompressing %.55s(%02d%%)", argv[2], (int)progress);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
BSC_BLOCK_HEADER header = {0, 0, 0};
|
||||
if (fread(&header, sizeof(BSC_BLOCK_HEADER), 1, fInput) != 1)
|
||||
{
|
||||
fprintf(stderr, "\nUnexpected end of file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
recordSize = header.recordSize;
|
||||
if (recordSize < 1)
|
||||
{
|
||||
fprintf(stderr, "\nThis is not bsc archive or invalid compression method!\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
sortingContexts = header.sortingContexts;
|
||||
if ((sortingContexts != LIBBSC_CONTEXTS_FOLLOWING) && (sortingContexts != LIBBSC_CONTEXTS_PRECEDING))
|
||||
{
|
||||
fprintf(stderr, "\nThis is not bsc archive or invalid compression method!\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
blockOffset = (BSC_FILEOFFSET)header.blockOffset;
|
||||
|
||||
unsigned char bscBlockHeader[LIBBSC_HEADER_SIZE];
|
||||
|
||||
if (fread(bscBlockHeader, LIBBSC_HEADER_SIZE, 1, fInput) != 1)
|
||||
{
|
||||
fprintf(stderr, "\nUnexpected end of file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (bsc_block_info(bscBlockHeader, LIBBSC_HEADER_SIZE, &blockSize, &dataSize, paramFeatures()) != LIBBSC_NO_ERROR)
|
||||
{
|
||||
fprintf(stderr, "\nThis is not bsc archive or invalid compression method!\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if ((blockSize > bufferSize) || (dataSize > bufferSize))
|
||||
{
|
||||
if (blockSize > bufferSize) bufferSize = blockSize;
|
||||
if (dataSize > bufferSize) bufferSize = dataSize;
|
||||
|
||||
if (buffer != NULL) bsc_free(buffer); buffer = (unsigned char *)bsc_malloc(bufferSize);
|
||||
}
|
||||
|
||||
if (buffer == NULL)
|
||||
{
|
||||
fprintf(stderr, "\nNot enough memory! Please check README file for more information.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
memcpy(buffer, bscBlockHeader, LIBBSC_HEADER_SIZE);
|
||||
|
||||
if (fread(buffer + LIBBSC_HEADER_SIZE, blockSize - LIBBSC_HEADER_SIZE, 1, fInput) != 1)
|
||||
{
|
||||
fprintf(stderr, "\nUnexpected end of file: %s!\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dataSize == 0) break;
|
||||
|
||||
int result = bsc_decompress(buffer, blockSize, buffer, dataSize, paramFeatures());
|
||||
if (result < LIBBSC_NO_ERROR)
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(print)
|
||||
#endif
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case LIBBSC_DATA_CORRUPT : fprintf(stderr, "\nThe compressed data is corrupted!\n"); break;
|
||||
case LIBBSC_NOT_ENOUGH_MEMORY : fprintf(stderr, "\nNot enough memory! Please check README file for more information.\n"); break;
|
||||
case LIBBSC_GPU_ERROR : fprintf(stderr, "\nGeneral GPU failure! Please check README file for more information.\n"); break;
|
||||
case LIBBSC_GPU_NOT_SUPPORTED : fprintf(stderr, "\nYour GPU is not supported! Please check README file for more information.\n"); break;
|
||||
case LIBBSC_GPU_NOT_ENOUGH_MEMORY : fprintf(stderr, "\nNot enough GPU memory! Please check README file for more information.\n"); break;
|
||||
|
||||
default : fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
}
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
if (sortingContexts == LIBBSC_CONTEXTS_PRECEDING)
|
||||
{
|
||||
result = bsc_reverse_block(buffer, dataSize, paramFeatures());
|
||||
if (result != LIBBSC_NO_ERROR)
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(print)
|
||||
#endif
|
||||
{
|
||||
fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (recordSize > 1)
|
||||
{
|
||||
result = bsc_reorder_reverse(buffer, dataSize, recordSize, paramFeatures());
|
||||
if (result != LIBBSC_NO_ERROR)
|
||||
{
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(print)
|
||||
#endif
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case LIBBSC_NOT_ENOUGH_MEMORY : fprintf(stderr, "\nNot enough memory! Please check README file for more information.\n"); break;
|
||||
default : fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
}
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
#pragma omp critical(output)
|
||||
#endif
|
||||
{
|
||||
if (BSC_FSEEK(fOutput, blockOffset, SEEK_SET))
|
||||
{
|
||||
fprintf(stderr, "\nIO error on file: %s!\n", argv[3]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((int)fwrite(buffer, 1, dataSize, fOutput) != dataSize)
|
||||
{
|
||||
fprintf(stderr, "\nIO error on file: %s!\n", argv[3]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer != NULL) bsc_free(buffer);
|
||||
}
|
||||
|
||||
if (BSC_FSEEK(fOutput, 0, SEEK_END))
|
||||
{
|
||||
fprintf(stderr, "IO error on file: %s!\n", argv[3]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fprintf(stdout, "\r%.55s decompressed %.0f into %.0f in %.3f seconds.\n", argv[2], (double)fileSize, (double)BSC_FTELL(fOutput), BSC_CLOCK() - startTime);
|
||||
|
||||
fclose(fInput); fclose(fOutput);
|
||||
}
|
||||
|
||||
void ShowUsage(void)
|
||||
{
|
||||
fprintf(stdout, "Usage: bsc <e|d> inputfile outputfile <options>\n\n");
|
||||
|
||||
fprintf(stdout, "Block sorting options:\n");
|
||||
fprintf(stdout, " -b<size> Block size in megabytes, default: -b25\n");
|
||||
fprintf(stdout, " minimum: -b1, maximum: -b1024\n");
|
||||
fprintf(stdout, " -m<algo> Block sorting algorithm, default: -m0\n");
|
||||
fprintf(stdout, " -m0 Burrows Wheeler Transform (default)\n");
|
||||
#ifdef LIBBSC_SORT_TRANSFORM_SUPPORT
|
||||
fprintf(stdout, " -m3..8 Sort Transform of order n\n");
|
||||
#endif
|
||||
fprintf(stdout, " -c<ctx> Contexts for sorting, default: -cf\n");
|
||||
fprintf(stdout, " -cf Following contexts (default)\n");
|
||||
fprintf(stdout, " -cp Preceding contexts\n");
|
||||
fprintf(stdout, " -ca Autodetect (experimental)\n");
|
||||
fprintf(stdout, " -e<algo> Entropy encoding algorithm, default: -e1\n");
|
||||
fprintf(stdout, " -e1 Static Quantized Local Frequency Coding (default)\n");
|
||||
fprintf(stdout, " -e2 Adaptive Quantized Local Frequency Coding (best compression)\n");
|
||||
|
||||
fprintf(stdout, "\nPreprocessing options:\n");
|
||||
fprintf(stdout, " -p Disable all preprocessing techniques\n");
|
||||
fprintf(stdout, " -s Enable segmentation (adaptive block size), default: disable\n");
|
||||
fprintf(stdout, " -r Enable structured data reordering, default: disable\n");
|
||||
fprintf(stdout, " -l Enable Lempel-Ziv preprocessing, default: enable\n");
|
||||
fprintf(stdout, " -H<size> LZP dictionary size in bits, default: -H16\n");
|
||||
fprintf(stdout, " minimum: -H10, maximum: -H28\n");
|
||||
fprintf(stdout, " -M<size> LZP minimum match length, default: -M128\n");
|
||||
fprintf(stdout, " minimum: -M4, maximum: -M255\n");
|
||||
|
||||
fprintf(stdout, "\nPlatform specific options:\n");
|
||||
#ifdef LIBBSC_CUDA_SUPPORT
|
||||
fprintf(stdout, " -G Enable Sort Transform acceleration on NVIDIA GPU, default: disable\n");
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
fprintf(stdout, " -P Enable large 2MB RAM pages, default: disable\n");
|
||||
#endif
|
||||
#ifdef LIBBSC_OPENMP
|
||||
fprintf(stdout, " -t Disable parallel blocks processing, default: enable\n");
|
||||
fprintf(stdout, " -T Disable multi-core systems support, default: enable\n");
|
||||
#endif
|
||||
|
||||
fprintf(stdout,"\nOptions may be combined into one, like -b128p -m5e1\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ProcessSwitch(char * s)
|
||||
{
|
||||
if (*s == 0)
|
||||
{
|
||||
ShowUsage();
|
||||
}
|
||||
|
||||
for (; *s != 0; )
|
||||
{
|
||||
switch (*s++)
|
||||
{
|
||||
case 'b':
|
||||
{
|
||||
char * strNum = s; while ((*s >= '0') && (*s <= '9')) s++;
|
||||
paramBlockSize = atoi(strNum) * 1024 * 1024;
|
||||
if ((paramBlockSize < 1024 * 1024) || (paramBlockSize > 1024 * 1024 * 1024)) ShowUsage();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'm':
|
||||
{
|
||||
char * strNum = s; while ((*s >= '0') && (*s <= '9')) s++;
|
||||
switch (atoi(strNum))
|
||||
{
|
||||
case 0 : paramBlockSorter = LIBBSC_BLOCKSORTER_BWT; break;
|
||||
|
||||
#ifdef LIBBSC_SORT_TRANSFORM_SUPPORT
|
||||
case 3 : paramBlockSorter = LIBBSC_BLOCKSORTER_ST3; break;
|
||||
case 4 : paramBlockSorter = LIBBSC_BLOCKSORTER_ST4; break;
|
||||
case 5 : paramBlockSorter = LIBBSC_BLOCKSORTER_ST5; break;
|
||||
case 6 : paramBlockSorter = LIBBSC_BLOCKSORTER_ST6; break;
|
||||
case 7 : paramBlockSorter = LIBBSC_BLOCKSORTER_ST7; paramEnableCUDA = 1; break;
|
||||
case 8 : paramBlockSorter = LIBBSC_BLOCKSORTER_ST8; paramEnableCUDA = 1; break;
|
||||
#endif
|
||||
|
||||
default : ShowUsage();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'c':
|
||||
{
|
||||
switch (*s++)
|
||||
{
|
||||
case 'f' : paramSortingContexts = LIBBSC_CONTEXTS_FOLLOWING; break;
|
||||
case 'p' : paramSortingContexts = LIBBSC_CONTEXTS_PRECEDING; break;
|
||||
case 'a' : paramSortingContexts = LIBBSC_CONTEXTS_AUTODETECT; break;
|
||||
default : ShowUsage();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'e':
|
||||
{
|
||||
switch (*s++)
|
||||
{
|
||||
case '1' : paramCoder = LIBBSC_CODER_QLFC_STATIC; break;
|
||||
case '2' : paramCoder = LIBBSC_CODER_QLFC_ADAPTIVE; break;
|
||||
default : ShowUsage();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'H':
|
||||
{
|
||||
char * strNum = s; while ((*s >= '0') && (*s <= '9')) s++;
|
||||
paramLZPHashSize = atoi(strNum);
|
||||
if ((paramLZPHashSize < 10) || (paramLZPHashSize > 28)) ShowUsage();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'M':
|
||||
{
|
||||
char * strNum = s; while ((*s >= '0') && (*s <= '9')) s++;
|
||||
paramLZPMinLen = atoi(strNum);
|
||||
if ((paramLZPMinLen < 4) || (paramLZPMinLen > 255)) ShowUsage();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'l': paramEnableLZP = 1; break;
|
||||
case 's': paramEnableSegmentation = 1; break;
|
||||
case 'r': paramEnableReordering = 1; break;
|
||||
|
||||
case 'p': paramEnableLZP = paramEnableSegmentation = paramEnableReordering = 0; break;
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
case 't': paramEnableParallelProcessing = 0; break;
|
||||
case 'T': paramEnableParallelProcessing = paramEnableMultiThreading = 0; break;
|
||||
#endif
|
||||
|
||||
#ifdef LIBBSC_CUDA_SUPPORT
|
||||
case 'G': paramEnableCUDA = 1; break;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
case 'P': paramEnableLargePages = 1; break;
|
||||
#endif
|
||||
|
||||
default : ShowUsage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessCommandline(int argc, char * argv[])
|
||||
{
|
||||
if (argc < 4 || strlen(argv[1]) != 1)
|
||||
{
|
||||
ShowUsage();
|
||||
}
|
||||
|
||||
for (int i = 4; i < argc; ++i)
|
||||
{
|
||||
if (argv[i][0] == '-')
|
||||
{
|
||||
ProcessSwitch(&argv[i][1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowUsage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
fprintf(stdout, "This is bsc, Block Sorting Compressor. Version 3.1.0. 8 July 2012.\n");
|
||||
fprintf(stdout, "Copyright (c) 2009-2012 Ilya Grebnov <Ilya.Grebnov@gmail.com>.\n\n");
|
||||
|
||||
#if defined(_OPENMP) && defined(__INTEL_COMPILER)
|
||||
|
||||
kmp_set_warnings_off();
|
||||
|
||||
#endif
|
||||
|
||||
ProcessCommandline(argc, argv);
|
||||
|
||||
if (bsc_init(paramFeatures()) != LIBBSC_NO_ERROR)
|
||||
{
|
||||
fprintf(stderr, "\nInternal program error, please contact the author!\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
switch (*argv[1])
|
||||
{
|
||||
case 'e' : case 'E' : Compression(argv); break;
|
||||
case 'd' : case 'D' : Decompression(argv); break;
|
||||
default : ShowUsage();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End bsc.cpp */
|
||||
/*-----------------------------------------------------------*/
|
85
bsc/libbsc/adler32/adler32.cpp
Normal file
85
bsc/libbsc/adler32/adler32.cpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Adler-32 checksum functions */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "adler32.h"
|
||||
|
||||
#include "../platform/platform.h"
|
||||
#include "../libbsc.h"
|
||||
|
||||
#define BASE 65521UL
|
||||
#define NMAX 5552
|
||||
|
||||
#define DO1(buf, i) { sum1 += (buf)[i]; sum2 += sum1; }
|
||||
#define DO2(buf, i) DO1(buf, i); DO1(buf, i + 1);
|
||||
#define DO4(buf, i) DO2(buf, i); DO2(buf, i + 2);
|
||||
#define DO8(buf, i) DO4(buf, i); DO4(buf, i + 4);
|
||||
#define DO16(buf) DO8(buf, 0); DO8(buf, 8);
|
||||
#define MOD(a) a %= BASE
|
||||
|
||||
unsigned int bsc_adler32(const unsigned char * T, int n, int features)
|
||||
{
|
||||
unsigned int sum1 = 1;
|
||||
unsigned int sum2 = 0;
|
||||
|
||||
while (n >= NMAX)
|
||||
{
|
||||
for (int i = 0; i < NMAX / 16; ++i)
|
||||
{
|
||||
DO16(T); T += 16;
|
||||
}
|
||||
MOD(sum1); MOD(sum2); n -= NMAX;
|
||||
}
|
||||
|
||||
while (n >= 16)
|
||||
{
|
||||
DO16(T); T += 16; n -= 16;
|
||||
}
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
DO1(T, 0); T += 1; n -= 1;
|
||||
}
|
||||
|
||||
MOD(sum1); MOD(sum2);
|
||||
|
||||
return sum1 | (sum2 << 16);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End adler32.cpp */
|
||||
/*-----------------------------------------------------------*/
|
59
bsc/libbsc/adler32/adler32.h
Normal file
59
bsc/libbsc/adler32/adler32.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Interface to Adler-32 checksum functions */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_ADLER32_H
|
||||
#define _LIBBSC_ADLER32_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Calculates Adler-32 checksum for input memory block.
|
||||
* @param T - the input memory block of n bytes.
|
||||
* @param n - the length of the input memory block.
|
||||
* @param features - the set of additional features.
|
||||
* @return the value of cyclic redundancy check.
|
||||
*/
|
||||
unsigned int bsc_adler32(const unsigned char * T, int n, int features);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End adler32.h */
|
||||
/*-----------------------------------------------------------*/
|
404
bsc/libbsc/bwt/bwt.cpp
Normal file
404
bsc/libbsc/bwt/bwt.cpp
Normal file
|
@ -0,0 +1,404 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Burrows Wheeler Transform */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "bwt.h"
|
||||
|
||||
#include "../platform/platform.h"
|
||||
#include "../libbsc.h"
|
||||
|
||||
#include "divsufsort/divsufsort.h"
|
||||
|
||||
int bsc_bwt_encode(unsigned char * T, int n, unsigned char * num_indexes, int * indexes, int features)
|
||||
{
|
||||
int index = divbwt(T, T, NULL, n, num_indexes, indexes, features & LIBBSC_FEATURE_MULTITHREADING);
|
||||
switch (index)
|
||||
{
|
||||
case -1 : return LIBBSC_BAD_PARAMETER;
|
||||
case -2 : return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
static int bsc_unbwt_mergedTL_serial(unsigned char * RESTRICT T, unsigned int * RESTRICT P, int n, int index)
|
||||
{
|
||||
unsigned int bucket[ALPHABET_SIZE];
|
||||
|
||||
memset(bucket, 0, ALPHABET_SIZE * sizeof(unsigned int));
|
||||
|
||||
for (int i = 0; i < index; ++i)
|
||||
{
|
||||
unsigned char c = T[i];
|
||||
P[i] = ((bucket[c]++) << 8) | c;
|
||||
}
|
||||
for (int i = index; i < n; ++i)
|
||||
{
|
||||
unsigned char c = T[i];
|
||||
P[i + 1] = ((bucket[c]++) << 8) | c;
|
||||
}
|
||||
|
||||
for (int sum = 1, i = 0; i < ALPHABET_SIZE; ++i)
|
||||
{
|
||||
int tmp = sum; sum += bucket[i]; bucket[i] = tmp;
|
||||
}
|
||||
|
||||
for (int p = 0, i = n - 1; i >= 0; --i)
|
||||
{
|
||||
unsigned int u = P[p];
|
||||
unsigned char c = u & 0xff;
|
||||
T[i] = c; p = (u >> 8) + bucket[c];
|
||||
}
|
||||
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
#define BWT_NUM_FASTBITS (17)
|
||||
|
||||
static int bsc_unbwt_biPSI_serial(unsigned char * RESTRICT T, unsigned int * RESTRICT P, int n, int index)
|
||||
{
|
||||
if (int * RESTRICT bucket = (int *)bsc_zero_malloc(ALPHABET_SIZE * ALPHABET_SIZE * sizeof(int)))
|
||||
{
|
||||
if (unsigned short * RESTRICT fastbits = (unsigned short *)bsc_malloc((1 + (1 << BWT_NUM_FASTBITS)) * sizeof(unsigned short)))
|
||||
{
|
||||
int count[ALPHABET_SIZE]; memset(count, 0, ALPHABET_SIZE * sizeof(int));
|
||||
|
||||
int shift = 0; while ((n >> shift) > (1 << BWT_NUM_FASTBITS)) shift++;
|
||||
|
||||
for (int i = 0; i < n; ++i) count[T[i]]++;
|
||||
|
||||
for (int sum = 1, c = 0; c < ALPHABET_SIZE; ++c)
|
||||
{
|
||||
int tmp = sum; sum += count[c]; count[c] = tmp;
|
||||
if (count[c] != sum)
|
||||
{
|
||||
int * RESTRICT bucket_p = &bucket[c << 8];
|
||||
|
||||
int hi = index; if (sum < hi) hi = sum;
|
||||
for (int i = count[c]; i < hi; ++i) bucket_p[T[i]]++;
|
||||
|
||||
int lo = index + 1; if (count[c] > lo) lo = count[c];
|
||||
for (int i = lo; i < sum; ++i) bucket_p[T[i - 1]]++;
|
||||
}
|
||||
}
|
||||
|
||||
int lastc = T[0];
|
||||
for (int v = 0, sum = 1, c = 0; c < ALPHABET_SIZE; ++c)
|
||||
{
|
||||
if (c == lastc) sum++;
|
||||
|
||||
int * RESTRICT bucket_p = &bucket[c];
|
||||
for (int d = 0; d < ALPHABET_SIZE; ++d)
|
||||
{
|
||||
int tmp = sum; sum += bucket_p[d << 8]; bucket_p[d << 8] = tmp;
|
||||
if (bucket_p[d << 8] != sum)
|
||||
{
|
||||
for (; v <= ((sum - 1) >> shift); ++v) fastbits[v] = (c << 8) | d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < index; ++i)
|
||||
{
|
||||
unsigned char c = T[i];
|
||||
int p = count[c]++;
|
||||
|
||||
if (p < index) P[bucket[(c << 8) | T[p ]]++] = i; else
|
||||
if (p > index) P[bucket[(c << 8) | T[p - 1]]++] = i;
|
||||
}
|
||||
|
||||
for (int i = index; i < n; ++i)
|
||||
{
|
||||
unsigned char c = T[i];
|
||||
int p = count[c]++;
|
||||
|
||||
if (p < index) P[bucket[(c << 8) | T[p ]]++] = i + 1; else
|
||||
if (p > index) P[bucket[(c << 8) | T[p - 1]]++] = i + 1;
|
||||
}
|
||||
|
||||
for (int c = 0; c < ALPHABET_SIZE; ++c)
|
||||
{
|
||||
for (int d = 0; d < c; ++d)
|
||||
{
|
||||
int tmp = bucket[(d << 8) | c]; bucket[(d << 8) | c] = bucket[(c << 8) | d]; bucket[(c << 8) | d] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
for (int p = index, i = 1; i < n; i += 2)
|
||||
{
|
||||
int c = fastbits[p >> shift]; while (bucket[c] <= p) c++;
|
||||
T[i - 1] = (unsigned char)(c >> 8); T[i] = (unsigned char)(c & 0xff);
|
||||
p = P[p];
|
||||
}
|
||||
|
||||
T[n - 1] = (unsigned char)lastc;
|
||||
|
||||
bsc_free(fastbits); bsc_free(bucket);
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
bsc_free(bucket);
|
||||
};
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
static int bsc_unbwt_reconstruct_serial(unsigned char * T, unsigned int * P, int n, int index)
|
||||
{
|
||||
if (n < 3 * 1024 * 1024) return bsc_unbwt_mergedTL_serial(T, P, n, index);
|
||||
return bsc_unbwt_biPSI_serial(T, P, n, index);
|
||||
}
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
static int bsc_unbwt_mergedTL_parallel(unsigned char * RESTRICT T, unsigned int * RESTRICT P, int n, int index, int * RESTRICT indexes)
|
||||
{
|
||||
unsigned int bucket[ALPHABET_SIZE];
|
||||
|
||||
memset(bucket, 0, ALPHABET_SIZE * sizeof(unsigned int));
|
||||
|
||||
for (int i = 0; i < index; ++i)
|
||||
{
|
||||
unsigned char c = T[i];
|
||||
P[i] = ((bucket[c]++) << 8) | c;
|
||||
}
|
||||
for (int i = index; i < n; ++i)
|
||||
{
|
||||
unsigned char c = T[i];
|
||||
P[i + 1] = ((bucket[c]++) << 8) | c;
|
||||
}
|
||||
|
||||
for (int sum = 1, i = 0; i < ALPHABET_SIZE; ++i)
|
||||
{
|
||||
int tmp = sum; sum += bucket[i]; bucket[i] = tmp;
|
||||
}
|
||||
|
||||
int mod = n / 8;
|
||||
{
|
||||
mod |= mod >> 1; mod |= mod >> 2;
|
||||
mod |= mod >> 4; mod |= mod >> 8;
|
||||
mod |= mod >> 16; mod >>= 1; mod++;
|
||||
}
|
||||
|
||||
int nBlocks = 1 + (n - 1) / mod;
|
||||
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int p = (blockId < nBlocks - 1) ? indexes[blockId] + 1 : 0;
|
||||
int blockStart = (blockId < nBlocks - 1) ? mod * blockId + mod - 1 : n - 1;
|
||||
int blockEnd = mod * blockId;
|
||||
|
||||
for (int i = blockStart; i >= blockEnd; --i)
|
||||
{
|
||||
unsigned int u = P[p];
|
||||
unsigned char c = u & 0xff;
|
||||
T[i] = c; p = (u >> 8) + bucket[c];
|
||||
}
|
||||
}
|
||||
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
static int bsc_unbwt_biPSI_parallel(unsigned char * RESTRICT T, unsigned int * RESTRICT P, int n, int index, int * RESTRICT indexes)
|
||||
{
|
||||
if (int * RESTRICT bucket = (int *)bsc_zero_malloc(ALPHABET_SIZE * ALPHABET_SIZE * sizeof(int)))
|
||||
{
|
||||
if (unsigned short * RESTRICT fastbits = (unsigned short *)bsc_malloc((1 + (1 << BWT_NUM_FASTBITS)) * sizeof(unsigned short)))
|
||||
{
|
||||
int count[ALPHABET_SIZE]; memset(count, 0, ALPHABET_SIZE * sizeof(int));
|
||||
|
||||
int shift = 0; while ((n >> shift) > (1 << BWT_NUM_FASTBITS)) shift++;
|
||||
|
||||
#pragma omp parallel
|
||||
{
|
||||
unsigned int count_local[ALPHABET_SIZE];
|
||||
|
||||
memset(count_local, 0, ALPHABET_SIZE * sizeof(unsigned int));
|
||||
|
||||
#pragma omp for schedule(static) nowait
|
||||
for (int i = 0; i < n; ++i) count_local[T[i]]++;
|
||||
|
||||
#pragma omp critical
|
||||
for (int c = 0; c < ALPHABET_SIZE; ++c) count[c] += count_local[c];
|
||||
}
|
||||
|
||||
for (int sum = 1, c = 0; c < ALPHABET_SIZE; ++c)
|
||||
{
|
||||
int tmp = sum; sum += count[c]; count[c] = tmp;
|
||||
}
|
||||
|
||||
#pragma omp parallel for schedule(static, 1)
|
||||
for (int c = 0; c < ALPHABET_SIZE; ++c)
|
||||
{
|
||||
int start = count[c], end = (c + 1 < ALPHABET_SIZE) ? count[c + 1] : n + 1;
|
||||
if (start != end)
|
||||
{
|
||||
int * RESTRICT bucket_p = &bucket[c << 8];
|
||||
|
||||
int hi = index; if (end < hi) hi = end;
|
||||
for (int i = start; i < hi; ++i) bucket_p[T[i]]++;
|
||||
|
||||
int lo = index + 1; if (start > lo) lo = start;
|
||||
for (int i = lo; i < end; ++i) bucket_p[T[i - 1]]++;
|
||||
}
|
||||
}
|
||||
|
||||
int lastc = T[0];
|
||||
for (int v = 0, sum = 1, c = 0; c < ALPHABET_SIZE; ++c)
|
||||
{
|
||||
if (c == lastc) sum++;
|
||||
|
||||
int * RESTRICT bucket_p = &bucket[c];
|
||||
for (int d = 0; d < ALPHABET_SIZE; ++d)
|
||||
{
|
||||
int tmp = sum; sum += bucket_p[d << 8]; bucket_p[d << 8] = tmp;
|
||||
if (bucket_p[d << 8] != sum)
|
||||
{
|
||||
for (; v <= ((sum - 1) >> shift); ++v) fastbits[v] = (c << 8) | d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < index; ++i)
|
||||
{
|
||||
unsigned char c = T[i];
|
||||
int p = count[c]++;
|
||||
|
||||
if (p < index) P[bucket[(c << 8) | T[p ]]++] = i; else
|
||||
if (p > index) P[bucket[(c << 8) | T[p - 1]]++] = i;
|
||||
}
|
||||
|
||||
for (int i = index; i < n; ++i)
|
||||
{
|
||||
unsigned char c = T[i];
|
||||
int p = count[c]++;
|
||||
|
||||
if (p < index) P[bucket[(c << 8) | T[p ]]++] = i + 1; else
|
||||
if (p > index) P[bucket[(c << 8) | T[p - 1]]++] = i + 1;
|
||||
}
|
||||
|
||||
for (int c = 0; c < ALPHABET_SIZE; ++c)
|
||||
{
|
||||
for (int d = 0; d < c; ++d)
|
||||
{
|
||||
int tmp = bucket[(d << 8) | c]; bucket[(d << 8) | c] = bucket[(c << 8) | d]; bucket[(c << 8) | d] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int mod = n / 8;
|
||||
{
|
||||
mod |= mod >> 1; mod |= mod >> 2;
|
||||
mod |= mod >> 4; mod |= mod >> 8;
|
||||
mod |= mod >> 16; mod >>= 1; mod++;
|
||||
}
|
||||
|
||||
int nBlocks = 1 + (n - 1) / mod;
|
||||
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int p = (blockId > 0 ) ? indexes[blockId - 1] + 1 : index;
|
||||
int blockEnd = (blockId < nBlocks - 1) ? mod * blockId + mod : n;
|
||||
int blockStart = mod * blockId;
|
||||
|
||||
if (blockEnd != n) blockEnd++; else T[n - 1] = (unsigned char)lastc;
|
||||
|
||||
for (int i = blockStart + 1; i < blockEnd; i += 2)
|
||||
{
|
||||
int c = fastbits[p >> shift]; while (bucket[c] <= p) c++;
|
||||
T[i - 1] = (unsigned char)(c >> 8); T[i] = (unsigned char)(c & 0xff);
|
||||
p = P[p];
|
||||
}
|
||||
}
|
||||
|
||||
bsc_free(fastbits); bsc_free(bucket);
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
bsc_free(bucket);
|
||||
};
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
static int bsc_unbwt_reconstruct_parallel(unsigned char * T, unsigned int * P, int n, int index, int * indexes)
|
||||
{
|
||||
if (n < 3 * 1024 * 1024) return bsc_unbwt_mergedTL_parallel(T, P, n, index, indexes);
|
||||
return bsc_unbwt_biPSI_parallel(T, P, n, index, indexes);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int bsc_bwt_decode(unsigned char * T, int n, int index, unsigned char num_indexes, int * indexes, int features)
|
||||
{
|
||||
if ((T == NULL) || (n < 0) || (index <= 0) || (index > n))
|
||||
{
|
||||
return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
if (n <= 1)
|
||||
{
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
if (unsigned int * P = (unsigned int *)bsc_malloc((n + 1) * sizeof(unsigned int)))
|
||||
{
|
||||
int result = LIBBSC_NO_ERROR;
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
int mod = n / 8;
|
||||
{
|
||||
mod |= mod >> 1; mod |= mod >> 2;
|
||||
mod |= mod >> 4; mod |= mod >> 8;
|
||||
mod |= mod >> 16; mod >>= 1;
|
||||
}
|
||||
|
||||
if ((features & LIBBSC_FEATURE_MULTITHREADING) && (n >= 64 * 1024) && (num_indexes == (unsigned char)((n - 1) / (mod + 1))) && (indexes != NULL))
|
||||
{
|
||||
result = bsc_unbwt_reconstruct_parallel(T, P, n, index, indexes);
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
result = bsc_unbwt_reconstruct_serial(T, P, n, index);
|
||||
}
|
||||
|
||||
bsc_free(P);
|
||||
return result;
|
||||
};
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End bwt.cpp */
|
||||
/*-----------------------------------------------------------*/
|
73
bsc/libbsc/bwt/bwt.h
Normal file
73
bsc/libbsc/bwt/bwt.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Interface to Burrows Wheeler Transform */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_BWT_H
|
||||
#define _LIBBSC_BWT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Constructs the burrows wheeler transformed string of a given string.
|
||||
* @param T - the input/output string of n chars.
|
||||
* @param n - the length of the given string.
|
||||
* @param num_indexes - the length of secondary indexes array, can be NULL.
|
||||
* @param indexes - the secondary indexes array, can be NULL.
|
||||
* @param features - the set of additional features.
|
||||
* @return the primary index if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_bwt_encode(unsigned char * T, int n, unsigned char * num_indexes, int * indexes, int features);
|
||||
|
||||
/**
|
||||
* Reconstructs the original string from burrows wheeler transformed string.
|
||||
* @param T - the input/output string of n chars.
|
||||
* @param n - the length of the given string.
|
||||
* @param index - the primary index.
|
||||
* @param num_indexes - the length of secondary indexes array, can be 0.
|
||||
* @param indexes - the secondary indexes array, can be NULL.
|
||||
* @param features - the set of additional features.
|
||||
* @return LIBBSC_NO_ERROR if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_bwt_decode(unsigned char * T, int n, int index, unsigned char num_indexes, int * indexes, int features);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End bwt.h */
|
||||
/*-----------------------------------------------------------*/
|
1907
bsc/libbsc/bwt/divsufsort/divsufsort.c
Normal file
1907
bsc/libbsc/bwt/divsufsort/divsufsort.c
Normal file
File diff suppressed because it is too large
Load diff
67
bsc/libbsc/bwt/divsufsort/divsufsort.h
Normal file
67
bsc/libbsc/bwt/divsufsort/divsufsort.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* divsufsort.h for libdivsufsort-lite
|
||||
* Copyright (c) 2003-2008 Yuta Mori All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _DIVSUFSORT_H
|
||||
#define _DIVSUFSORT_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/*- Prototypes -*/
|
||||
|
||||
/**
|
||||
* Constructs the suffix array of a given string.
|
||||
* @param T[0..n-1] The input string.
|
||||
* @param SA[0..n-1] The output array of suffixes.
|
||||
* @param n The length of the given string.
|
||||
* @param openMP enables OpenMP optimization.
|
||||
* @return 0 if no error occurred, -1 or -2 otherwise.
|
||||
*/
|
||||
int
|
||||
divsufsort(const unsigned char *T, int *SA, int n, int openMP);
|
||||
|
||||
/**
|
||||
* Constructs the burrows-wheeler transformed string of a given string.
|
||||
* @param T[0..n-1] The input string.
|
||||
* @param U[0..n-1] The output string. (can be T)
|
||||
* @param A[0..n-1] The temporary array. (can be NULL)
|
||||
* @param n The length of the given string.
|
||||
* @param num_indexes The length of secondary indexes array. (can be NULL)
|
||||
* @param indexes The secondary indexes array. (can be NULL)
|
||||
* @param openMP enables OpenMP optimization.
|
||||
* @return The primary index if no error occurred, -1 or -2 otherwise.
|
||||
*/
|
||||
int
|
||||
divbwt(const unsigned char *T, unsigned char *U, int *A, int n, unsigned char * num_indexes, int * indexes, int openMP);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _DIVSUFSORT_H */
|
346
bsc/libbsc/coder/coder.cpp
Normal file
346
bsc/libbsc/coder/coder.cpp
Normal file
|
@ -0,0 +1,346 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Second stage encoding functions */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "coder.h"
|
||||
|
||||
#include "../libbsc.h"
|
||||
#include "../platform/platform.h"
|
||||
|
||||
#include "qlfc/qlfc.h"
|
||||
|
||||
int bsc_coder_init(int features)
|
||||
{
|
||||
int result = LIBBSC_NO_ERROR;
|
||||
|
||||
if (result == LIBBSC_NO_ERROR) result = bsc_qlfc_init(features);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static INLINE int bsc_coder_num_blocks(int n)
|
||||
{
|
||||
if (n < 256 * 1024) return 1;
|
||||
if (n < 4 * 1024 * 1024) return 2;
|
||||
if (n < 16 * 1024 * 1024) return 4;
|
||||
|
||||
return 8;
|
||||
}
|
||||
|
||||
int bsc_coder_encode_block(const unsigned char * input, unsigned char * output, int inputSize, int outputSize, int coder)
|
||||
{
|
||||
if (coder == LIBBSC_CODER_QLFC_STATIC) return bsc_qlfc_static_encode_block (input, output, inputSize, outputSize);
|
||||
if (coder == LIBBSC_CODER_QLFC_ADAPTIVE) return bsc_qlfc_adaptive_encode_block(input, output, inputSize, outputSize);
|
||||
|
||||
return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
void bsc_coder_split_blocks(const unsigned char * input, int n, int nBlocks, int * blockStart, int * blockSize)
|
||||
{
|
||||
int rankSize = 0;
|
||||
for (int i = 1; i < n; i += 32)
|
||||
{
|
||||
if (input[i] != input[i - 1]) rankSize++;
|
||||
}
|
||||
|
||||
if (rankSize > nBlocks)
|
||||
{
|
||||
int blockRankSize = rankSize / nBlocks;
|
||||
|
||||
blockStart[0] = 0; rankSize = 0;
|
||||
for (int id = 0, i = 1; i < n; i += 32)
|
||||
{
|
||||
if (input[i] != input[i - 1])
|
||||
{
|
||||
rankSize++;
|
||||
if (rankSize == blockRankSize)
|
||||
{
|
||||
rankSize = 0;
|
||||
|
||||
blockSize[id] = i - blockStart[id];
|
||||
id++; blockStart[id] = i;
|
||||
|
||||
if (id == nBlocks - 1) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
blockSize[nBlocks - 1] = n - blockStart[nBlocks - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int p = 0; p < nBlocks; ++p)
|
||||
{
|
||||
blockStart[p] = (n / nBlocks) * p;
|
||||
blockSize[p] = (p != nBlocks - 1) ? n / nBlocks : n - (n / nBlocks) * (nBlocks - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int bsc_coder_compress_serial(const unsigned char * input, unsigned char * output, int n, int coder)
|
||||
{
|
||||
if (bsc_coder_num_blocks(n) == 1)
|
||||
{
|
||||
int result = bsc_coder_encode_block(input, output + 1, n, n - 1, coder);
|
||||
if (result >= LIBBSC_NO_ERROR) result = (output[0] = 1, result + 1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int compressedStart[ALPHABET_SIZE];
|
||||
int compressedSize[ALPHABET_SIZE];
|
||||
|
||||
int nBlocks = bsc_coder_num_blocks(n);
|
||||
int outputPtr = 1 + 8 * nBlocks;
|
||||
|
||||
bsc_coder_split_blocks(input, n, nBlocks, compressedStart, compressedSize);
|
||||
|
||||
output[0] = nBlocks;
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int inputStart = compressedStart[blockId];
|
||||
int inputSize = compressedSize[blockId];
|
||||
int outputSize = inputSize; if (outputSize > n - outputPtr) outputSize = n - outputPtr;
|
||||
|
||||
int result = bsc_coder_encode_block(input + inputStart, output + outputPtr, inputSize, outputSize, coder);
|
||||
if (result < LIBBSC_NO_ERROR)
|
||||
{
|
||||
if (outputPtr + inputSize >= n) return LIBBSC_NOT_COMPRESSIBLE;
|
||||
result = inputSize; memcpy(output + outputPtr, input + inputStart, inputSize);
|
||||
}
|
||||
|
||||
*(int *)(output + 1 + 8 * blockId + 0) = inputSize;
|
||||
*(int *)(output + 1 + 8 * blockId + 4) = result;
|
||||
|
||||
outputPtr += result;
|
||||
}
|
||||
|
||||
return outputPtr;
|
||||
}
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
int bsc_coder_compress_parallel(const unsigned char * input, unsigned char * output, int n, int coder)
|
||||
{
|
||||
if (unsigned char * buffer = (unsigned char *)bsc_malloc(n * sizeof(unsigned char)))
|
||||
{
|
||||
int compressionResult[ALPHABET_SIZE];
|
||||
int compressedStart[ALPHABET_SIZE];
|
||||
int compressedSize[ALPHABET_SIZE];
|
||||
|
||||
int nBlocks = bsc_coder_num_blocks(n);
|
||||
int result = LIBBSC_NO_ERROR;
|
||||
|
||||
int numThreads = omp_get_max_threads();
|
||||
if (numThreads > nBlocks) numThreads = nBlocks;
|
||||
|
||||
output[0] = nBlocks;
|
||||
#pragma omp parallel num_threads(numThreads) if(numThreads > 1)
|
||||
{
|
||||
if (omp_get_num_threads() == 1)
|
||||
{
|
||||
result = bsc_coder_compress_serial(input, output, n, coder);
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma omp single
|
||||
{
|
||||
bsc_coder_split_blocks(input, n, nBlocks, compressedStart, compressedSize);
|
||||
}
|
||||
|
||||
#pragma omp for schedule(dynamic)
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int blockStart = compressedStart[blockId];
|
||||
int blockSize = compressedSize[blockId];
|
||||
|
||||
compressionResult[blockId] = bsc_coder_encode_block(input + blockStart, buffer + blockStart, blockSize, blockSize, coder);
|
||||
if (compressionResult[blockId] < LIBBSC_NO_ERROR) compressionResult[blockId] = blockSize;
|
||||
|
||||
*(int *)(output + 1 + 8 * blockId + 0) = blockSize;
|
||||
*(int *)(output + 1 + 8 * blockId + 4) = compressionResult[blockId];
|
||||
}
|
||||
|
||||
#pragma omp single
|
||||
{
|
||||
result = 1 + 8 * nBlocks;
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
result += compressionResult[blockId];
|
||||
}
|
||||
|
||||
if (result >= n) result = LIBBSC_NOT_COMPRESSIBLE;
|
||||
}
|
||||
|
||||
if (result >= LIBBSC_NO_ERROR)
|
||||
{
|
||||
#pragma omp for schedule(dynamic)
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int blockStart = compressedStart[blockId];
|
||||
int blockSize = compressedSize[blockId];
|
||||
|
||||
int outputPtr = 1 + 8 * nBlocks;
|
||||
for (int p = 0; p < blockId; ++p) outputPtr += compressionResult[p];
|
||||
|
||||
if (compressionResult[blockId] != blockSize)
|
||||
{
|
||||
memcpy(output + outputPtr, buffer + blockStart, compressionResult[blockId]);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(output + outputPtr, input + blockStart, compressionResult[blockId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bsc_free(buffer);
|
||||
|
||||
return result;
|
||||
}
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int bsc_coder_compress(const unsigned char * input, unsigned char * output, int n, int coder, int features)
|
||||
{
|
||||
if ((coder != LIBBSC_CODER_QLFC_STATIC) && (coder != LIBBSC_CODER_QLFC_ADAPTIVE))
|
||||
{
|
||||
return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
if ((bsc_coder_num_blocks(n) != 1) && (features & LIBBSC_FEATURE_MULTITHREADING))
|
||||
{
|
||||
return bsc_coder_compress_parallel(input, output, n, coder);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return bsc_coder_compress_serial(input, output, n, coder);
|
||||
}
|
||||
|
||||
|
||||
int bsc_coder_decode_block(const unsigned char * input, unsigned char * output, int coder)
|
||||
{
|
||||
if (coder == LIBBSC_CODER_QLFC_STATIC) return bsc_qlfc_static_decode_block (input, output);
|
||||
if (coder == LIBBSC_CODER_QLFC_ADAPTIVE) return bsc_qlfc_adaptive_decode_block(input, output);
|
||||
|
||||
return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
int bsc_coder_decompress(const unsigned char * input, unsigned char * output, int coder, int features)
|
||||
{
|
||||
if ((coder != LIBBSC_CODER_QLFC_STATIC) && (coder != LIBBSC_CODER_QLFC_ADAPTIVE))
|
||||
{
|
||||
return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
int nBlocks = input[0];
|
||||
if (nBlocks == 1)
|
||||
{
|
||||
return bsc_coder_decode_block(input + 1, output, coder);
|
||||
}
|
||||
|
||||
int decompressionResult[ALPHABET_SIZE];
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
if (features & LIBBSC_FEATURE_MULTITHREADING)
|
||||
{
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int inputPtr = 0; for (int p = 0; p < blockId; ++p) inputPtr += *(int *)(input + 1 + 8 * p + 4);
|
||||
int outputPtr = 0; for (int p = 0; p < blockId; ++p) outputPtr += *(int *)(input + 1 + 8 * p + 0);
|
||||
|
||||
inputPtr += 1 + 8 * nBlocks;
|
||||
|
||||
int inputSize = *(int *)(input + 1 + 8 * blockId + 4);
|
||||
int outputSize = *(int *)(input + 1 + 8 * blockId + 0);
|
||||
|
||||
if (inputSize != outputSize)
|
||||
{
|
||||
decompressionResult[blockId] = bsc_coder_decode_block(input + inputPtr, output + outputPtr, coder);
|
||||
}
|
||||
else
|
||||
{
|
||||
decompressionResult[blockId] = inputSize; memcpy(output + outputPtr, input + inputPtr, inputSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int inputPtr = 0; for (int p = 0; p < blockId; ++p) inputPtr += *(int *)(input + 1 + 8 * p + 4);
|
||||
int outputPtr = 0; for (int p = 0; p < blockId; ++p) outputPtr += *(int *)(input + 1 + 8 * p + 0);
|
||||
|
||||
inputPtr += 1 + 8 * nBlocks;
|
||||
|
||||
int inputSize = *(int *)(input + 1 + 8 * blockId + 4);
|
||||
int outputSize = *(int *)(input + 1 + 8 * blockId + 0);
|
||||
|
||||
if (inputSize != outputSize)
|
||||
{
|
||||
decompressionResult[blockId] = bsc_coder_decode_block(input + inputPtr, output + outputPtr, coder);
|
||||
}
|
||||
else
|
||||
{
|
||||
decompressionResult[blockId] = inputSize; memcpy(output + outputPtr, input + inputPtr, inputSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int dataSize = 0, result = LIBBSC_NO_ERROR;
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
if (decompressionResult[blockId] < LIBBSC_NO_ERROR) result = decompressionResult[blockId];
|
||||
dataSize += decompressionResult[blockId];
|
||||
}
|
||||
|
||||
return (result == LIBBSC_NO_ERROR) ? dataSize : result;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End coder.cpp */
|
||||
/*-----------------------------------------------------------*/
|
78
bsc/libbsc/coder/coder.h
Normal file
78
bsc/libbsc/coder/coder.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Interface to second stage encoding functions */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_CODER_H
|
||||
#define _LIBBSC_CODER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* You should call this function before you call any of the other functions in coder.
|
||||
* @param features - the set of additional features.
|
||||
* @return LIBBSC_NO_ERROR if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_coder_init(int features);
|
||||
|
||||
/**
|
||||
* Compress a memory block using Quantized Local Frequency Coding.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param output - the output memory block of n bytes.
|
||||
* @param n - the length of the input memory block.
|
||||
* @param coder - the entropy coding algorithm.
|
||||
* @param features - the set of additional features.
|
||||
* @return the length of compressed memory block if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_coder_compress(const unsigned char * input, unsigned char * output, int n, int coder, int features);
|
||||
|
||||
/**
|
||||
* Decompress a memory block using Quantized Local Frequency Coding.
|
||||
* @param input - the input memory block.
|
||||
* @param output - the output memory block.
|
||||
* @param coder - the entropy coding algorithm.
|
||||
* @param features - the set of additional features.
|
||||
* @return the length of decompressed memory block if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_coder_decompress(const unsigned char * input, unsigned char * output, int coder, int features);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End coder.h */
|
||||
/*-----------------------------------------------------------*/
|
205
bsc/libbsc/coder/common/predictor.h
Normal file
205
bsc/libbsc/coder/common/predictor.h
Normal file
|
@ -0,0 +1,205 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Probability counter and logistic mixer */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_CODER_PREDICTOR_H
|
||||
#define _LIBBSC_CODER_PREDICTOR_H
|
||||
|
||||
#include "../../platform/platform.h"
|
||||
|
||||
#include "tables.h"
|
||||
|
||||
struct ProbabilityCounter
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static INLINE void UpdateBit0(short & probability, const int threshold, const int adaptationRate)
|
||||
{
|
||||
probability = probability + (((4096 - threshold - probability) * adaptationRate) >> 12);
|
||||
};
|
||||
|
||||
static INLINE void UpdateBit1(short & probability, const int threshold, const int adaptationRate)
|
||||
{
|
||||
probability = probability - (((probability - threshold) * adaptationRate) >> 12);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
struct ProbabilityMixer
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
short stretchedProbability0;
|
||||
short stretchedProbability1;
|
||||
short stretchedProbability2;
|
||||
int mixedProbability;
|
||||
int index;
|
||||
|
||||
short probabilityMap[17];
|
||||
|
||||
int weight0;
|
||||
int weight1;
|
||||
int weight2;
|
||||
|
||||
public:
|
||||
|
||||
INLINE void Init()
|
||||
{
|
||||
weight0 = weight1 = 2048 << 5; weight2 = 0;
|
||||
for (int p = 0; p < 17; ++p)
|
||||
{
|
||||
probabilityMap[p] = bsc_squash((p - 8) * 256);
|
||||
}
|
||||
}
|
||||
|
||||
INLINE int Mixup(const int probability0, const int probability1, const int probability2)
|
||||
{
|
||||
stretchedProbability0 = bsc_stretch(probability0);
|
||||
stretchedProbability1 = bsc_stretch(probability1);
|
||||
stretchedProbability2 = bsc_stretch(probability2);
|
||||
|
||||
short stretchedProbability = (stretchedProbability0 * weight0 + stretchedProbability1 * weight1 + stretchedProbability2 * weight2) >> 17;
|
||||
|
||||
if (stretchedProbability < -2047) stretchedProbability = -2047;
|
||||
if (stretchedProbability > 2047) stretchedProbability = 2047;
|
||||
|
||||
index = (stretchedProbability + 2048) >> 8;
|
||||
const int weight = stretchedProbability & 255;
|
||||
const int probability = bsc_squash(stretchedProbability);
|
||||
const int mappedProbability = probabilityMap[index] + (((probabilityMap[index + 1] - probabilityMap[index]) * weight) >> 8);
|
||||
|
||||
return mixedProbability = (3 * probability + mappedProbability) >> 2;
|
||||
};
|
||||
|
||||
INLINE int MixupAndUpdateBit0(const int probability0, const int probability1, const int probability2,
|
||||
const int learningRate0, const int learningRate1, const int learningRate2,
|
||||
const int threshold, const int adaptationRate
|
||||
)
|
||||
{
|
||||
const short stretchedProbability0 = bsc_stretch(probability0);
|
||||
const short stretchedProbability1 = bsc_stretch(probability1);
|
||||
const short stretchedProbability2 = bsc_stretch(probability2);
|
||||
|
||||
short stretchedProbability = (stretchedProbability0 * weight0 + stretchedProbability1 * weight1 + stretchedProbability2 * weight2) >> 17;
|
||||
|
||||
if (stretchedProbability < -2047) stretchedProbability = -2047;
|
||||
if (stretchedProbability > 2047) stretchedProbability = 2047;
|
||||
|
||||
const int weight = stretchedProbability & 255;
|
||||
const int index = (stretchedProbability + 2048) >> 8;
|
||||
const int probability = bsc_squash(stretchedProbability);
|
||||
const int mappedProbability = probabilityMap[index] + (((probabilityMap[index + 1] - probabilityMap[index]) * weight) >> 8);
|
||||
const int mixedProbability = (3 * probability + mappedProbability) >> 2;
|
||||
|
||||
ProbabilityCounter::UpdateBit0(probabilityMap[index], threshold, adaptationRate);
|
||||
ProbabilityCounter::UpdateBit0(probabilityMap[index + 1], threshold, adaptationRate);
|
||||
|
||||
const int eps = mixedProbability - 4095;
|
||||
|
||||
weight0 -= (learningRate0 * eps * stretchedProbability0) >> 16;
|
||||
weight1 -= (learningRate1 * eps * stretchedProbability1) >> 16;
|
||||
weight2 -= (learningRate2 * eps * stretchedProbability2) >> 16;
|
||||
|
||||
return mixedProbability;
|
||||
};
|
||||
|
||||
INLINE int MixupAndUpdateBit1(const int probability0, const int probability1, const int probability2,
|
||||
const int learningRate0, const int learningRate1, const int learningRate2,
|
||||
const int threshold, const int adaptationRate
|
||||
)
|
||||
{
|
||||
const short stretchedProbability0 = bsc_stretch(probability0);
|
||||
const short stretchedProbability1 = bsc_stretch(probability1);
|
||||
const short stretchedProbability2 = bsc_stretch(probability2);
|
||||
|
||||
short stretchedProbability = (stretchedProbability0 * weight0 + stretchedProbability1 * weight1 + stretchedProbability2 * weight2) >> 17;
|
||||
|
||||
if (stretchedProbability < -2047) stretchedProbability = -2047;
|
||||
if (stretchedProbability > 2047) stretchedProbability = 2047;
|
||||
|
||||
const int weight = stretchedProbability & 255;
|
||||
const int index = (stretchedProbability + 2048) >> 8;
|
||||
const int probability = bsc_squash(stretchedProbability);
|
||||
const int mappedProbability = probabilityMap[index] + (((probabilityMap[index + 1] - probabilityMap[index]) * weight) >> 8);
|
||||
const int mixedProbability = (3 * probability + mappedProbability) >> 2;
|
||||
|
||||
ProbabilityCounter::UpdateBit1(probabilityMap[index], threshold, adaptationRate);
|
||||
ProbabilityCounter::UpdateBit1(probabilityMap[index + 1], threshold, adaptationRate);
|
||||
|
||||
const int eps = mixedProbability - 1;
|
||||
|
||||
weight0 -= (learningRate0 * eps * stretchedProbability0) >> 16;
|
||||
weight1 -= (learningRate1 * eps * stretchedProbability1) >> 16;
|
||||
weight2 -= (learningRate2 * eps * stretchedProbability2) >> 16;
|
||||
|
||||
return mixedProbability;
|
||||
};
|
||||
|
||||
INLINE void UpdateBit0(const int learningRate0, const int learningRate1, const int learningRate2,
|
||||
const int threshold, const int adaptationRate
|
||||
)
|
||||
{
|
||||
ProbabilityCounter::UpdateBit0(probabilityMap[index], threshold, adaptationRate);
|
||||
ProbabilityCounter::UpdateBit0(probabilityMap[index + 1], threshold, adaptationRate);
|
||||
|
||||
const int eps = mixedProbability - 4095;
|
||||
|
||||
weight0 -= (learningRate0 * eps * stretchedProbability0) >> 16;
|
||||
weight1 -= (learningRate1 * eps * stretchedProbability1) >> 16;
|
||||
weight2 -= (learningRate2 * eps * stretchedProbability2) >> 16;
|
||||
};
|
||||
|
||||
INLINE void UpdateBit1(const int learningRate0, const int learningRate1, const int learningRate2,
|
||||
const int threshold, const int adaptationRate
|
||||
)
|
||||
{
|
||||
ProbabilityCounter::UpdateBit1(probabilityMap[index], threshold, adaptationRate);
|
||||
ProbabilityCounter::UpdateBit1(probabilityMap[index + 1], threshold, adaptationRate);
|
||||
|
||||
const int eps = mixedProbability - 1;
|
||||
|
||||
weight0 -= (learningRate0 * eps * stretchedProbability0) >> 16;
|
||||
weight1 -= (learningRate1 * eps * stretchedProbability1) >> 16;
|
||||
weight2 -= (learningRate2 * eps * stretchedProbability2) >> 16;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End predictor.h */
|
||||
/*-----------------------------------------------------------*/
|
215
bsc/libbsc/coder/common/rangecoder.h
Normal file
215
bsc/libbsc/coder/common/rangecoder.h
Normal file
|
@ -0,0 +1,215 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Range coder */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_CODER_RANGECODER_H
|
||||
#define _LIBBSC_CODER_RANGECODER_H
|
||||
|
||||
#include "../../platform/platform.h"
|
||||
|
||||
class RangeCoder
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
union ari
|
||||
{
|
||||
struct u
|
||||
{
|
||||
unsigned int low32;
|
||||
unsigned int carry;
|
||||
} u;
|
||||
unsigned long long low;
|
||||
} ari;
|
||||
|
||||
unsigned int ari_code;
|
||||
unsigned int ari_ffnum;
|
||||
unsigned int ari_cache;
|
||||
unsigned int ari_range;
|
||||
|
||||
const unsigned short * RESTRICT ari_input;
|
||||
unsigned short * RESTRICT ari_output;
|
||||
unsigned short * RESTRICT ari_outputEOB;
|
||||
unsigned short * RESTRICT ari_outputStart;
|
||||
|
||||
INLINE void OutputShort(unsigned short s)
|
||||
{
|
||||
*ari_output++ = s;
|
||||
};
|
||||
|
||||
INLINE unsigned short InputShort()
|
||||
{
|
||||
return *ari_input++;
|
||||
};
|
||||
|
||||
INLINE void ShiftLow()
|
||||
{
|
||||
if (ari.u.low32 < 0xffff0000U || ari.u.carry)
|
||||
{
|
||||
OutputShort(ari_cache + ari.u.carry);
|
||||
if (ari_ffnum)
|
||||
{
|
||||
unsigned short s = ari.u.carry - 1;
|
||||
do { OutputShort(s); } while (--ari_ffnum);
|
||||
}
|
||||
ari_cache = ari.u.low32 >> 16; ari.u.carry = 0;
|
||||
} else ari_ffnum++;
|
||||
ari.u.low32 <<= 16;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
INLINE bool CheckEOB()
|
||||
{
|
||||
return ari_output >= ari_outputEOB;
|
||||
}
|
||||
|
||||
INLINE void InitEncoder(unsigned char * output, int outputSize)
|
||||
{
|
||||
ari_outputStart = (unsigned short *)output;
|
||||
ari_output = (unsigned short *)output;
|
||||
ari_outputEOB = (unsigned short *)(output + outputSize - 16);
|
||||
ari.low = 0;
|
||||
ari_ffnum = 0;
|
||||
ari_cache = 0;
|
||||
ari_range = 0xffffffff;
|
||||
};
|
||||
|
||||
INLINE int FinishEncoder()
|
||||
{
|
||||
ShiftLow(); ShiftLow(); ShiftLow();
|
||||
return (int)(ari_output - ari_outputStart) * sizeof(ari_output[0]);
|
||||
}
|
||||
|
||||
INLINE void EncodeBit0(int probability)
|
||||
{
|
||||
ari_range = (ari_range >> 12) * probability;
|
||||
if (ari_range < 0x10000)
|
||||
{
|
||||
ari_range <<= 16; ShiftLow();
|
||||
}
|
||||
}
|
||||
|
||||
INLINE void EncodeBit1(int probability)
|
||||
{
|
||||
unsigned int range = (ari_range >> 12) * probability;
|
||||
ari.low += range; ari_range -= range;
|
||||
if (ari_range < 0x10000)
|
||||
{
|
||||
ari_range <<= 16; ShiftLow();
|
||||
}
|
||||
}
|
||||
|
||||
INLINE void EncodeBit(unsigned int bit)
|
||||
{
|
||||
if (bit) EncodeBit1(2048); else EncodeBit0(2048);
|
||||
};
|
||||
|
||||
INLINE void EncodeByte(unsigned int byte)
|
||||
{
|
||||
for (int bit = 7; bit >= 0; --bit)
|
||||
{
|
||||
EncodeBit(byte & (1 << bit));
|
||||
}
|
||||
};
|
||||
|
||||
INLINE void EncodeWord(unsigned int word)
|
||||
{
|
||||
for (int bit = 31; bit >= 0; --bit)
|
||||
{
|
||||
EncodeBit(word & (1 << bit));
|
||||
}
|
||||
};
|
||||
|
||||
INLINE void InitDecoder(const unsigned char * input)
|
||||
{
|
||||
ari_input = (unsigned short *)input;
|
||||
ari_code = 0;
|
||||
ari_range = 0xffffffff;
|
||||
ari_code = (ari_code << 16) | InputShort();
|
||||
ari_code = (ari_code << 16) | InputShort();
|
||||
ari_code = (ari_code << 16) | InputShort();
|
||||
};
|
||||
|
||||
INLINE int DecodeBit(int probability)
|
||||
{
|
||||
unsigned int range = (ari_range >> 12) * probability;
|
||||
if (ari_code >= range)
|
||||
{
|
||||
ari_code -= range; ari_range -= range;
|
||||
if (ari_range < 0x10000)
|
||||
{
|
||||
ari_range <<= 16; ari_code = (ari_code << 16) | InputShort();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
ari_range = range;
|
||||
if (ari_range < 0x10000)
|
||||
{
|
||||
ari_range <<= 16; ari_code = (ari_code << 16) | InputShort();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
INLINE unsigned int DecodeBit()
|
||||
{
|
||||
return DecodeBit(2048);
|
||||
}
|
||||
|
||||
INLINE unsigned int DecodeByte()
|
||||
{
|
||||
unsigned int byte = 0;
|
||||
for (int bit = 7; bit >= 0; --bit)
|
||||
{
|
||||
byte += byte + DecodeBit();
|
||||
}
|
||||
return byte;
|
||||
}
|
||||
|
||||
INLINE unsigned int DecodeWord()
|
||||
{
|
||||
unsigned int word = 0;
|
||||
for (int bit = 31; bit >= 0; --bit)
|
||||
{
|
||||
word += word + DecodeBit();
|
||||
}
|
||||
return word;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End rangecoder.h */
|
||||
/*-----------------------------------------------------------*/
|
1899
bsc/libbsc/coder/common/tables.h
Normal file
1899
bsc/libbsc/coder/common/tables.h
Normal file
File diff suppressed because it is too large
Load diff
1363
bsc/libbsc/coder/qlfc/qlfc.cpp
Normal file
1363
bsc/libbsc/coder/qlfc/qlfc.cpp
Normal file
File diff suppressed because it is too large
Load diff
93
bsc/libbsc/coder/qlfc/qlfc.h
Normal file
93
bsc/libbsc/coder/qlfc/qlfc.h
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Interface to Quantized Local Frequency Coding functions */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_QLFC_H
|
||||
#define _LIBBSC_QLFC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* You should call this function before you call any of the other functions in qlfc.
|
||||
* @param features - the set of additional features.
|
||||
* @return LIBBSC_NO_ERROR if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_qlfc_init(int features);
|
||||
|
||||
/**
|
||||
* Compress a memory block using Quantized Local Frequency Coding algorithm.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param output - the output memory block of n bytes.
|
||||
* @param inputSize - the length of the input memory block.
|
||||
* @param outputSize - the length of the output memory block.
|
||||
* @return the length of compressed memory block if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_qlfc_static_encode_block(const unsigned char * input, unsigned char * output, int inputSize, int outputSize);
|
||||
|
||||
/**
|
||||
* Decompress a memory block using Quantized Local Frequency Coding algorithm.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param output - the output memory block of n bytes.
|
||||
* @param inputSize - the length of the input memory block.
|
||||
* @param outputSize - the length of the output memory block.
|
||||
* @return the length of decompressed memory block if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_qlfc_adaptive_encode_block(const unsigned char * input, unsigned char * output, int inputSize, int outputSize);
|
||||
|
||||
/**
|
||||
* Compress a memory block using Quantized Local Frequency Coding algorithm.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param output - the output memory block of n bytes.
|
||||
* @return the length of compressed memory block if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_qlfc_static_decode_block(const unsigned char * input, unsigned char * output);
|
||||
|
||||
/**
|
||||
* Decompress a memory block using Quantized Local Frequency Coding algorithm.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param output - the output memory block of n bytes.
|
||||
* @return the length of decompressed memory block if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_qlfc_adaptive_decode_block(const unsigned char * input, unsigned char * output);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End qlfc.h */
|
||||
/*-----------------------------------------------------------*/
|
84
bsc/libbsc/coder/qlfc/qlfc_model.cpp
Normal file
84
bsc/libbsc/coder/qlfc/qlfc_model.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Statistical data compression model for QLFC */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "qlfc_model.h"
|
||||
|
||||
#include "../../libbsc.h"
|
||||
#include "../../platform/platform.h"
|
||||
|
||||
QlfcStatisticalModel g_QlfcStatisticalModel;
|
||||
|
||||
void bsc_qlfc_memset_2048(void * dst, int size)
|
||||
{
|
||||
for (int i = 0; i < size / 2; ++i) ((short *)dst)[i] = 2048;
|
||||
}
|
||||
|
||||
int bsc_qlfc_init_static_model()
|
||||
{
|
||||
for (int mixer = 0; mixer < ALPHABET_SIZE; ++mixer)
|
||||
{
|
||||
g_QlfcStatisticalModel.mixerOfRank[mixer].Init();
|
||||
g_QlfcStatisticalModel.mixerOfRankEscape[mixer].Init();
|
||||
g_QlfcStatisticalModel.mixerOfRun[mixer].Init();
|
||||
}
|
||||
for (int bit = 0; bit < 8; ++bit)
|
||||
{
|
||||
g_QlfcStatisticalModel.mixerOfRankMantissa[bit].Init();
|
||||
for (int context = 0; context < 8; ++context)
|
||||
g_QlfcStatisticalModel.mixerOfRankExponent[context][bit].Init();
|
||||
}
|
||||
for (int bit = 0; bit < 32; ++bit)
|
||||
{
|
||||
g_QlfcStatisticalModel.mixerOfRunMantissa[bit].Init();
|
||||
for (int context = 0; context < 32; ++context)
|
||||
g_QlfcStatisticalModel.mixerOfRunExponent[context][bit].Init();
|
||||
}
|
||||
|
||||
bsc_qlfc_memset_2048(&g_QlfcStatisticalModel.Rank, sizeof(g_QlfcStatisticalModel.Rank));
|
||||
bsc_qlfc_memset_2048(&g_QlfcStatisticalModel.Run, sizeof(g_QlfcStatisticalModel.Run));
|
||||
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
void bsc_qlfc_init_model(QlfcStatisticalModel * model)
|
||||
{
|
||||
memcpy(model, &g_QlfcStatisticalModel, sizeof(QlfcStatisticalModel));
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End qlfc_model.cpp */
|
||||
/*-----------------------------------------------------------*/
|
252
bsc/libbsc/coder/qlfc/qlfc_model.h
Normal file
252
bsc/libbsc/coder/qlfc/qlfc_model.h
Normal file
|
@ -0,0 +1,252 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Statistical data compression model for QLFC */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_QLFC_MODEL_H
|
||||
#define _LIBBSC_QLFC_MODEL_H
|
||||
|
||||
#include "../common/predictor.h"
|
||||
|
||||
const int M_RANK_TS_TH0 = 1; const int M_RANK_TS_AR0 = 57;
|
||||
const int M_RANK_TS_TH1 = -111; const int M_RANK_TS_AR1 = 31;
|
||||
const int M_RANK_TC_TH0 = 291; const int M_RANK_TC_AR0 = 250;
|
||||
const int M_RANK_TC_TH1 = 154; const int M_RANK_TC_AR1 = 528;
|
||||
const int M_RANK_TP_TH0 = 375; const int M_RANK_TP_AR0 = 163;
|
||||
const int M_RANK_TP_TH1 = 313; const int M_RANK_TP_AR1 = 639;
|
||||
const int M_RANK_TM_TH0 = -41; const int M_RANK_TM_AR0 = 96;
|
||||
const int M_RANK_TM_TH1 = 53; const int M_RANK_TM_AR1 = 49;
|
||||
const int M_RANK_TM_LR0 = 20; const int M_RANK_TM_LR1 = 47;
|
||||
const int M_RANK_TM_LR2 = 27;
|
||||
|
||||
const int M_RANK_ES_TH0 = -137; const int M_RANK_ES_AR0 = 17;
|
||||
const int M_RANK_ES_TH1 = 482; const int M_RANK_ES_AR1 = 40;
|
||||
const int M_RANK_EC_TH0 = 61; const int M_RANK_EC_AR0 = 192;
|
||||
const int M_RANK_EC_TH1 = 200; const int M_RANK_EC_AR1 = 133;
|
||||
const int M_RANK_EP_TH0 = 54; const int M_RANK_EP_AR0 = 1342;
|
||||
const int M_RANK_EP_TH1 = 578; const int M_RANK_EP_AR1 = 1067;
|
||||
const int M_RANK_EM_TH0 = -11; const int M_RANK_EM_AR0 = 318;
|
||||
const int M_RANK_EM_TH1 = 144; const int M_RANK_EM_AR1 = 848;
|
||||
const int M_RANK_EM_LR0 = 49; const int M_RANK_EM_LR1 = 41;
|
||||
const int M_RANK_EM_LR2 = 40;
|
||||
|
||||
const int M_RANK_MS_TH0 = -145; const int M_RANK_MS_AR0 = 18;
|
||||
const int M_RANK_MS_TH1 = 114; const int M_RANK_MS_AR1 = 24;
|
||||
const int M_RANK_MC_TH0 = -43; const int M_RANK_MC_AR0 = 69;
|
||||
const int M_RANK_MC_TH1 = -36; const int M_RANK_MC_AR1 = 78;
|
||||
const int M_RANK_MP_TH0 = -2; const int M_RANK_MP_AR0 = 1119;
|
||||
const int M_RANK_MP_TH1 = 11; const int M_RANK_MP_AR1 = 1181;
|
||||
const int M_RANK_MM_TH0 = -203; const int M_RANK_MM_AR0 = 20;
|
||||
const int M_RANK_MM_TH1 = -271; const int M_RANK_MM_AR1 = 15;
|
||||
const int M_RANK_MM_LR0 = 263; const int M_RANK_MM_LR1 = 175;
|
||||
const int M_RANK_MM_LR2 = 17;
|
||||
|
||||
const int M_RANK_PS_TH0 = -99; const int M_RANK_PS_AR0 = 32;
|
||||
const int M_RANK_PS_TH1 = 318; const int M_RANK_PS_AR1 = 42;
|
||||
const int M_RANK_PC_TH0 = 17; const int M_RANK_PC_AR0 = 101;
|
||||
const int M_RANK_PC_TH1 = 1116; const int M_RANK_PC_AR1 = 246;
|
||||
const int M_RANK_PP_TH0 = 22; const int M_RANK_PP_AR0 = 964;
|
||||
const int M_RANK_PP_TH1 = -2; const int M_RANK_PP_AR1 = 1110;
|
||||
const int M_RANK_PM_TH0 = -194; const int M_RANK_PM_AR0 = 21;
|
||||
const int M_RANK_PM_TH1 = -129; const int M_RANK_PM_AR1 = 20;
|
||||
const int M_RANK_PM_LR0 = 480; const int M_RANK_PM_LR1 = 202;
|
||||
const int M_RANK_PM_LR2 = 17;
|
||||
|
||||
const int M_RUN_TS_TH0 = -93; const int M_RUN_TS_AR0 = 34;
|
||||
const int M_RUN_TS_TH1 = -4; const int M_RUN_TS_AR1 = 51;
|
||||
const int M_RUN_TC_TH0 = 139; const int M_RUN_TC_AR0 = 423;
|
||||
const int M_RUN_TC_TH1 = 244; const int M_RUN_TC_AR1 = 162;
|
||||
const int M_RUN_TP_TH0 = 275; const int M_RUN_TP_AR0 = 450;
|
||||
const int M_RUN_TP_TH1 = -6; const int M_RUN_TP_AR1 = 579;
|
||||
const int M_RUN_TM_TH0 = -68; const int M_RUN_TM_AR0 = 25;
|
||||
const int M_RUN_TM_TH1 = 1; const int M_RUN_TM_AR1 = 64;
|
||||
const int M_RUN_TM_LR0 = 15; const int M_RUN_TM_LR1 = 50;
|
||||
const int M_RUN_TM_LR2 = 78;
|
||||
|
||||
const int M_RUN_ES_TH0 = -116; const int M_RUN_ES_AR0 = 31;
|
||||
const int M_RUN_ES_TH1 = 43; const int M_RUN_ES_AR1 = 45;
|
||||
const int M_RUN_EC_TH0 = 165; const int M_RUN_EC_AR0 = 222;
|
||||
const int M_RUN_EC_TH1 = 30; const int M_RUN_EC_AR1 = 324;
|
||||
const int M_RUN_EP_TH0 = 315; const int M_RUN_EP_AR0 = 857;
|
||||
const int M_RUN_EP_TH1 = 109; const int M_RUN_EP_AR1 = 867;
|
||||
const int M_RUN_EM_TH0 = -14; const int M_RUN_EM_AR0 = 215;
|
||||
const int M_RUN_EM_TH1 = 61; const int M_RUN_EM_AR1 = 73;
|
||||
const int M_RUN_EM_LR0 = 35; const int M_RUN_EM_LR1 = 37;
|
||||
const int M_RUN_EM_LR2 = 42;
|
||||
|
||||
const int M_RUN_MS_TH0 = -176; const int M_RUN_MS_AR0 = 14;
|
||||
const int M_RUN_MS_TH1 = -141; const int M_RUN_MS_AR1 = 21;
|
||||
const int M_RUN_MC_TH0 = 84; const int M_RUN_MC_AR0 = 172;
|
||||
const int M_RUN_MC_TH1 = 37; const int M_RUN_MC_AR1 = 263;
|
||||
const int M_RUN_MP_TH0 = 2; const int M_RUN_MP_AR0 = 15;
|
||||
const int M_RUN_MP_TH1 = -197; const int M_RUN_MP_AR1 = 20;
|
||||
const int M_RUN_MM_TH0 = -27; const int M_RUN_MM_AR0 = 142;
|
||||
const int M_RUN_MM_TH1 = -146; const int M_RUN_MM_AR1 = 27;
|
||||
const int M_RUN_MM_LR0 = 51; const int M_RUN_MM_LR1 = 44;
|
||||
const int M_RUN_MM_LR2 = 80;
|
||||
|
||||
const int F_RANK_TS_TH0 = -116; const int F_RANK_TS_AR0 = 33;
|
||||
const int F_RANK_TS_TH1 = -78; const int F_RANK_TS_AR1 = 34;
|
||||
const int F_RANK_TC_TH0 = -2; const int F_RANK_TC_AR0 = 282;
|
||||
const int F_RANK_TC_TH1 = 12; const int F_RANK_TC_AR1 = 274;
|
||||
const int F_RANK_TP_TH0 = 4; const int F_RANK_TP_AR0 = 697;
|
||||
const int F_RANK_TP_TH1 = 55; const int F_RANK_TP_AR1 = 1185;
|
||||
const int F_RANK_TM_LR0 = 17; const int F_RANK_TM_LR1 = 14;
|
||||
const int F_RANK_TM_LR2 = 1;
|
||||
|
||||
const int F_RANK_ES_TH0 = -177; const int F_RANK_ES_AR0 = 23;
|
||||
const int F_RANK_ES_TH1 = -370; const int F_RANK_ES_AR1 = 11;
|
||||
const int F_RANK_EC_TH0 = -14; const int F_RANK_EC_AR0 = 271;
|
||||
const int F_RANK_EC_TH1 = 3; const int F_RANK_EC_AR1 = 308;
|
||||
const int F_RANK_EP_TH0 = -3; const int F_RANK_EP_AR0 = 788;
|
||||
const int F_RANK_EP_TH1 = 135; const int F_RANK_EP_AR1 = 1364;
|
||||
const int F_RANK_EM_LR0 = 22; const int F_RANK_EM_LR1 = 6;
|
||||
const int F_RANK_EM_LR2 = 4;
|
||||
|
||||
const int F_RANK_MS_TH0 = -254; const int F_RANK_MS_AR0 = 16;
|
||||
const int F_RANK_MS_TH1 = -177; const int F_RANK_MS_AR1 = 20;
|
||||
const int F_RANK_MC_TH0 = -55; const int F_RANK_MC_AR0 = 73;
|
||||
const int F_RANK_MC_TH1 = -54; const int F_RANK_MC_AR1 = 74;
|
||||
const int F_RANK_MP_TH0 = -6; const int F_RANK_MP_AR0 = 575;
|
||||
const int F_RANK_MP_TH1 = 1670; const int F_RANK_MP_AR1 = 1173;
|
||||
const int F_RANK_MM_LR0 = 15; const int F_RANK_MM_LR1 = 10;
|
||||
const int F_RANK_MM_LR2 = 7;
|
||||
|
||||
const int F_RANK_PS_TH0 = -126; const int F_RANK_PS_AR0 = 32;
|
||||
const int F_RANK_PS_TH1 = -126; const int F_RANK_PS_AR1 = 32;
|
||||
const int F_RANK_PC_TH0 = -33; const int F_RANK_PC_AR0 = 120;
|
||||
const int F_RANK_PC_TH1 = -25; const int F_RANK_PC_AR1 = 157;
|
||||
const int F_RANK_PP_TH0 = -6; const int F_RANK_PP_AR0 = 585;
|
||||
const int F_RANK_PP_TH1 = 150; const int F_RANK_PP_AR1 = 275;
|
||||
const int F_RANK_PM_LR0 = 16; const int F_RANK_PM_LR1 = 11;
|
||||
const int F_RANK_PM_LR2 = 5;
|
||||
|
||||
const int F_RUN_TS_TH0 = -68; const int F_RUN_TS_AR0 = 38;
|
||||
const int F_RUN_TS_TH1 = -112; const int F_RUN_TS_AR1 = 36;
|
||||
const int F_RUN_TC_TH0 = -4; const int F_RUN_TC_AR0 = 221;
|
||||
const int F_RUN_TC_TH1 = -13; const int F_RUN_TC_AR1 = 231;
|
||||
const int F_RUN_TP_TH0 = 0; const int F_RUN_TP_AR0 = 0;
|
||||
const int F_RUN_TP_TH1 = 0; const int F_RUN_TP_AR1 = 0;
|
||||
const int F_RUN_TM_LR0 = 14; const int F_RUN_TM_LR1 = 18;
|
||||
const int F_RUN_TM_LR2 = 0;
|
||||
|
||||
const int F_RUN_ES_TH0 = -90; const int F_RUN_ES_AR0 = 45;
|
||||
const int F_RUN_ES_TH1 = -92; const int F_RUN_ES_AR1 = 44;
|
||||
const int F_RUN_EC_TH0 = -3; const int F_RUN_EC_AR0 = 325;
|
||||
const int F_RUN_EC_TH1 = -11; const int F_RUN_EC_AR1 = 341;
|
||||
const int F_RUN_EP_TH0 = 24; const int F_RUN_EP_AR0 = 887;
|
||||
const int F_RUN_EP_TH1 = -4; const int F_RUN_EP_AR1 = 765;
|
||||
const int F_RUN_EM_LR0 = 14; const int F_RUN_EM_LR1 = 15;
|
||||
const int F_RUN_EM_LR2 = 3;
|
||||
|
||||
const int F_RUN_MS_TH0 = -275; const int F_RUN_MS_AR0 = 14;
|
||||
const int F_RUN_MS_TH1 = -185; const int F_RUN_MS_AR1 = 22;
|
||||
const int F_RUN_MC_TH0 = -18; const int F_RUN_MC_AR0 = 191;
|
||||
const int F_RUN_MC_TH1 = -15; const int F_RUN_MC_AR1 = 241;
|
||||
const int F_RUN_MP_TH0 = -73; const int F_RUN_MP_AR0 = 54;
|
||||
const int F_RUN_MP_TH1 = -214; const int F_RUN_MP_AR1 = 19;
|
||||
const int F_RUN_MM_LR0 = 7; const int F_RUN_MM_LR1 = 15;
|
||||
const int F_RUN_MM_LR2 = 10;
|
||||
|
||||
struct QlfcStatisticalModel
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
ProbabilityMixer mixerOfRank[ALPHABET_SIZE];
|
||||
ProbabilityMixer mixerOfRankExponent[8][8];
|
||||
ProbabilityMixer mixerOfRankMantissa[8];
|
||||
ProbabilityMixer mixerOfRankEscape[ALPHABET_SIZE];
|
||||
ProbabilityMixer mixerOfRun[ALPHABET_SIZE];
|
||||
ProbabilityMixer mixerOfRunExponent[32][32];
|
||||
ProbabilityMixer mixerOfRunMantissa[32];
|
||||
|
||||
struct Rank
|
||||
{
|
||||
short StaticModel;
|
||||
short StateModel[ALPHABET_SIZE];
|
||||
short CharModel[ALPHABET_SIZE];
|
||||
|
||||
struct Exponent
|
||||
{
|
||||
short StaticModel[8];
|
||||
short StateModel[ALPHABET_SIZE][8];
|
||||
short CharModel[ALPHABET_SIZE][8];
|
||||
} Exponent;
|
||||
|
||||
struct Mantissa
|
||||
{
|
||||
short StaticModel[ALPHABET_SIZE];
|
||||
short StateModel[ALPHABET_SIZE][ALPHABET_SIZE];
|
||||
short CharModel[ALPHABET_SIZE][ALPHABET_SIZE];
|
||||
} Mantissa[8];
|
||||
|
||||
struct Escape
|
||||
{
|
||||
short StaticModel[ALPHABET_SIZE];
|
||||
short StateModel[ALPHABET_SIZE][ALPHABET_SIZE];
|
||||
short CharModel[ALPHABET_SIZE][ALPHABET_SIZE];
|
||||
} Escape;
|
||||
|
||||
} Rank;
|
||||
|
||||
struct Run
|
||||
{
|
||||
short StaticModel;
|
||||
short StateModel[ALPHABET_SIZE];
|
||||
short CharModel[ALPHABET_SIZE];
|
||||
|
||||
struct Exponent
|
||||
{
|
||||
short StaticModel[32];
|
||||
short StateModel[ALPHABET_SIZE][32];
|
||||
short CharModel[ALPHABET_SIZE][32];
|
||||
} Exponent;
|
||||
|
||||
struct Mantissa
|
||||
{
|
||||
short StaticModel[32];
|
||||
short StateModel[ALPHABET_SIZE][32];
|
||||
short CharModel[ALPHABET_SIZE][32];
|
||||
} Mantissa[32];
|
||||
|
||||
} Run;
|
||||
};
|
||||
|
||||
int bsc_qlfc_init_static_model();
|
||||
void bsc_qlfc_init_model(QlfcStatisticalModel * model);
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End qlfc_model.h */
|
||||
/*-----------------------------------------------------------*/
|
111
bsc/libbsc/filters.h
Normal file
111
bsc/libbsc/filters.h
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Interface to data preprocessing filters */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_FILTERS_H
|
||||
#define _LIBBSC_FILTERS_H
|
||||
|
||||
#define LIBBSC_CONTEXTS_FOLLOWING 1
|
||||
#define LIBBSC_CONTEXTS_PRECEDING 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Autodetects segments for better compression of heterogeneous files.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param n - the length of the input memory block.
|
||||
* @param segments - the output array of segments of k elements size.
|
||||
* @param k - the size of the output segments array.
|
||||
* @param features - the set of additional features.
|
||||
* @return The number of segments if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_detect_segments(const unsigned char * input, int n, int * segments, int k, int features);
|
||||
|
||||
/**
|
||||
* Autodetects order of contexts for better compression of binary files.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param n - the length of the input memory block.
|
||||
* @param features - the set of additional features.
|
||||
* @return The detected contexts order if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_detect_contextsorder(const unsigned char * input, int n, int features);
|
||||
|
||||
/**
|
||||
* Reverses memory block to change order of contexts.
|
||||
* @param T - the input/output memory block of n bytes.
|
||||
* @param n - the length of the memory block.
|
||||
* @param features - the set of additional features.
|
||||
* @return LIBBSC_NO_ERROR if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_reverse_block(unsigned char * T, int n, int features);
|
||||
|
||||
/**
|
||||
* Autodetects record size for better compression of multimedia files.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param n - the length of the input memory block.
|
||||
* @param features - the set of additional features.
|
||||
* @return The size of record if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_detect_recordsize(const unsigned char * input, int n, int features);
|
||||
|
||||
/**
|
||||
* Reorders memory block for specific size of record (Forward transform).
|
||||
* @param T - the input/output memory block of n bytes.
|
||||
* @param n - the length of the memory block.
|
||||
* @param recordSize - the size of record.
|
||||
* @param features - the set of additional features.
|
||||
* @return LIBBSC_NO_ERROR if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_reorder_forward(unsigned char * T, int n, int recordSize, int features);
|
||||
|
||||
/**
|
||||
* Reorders memory block for specific size of record (Reverse transform).
|
||||
* @param T - the input/output memory block of n bytes.
|
||||
* @param n - the length of the memory block.
|
||||
* @param recordSize - the size of record.
|
||||
* @param features - the set of additional features.
|
||||
* @return LIBBSC_NO_ERROR if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_reorder_reverse(unsigned char * T, int n, int recordSize, int features);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------*/
|
||||
/* End filters.h */
|
||||
/*-------------------------------------------------*/
|
587
bsc/libbsc/filters/detectors.cpp
Normal file
587
bsc/libbsc/filters/detectors.cpp
Normal file
|
@ -0,0 +1,587 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Detectors of blocksize, recordsize and contexts reorder. */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "../filters.h"
|
||||
|
||||
#include "../platform/platform.h"
|
||||
#include "../libbsc.h"
|
||||
|
||||
#include "tables.h"
|
||||
|
||||
#define DETECTORS_MAX_RECORD_SIZE 4
|
||||
#define DETECTORS_NUM_BLOCKS 48
|
||||
#define DETECTORS_BLOCK_SIZE 24576
|
||||
|
||||
struct BscSegmentationModel
|
||||
{
|
||||
struct
|
||||
{
|
||||
int left, right;
|
||||
} contextsCount[ALPHABET_SIZE];
|
||||
struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
int left, right;
|
||||
} Frequencies[ALPHABET_SIZE];
|
||||
} contexts[ALPHABET_SIZE];
|
||||
};
|
||||
|
||||
struct BscReorderingModel
|
||||
{
|
||||
struct
|
||||
{
|
||||
int frequencies[ALPHABET_SIZE];
|
||||
} contexts[DETECTORS_MAX_RECORD_SIZE][ALPHABET_SIZE];
|
||||
};
|
||||
|
||||
int bsc_detect_segments_serial(BscSegmentationModel * RESTRICT model, const unsigned char * RESTRICT input, int n)
|
||||
{
|
||||
memset(model, 0, sizeof(BscSegmentationModel));
|
||||
|
||||
for (int context = 0, i = 0; i < n; ++i)
|
||||
{
|
||||
unsigned char symbol = input[i];
|
||||
model->contexts[context].Frequencies[symbol].right++;
|
||||
context = (unsigned char)((context << 5) ^ symbol);
|
||||
}
|
||||
|
||||
long long entropy = 0;
|
||||
for (int context = 0; context < ALPHABET_SIZE; ++context)
|
||||
{
|
||||
int count = 0;
|
||||
for (int symbol = 0; symbol < ALPHABET_SIZE; ++symbol)
|
||||
{
|
||||
int frequency = model->contexts[context].Frequencies[symbol].right;
|
||||
count += frequency; entropy -= bsc_entropy(frequency);
|
||||
}
|
||||
model->contextsCount[context].right = count; entropy += bsc_entropy(count);
|
||||
}
|
||||
|
||||
int blockSize = n;
|
||||
|
||||
long long localEntropy = entropy, bestEntropy = entropy - (entropy >> 5) - (65536LL * 12 * 1024);
|
||||
for (int context = 0, i = 0; i < n; ++i)
|
||||
{
|
||||
if (localEntropy < bestEntropy)
|
||||
{
|
||||
bestEntropy = localEntropy;
|
||||
blockSize = i;
|
||||
}
|
||||
|
||||
unsigned char symbol = input[i];
|
||||
|
||||
localEntropy += bsc_delta(--model->contexts[context].Frequencies[symbol].right);
|
||||
localEntropy -= bsc_delta(model->contexts[context].Frequencies[symbol].left++);
|
||||
localEntropy -= bsc_delta(--model->contextsCount[context].right);
|
||||
localEntropy += bsc_delta(model->contextsCount[context].left++);
|
||||
|
||||
context = (unsigned char)((context << 5) ^ symbol);
|
||||
}
|
||||
|
||||
return blockSize;
|
||||
}
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
int bsc_detect_segments_parallel(BscSegmentationModel * RESTRICT model0, BscSegmentationModel * RESTRICT model1, const unsigned char * RESTRICT input, int n)
|
||||
{
|
||||
int globalBlockSize = n; long long globalEntropy, globalBestEntropy;
|
||||
|
||||
#pragma omp parallel num_threads(2)
|
||||
{
|
||||
int nThreads = omp_get_num_threads();
|
||||
int threadId = omp_get_thread_num();
|
||||
|
||||
if (nThreads == 1)
|
||||
{
|
||||
globalBlockSize = bsc_detect_segments_serial(model0, input, n);
|
||||
}
|
||||
else
|
||||
{
|
||||
int median = n / 2;
|
||||
|
||||
{
|
||||
if (threadId == 0)
|
||||
{
|
||||
memset(model0, 0, sizeof(BscSegmentationModel));
|
||||
|
||||
int context = 0;
|
||||
for (int i = 0; i < median; ++i)
|
||||
{
|
||||
unsigned char symbol = input[i];
|
||||
model0->contexts[context].Frequencies[symbol].right++;
|
||||
context = (unsigned char)((context << 5) ^ symbol);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(model1, 0, sizeof(BscSegmentationModel));
|
||||
|
||||
int context = (unsigned char)((input[median - 2] << 5) ^ input[median - 1]);
|
||||
for (int i = median; i < n; ++i)
|
||||
{
|
||||
unsigned char symbol = input[i];
|
||||
model1->contexts[context].Frequencies[symbol].left++;
|
||||
context = (unsigned char)((context << 5) ^ symbol);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma omp barrier
|
||||
}
|
||||
|
||||
{
|
||||
#pragma omp single
|
||||
{
|
||||
long long entropy = 0;
|
||||
for (int context = 0; context < ALPHABET_SIZE; ++context)
|
||||
{
|
||||
int count = 0;
|
||||
for (int symbol = 0; symbol < ALPHABET_SIZE; ++symbol)
|
||||
{
|
||||
int frequency = model0->contexts[context].Frequencies[symbol].right + model1->contexts[context].Frequencies[symbol].left;
|
||||
model0->contexts[context].Frequencies[symbol].right = model1->contexts[context].Frequencies[symbol].left = frequency;
|
||||
|
||||
count += frequency; entropy -= bsc_entropy(frequency);
|
||||
}
|
||||
model0->contextsCount[context].right = model1->contextsCount[context].left = count; entropy += bsc_entropy(count);
|
||||
}
|
||||
|
||||
globalEntropy = entropy; globalBestEntropy = entropy - (entropy >> 5) - (65536LL * 12 * 1024);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int localBlockSize = n; long long localBestEntropy = globalEntropy - (globalEntropy >> 5) - (65536LL * 12 * 1024);
|
||||
|
||||
if (threadId == 0)
|
||||
{
|
||||
long long localEntropy = globalEntropy;
|
||||
for (int context = 0, i = 0; i < median; ++i)
|
||||
{
|
||||
if (localEntropy < localBestEntropy)
|
||||
{
|
||||
localBestEntropy = localEntropy;
|
||||
localBlockSize = i;
|
||||
}
|
||||
|
||||
unsigned char symbol = input[i];
|
||||
|
||||
localEntropy += bsc_delta(--model0->contexts[context].Frequencies[symbol].right);
|
||||
localEntropy -= bsc_delta(model0->contexts[context].Frequencies[symbol].left++);
|
||||
localEntropy -= bsc_delta(--model0->contextsCount[context].right);
|
||||
localEntropy += bsc_delta(model0->contextsCount[context].left++);
|
||||
|
||||
context = (unsigned char)((context << 5) ^ symbol);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
long long localEntropy = globalEntropy;
|
||||
for (int i = n - 1; i >= median; --i)
|
||||
{
|
||||
unsigned char symbol = input[i];
|
||||
int context = (unsigned char)((input[i - 2] << 5) ^ input[i - 1]);
|
||||
|
||||
localEntropy -= bsc_delta(model1->contexts[context].Frequencies[symbol].right++);
|
||||
localEntropy += bsc_delta(--model1->contexts[context].Frequencies[symbol].left);
|
||||
localEntropy += bsc_delta(model1->contextsCount[context].right++);
|
||||
localEntropy -= bsc_delta(--model1->contextsCount[context].left);
|
||||
|
||||
if (localEntropy <= localBestEntropy)
|
||||
{
|
||||
localBestEntropy = localEntropy;
|
||||
localBlockSize = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (globalBestEntropy > localBestEntropy)
|
||||
{
|
||||
#pragma omp critical
|
||||
{
|
||||
if (globalBestEntropy > localBestEntropy)
|
||||
{
|
||||
globalBlockSize = localBlockSize; globalBestEntropy = localBestEntropy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return globalBlockSize;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
int bsc_detect_segments_recursive(BscSegmentationModel * model0, BscSegmentationModel * model1, const unsigned char * input, int n, int * segments, int k, int features)
|
||||
{
|
||||
if (n < DETECTORS_BLOCK_SIZE || k == 1)
|
||||
{
|
||||
segments[0] = n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int blockSize = n;
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
if (features & LIBBSC_FEATURE_MULTITHREADING)
|
||||
{
|
||||
blockSize = bsc_detect_segments_parallel(model0, model1, input, n);
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
blockSize = bsc_detect_segments_serial(model0, input, n);
|
||||
}
|
||||
|
||||
if (blockSize == n)
|
||||
{
|
||||
segments[0] = n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int leftResult = bsc_detect_segments_recursive(model0, model1, input, blockSize, segments, k - 1, features);
|
||||
if (leftResult < LIBBSC_NO_ERROR) return leftResult;
|
||||
|
||||
int rightResult = bsc_detect_segments_recursive(model0, model1, input + blockSize, n - blockSize, segments + leftResult, k - leftResult, features);
|
||||
if (rightResult < LIBBSC_NO_ERROR) return rightResult;
|
||||
|
||||
return leftResult + rightResult;
|
||||
}
|
||||
|
||||
int bsc_detect_segments(const unsigned char * input, int n, int * segments, int k, int features)
|
||||
{
|
||||
if (n < DETECTORS_BLOCK_SIZE || k == 1)
|
||||
{
|
||||
segments[0] = n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (BscSegmentationModel * model0 = (BscSegmentationModel *)bsc_malloc(sizeof(BscSegmentationModel)))
|
||||
{
|
||||
if (BscSegmentationModel * model1 = (BscSegmentationModel *)bsc_malloc(sizeof(BscSegmentationModel)))
|
||||
{
|
||||
int result = bsc_detect_segments_recursive(model0, model1, input, n, segments, k, features);
|
||||
|
||||
bsc_free(model1); bsc_free(model0);
|
||||
|
||||
return result;
|
||||
}
|
||||
bsc_free(model0);
|
||||
};
|
||||
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
static long long bsc_estimate_contextsorder(const unsigned char * input, int n)
|
||||
{
|
||||
int frequencies[ALPHABET_SIZE][3];
|
||||
|
||||
memset(frequencies, 0, sizeof(frequencies));
|
||||
|
||||
unsigned char MTF0 = 0;
|
||||
unsigned char MTF1 = 1;
|
||||
unsigned char MTFC = 0;
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
unsigned char C = input[i];
|
||||
if (C == MTF0)
|
||||
{
|
||||
frequencies[MTFC][0]++; MTFC = MTFC << 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (C == MTF1)
|
||||
{
|
||||
frequencies[MTFC][1]++; MTFC = (MTFC << 2) | 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
frequencies[MTFC][2]++; MTFC = (MTFC << 2) | 2;
|
||||
}
|
||||
MTF1 = MTF0; MTF0 = C;
|
||||
}
|
||||
}
|
||||
|
||||
long long entropy = 0;
|
||||
for (int context = 0; context < ALPHABET_SIZE; ++context)
|
||||
{
|
||||
int count = 0;
|
||||
for (int rank = 0; rank < 3; ++rank)
|
||||
{
|
||||
count += frequencies[context][rank];
|
||||
entropy -= bsc_entropy(frequencies[context][rank]);
|
||||
}
|
||||
entropy += bsc_entropy(count);
|
||||
}
|
||||
|
||||
return entropy;
|
||||
}
|
||||
|
||||
int bsc_detect_contextsorder(const unsigned char * RESTRICT input, int n, int features)
|
||||
{
|
||||
int sortingContexts = LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
|
||||
if ((n > DETECTORS_NUM_BLOCKS * DETECTORS_BLOCK_SIZE) && (features & LIBBSC_FEATURE_FASTMODE))
|
||||
{
|
||||
if (unsigned char * buffer = (unsigned char *)bsc_malloc(DETECTORS_NUM_BLOCKS * DETECTORS_BLOCK_SIZE * sizeof(unsigned char)))
|
||||
{
|
||||
int blockStride = (((n - DETECTORS_NUM_BLOCKS * DETECTORS_BLOCK_SIZE) / DETECTORS_NUM_BLOCKS) / 48) * 48;
|
||||
|
||||
for (int block = 0; block < DETECTORS_NUM_BLOCKS; ++block)
|
||||
{
|
||||
memcpy(buffer + block * DETECTORS_BLOCK_SIZE, input + block * (DETECTORS_BLOCK_SIZE + blockStride), DETECTORS_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
sortingContexts = bsc_detect_contextsorder(buffer, DETECTORS_NUM_BLOCKS * DETECTORS_BLOCK_SIZE, features);
|
||||
|
||||
bsc_free(buffer);
|
||||
}
|
||||
|
||||
return sortingContexts;
|
||||
}
|
||||
|
||||
if (unsigned char * RESTRICT buffer = (unsigned char *)bsc_malloc(n * sizeof(unsigned char)))
|
||||
{
|
||||
if (int * RESTRICT bucket0 = (int *)bsc_zero_malloc(ALPHABET_SIZE * ALPHABET_SIZE * sizeof(int)))
|
||||
{
|
||||
if (int * RESTRICT bucket1 = (int *)bsc_zero_malloc(ALPHABET_SIZE * ALPHABET_SIZE * sizeof(int)))
|
||||
{
|
||||
unsigned char C0 = input[n - 1];
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
unsigned char C1 = input[i];
|
||||
bucket0[(C0 << 8) | C1]++;
|
||||
bucket1[(C1 << 8) | C0]++;
|
||||
C0 = C1;
|
||||
}
|
||||
|
||||
for (int sum = 0, i = 0; i < ALPHABET_SIZE * ALPHABET_SIZE; ++i)
|
||||
{
|
||||
int tmp = sum; sum += bucket0[i]; bucket0[i] = tmp;
|
||||
}
|
||||
|
||||
unsigned char F0 = input[n - 2];
|
||||
unsigned char F1 = input[n - 1];
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
unsigned char F2 = input[i];
|
||||
buffer[bucket0[(F1 << 8) | F2]++] = F0;
|
||||
F0 = F1; F1 = F2;
|
||||
}
|
||||
|
||||
long long following = bsc_estimate_contextsorder(buffer, n);
|
||||
|
||||
for (int sum = 0, i = 0; i < ALPHABET_SIZE * ALPHABET_SIZE; ++i)
|
||||
{
|
||||
int tmp = sum; sum += bucket1[i]; bucket1[i] = tmp;
|
||||
}
|
||||
|
||||
unsigned char P0 = input[1];
|
||||
unsigned char P1 = input[0];
|
||||
for (int i = n - 1; i >= 0; --i)
|
||||
{
|
||||
unsigned char P2 = input[i];
|
||||
buffer[bucket1[(P1 << 8) | P2]++] = P0;
|
||||
P0 = P1; P1 = P2;
|
||||
}
|
||||
|
||||
long long preceding = bsc_estimate_contextsorder(buffer, n);
|
||||
|
||||
sortingContexts = (preceding < following) ? LIBBSC_CONTEXTS_PRECEDING : LIBBSC_CONTEXTS_FOLLOWING;
|
||||
|
||||
bsc_free(bucket1);
|
||||
}
|
||||
bsc_free(bucket0);
|
||||
};
|
||||
bsc_free(buffer);
|
||||
}
|
||||
|
||||
return sortingContexts;
|
||||
}
|
||||
|
||||
long long bsc_estimate_reordering(BscReorderingModel * model, int recordSize)
|
||||
{
|
||||
long long entropy = 0;
|
||||
for (int record = 0; record < recordSize; ++record)
|
||||
{
|
||||
for (int context = 0; context < ALPHABET_SIZE; ++context)
|
||||
{
|
||||
int count = 0;
|
||||
for (int symbol = 0; symbol < ALPHABET_SIZE; ++symbol)
|
||||
{
|
||||
int frequency = model->contexts[record][context].frequencies[symbol];
|
||||
count += frequency; entropy -= bsc_entropy(frequency);
|
||||
}
|
||||
entropy += (65536LL * 8 * (count < 256 ? count : 256)) + bsc_entropy(count);
|
||||
}
|
||||
}
|
||||
return entropy;
|
||||
}
|
||||
|
||||
int bsc_detect_recordsize(const unsigned char * RESTRICT input, int n, int features)
|
||||
{
|
||||
int result = LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
|
||||
if ((n > DETECTORS_NUM_BLOCKS * DETECTORS_BLOCK_SIZE) && (features & LIBBSC_FEATURE_FASTMODE))
|
||||
{
|
||||
if (unsigned char * buffer = (unsigned char *)bsc_malloc(DETECTORS_NUM_BLOCKS * DETECTORS_BLOCK_SIZE * sizeof(unsigned char)))
|
||||
{
|
||||
int blockStride = (((n - DETECTORS_NUM_BLOCKS * DETECTORS_BLOCK_SIZE) / DETECTORS_NUM_BLOCKS) / 48) * 48;
|
||||
|
||||
for (int block = 0; block < DETECTORS_NUM_BLOCKS; ++block)
|
||||
{
|
||||
memcpy(buffer + block * DETECTORS_BLOCK_SIZE, input + block * (DETECTORS_BLOCK_SIZE + blockStride), DETECTORS_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
result = bsc_detect_recordsize(buffer, DETECTORS_NUM_BLOCKS * DETECTORS_BLOCK_SIZE, features);
|
||||
|
||||
bsc_free(buffer);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (BscReorderingModel * RESTRICT model = (BscReorderingModel *)bsc_malloc(sizeof(BscReorderingModel)))
|
||||
{
|
||||
long long Entropy[DETECTORS_MAX_RECORD_SIZE];
|
||||
|
||||
if ((n % 48) != 0) n = n - (n % 48);
|
||||
|
||||
for (int recordSize = 1; recordSize <= DETECTORS_MAX_RECORD_SIZE; ++recordSize)
|
||||
{
|
||||
memset(model, 0, sizeof(BscReorderingModel));
|
||||
|
||||
if (recordSize == 1)
|
||||
{
|
||||
int ctx0 = 0;
|
||||
for (int i = 0; i < n; i += 8)
|
||||
{
|
||||
unsigned char c0 = input[i + 0]; model->contexts[0][ctx0].frequencies[c0]++; ctx0 = c0;
|
||||
unsigned char c1 = input[i + 1]; model->contexts[0][ctx0].frequencies[c1]++; ctx0 = c1;
|
||||
unsigned char c2 = input[i + 2]; model->contexts[0][ctx0].frequencies[c2]++; ctx0 = c2;
|
||||
unsigned char c3 = input[i + 3]; model->contexts[0][ctx0].frequencies[c3]++; ctx0 = c3;
|
||||
unsigned char c4 = input[i + 4]; model->contexts[0][ctx0].frequencies[c4]++; ctx0 = c4;
|
||||
unsigned char c5 = input[i + 5]; model->contexts[0][ctx0].frequencies[c5]++; ctx0 = c5;
|
||||
unsigned char c6 = input[i + 6]; model->contexts[0][ctx0].frequencies[c6]++; ctx0 = c6;
|
||||
unsigned char c7 = input[i + 7]; model->contexts[0][ctx0].frequencies[c7]++; ctx0 = c7;
|
||||
}
|
||||
}
|
||||
|
||||
if (recordSize == 2)
|
||||
{
|
||||
int ctx0 = 0, ctx1 = 0;
|
||||
for (int i = 0; i < n; i += 8)
|
||||
{
|
||||
unsigned char c0 = input[i + 0]; model->contexts[0][ctx0].frequencies[c0]++; ctx0 = c0;
|
||||
unsigned char c1 = input[i + 1]; model->contexts[1][ctx1].frequencies[c1]++; ctx1 = c1;
|
||||
unsigned char c2 = input[i + 2]; model->contexts[0][ctx0].frequencies[c2]++; ctx0 = c2;
|
||||
unsigned char c3 = input[i + 3]; model->contexts[1][ctx1].frequencies[c3]++; ctx1 = c3;
|
||||
unsigned char c4 = input[i + 4]; model->contexts[0][ctx0].frequencies[c4]++; ctx0 = c4;
|
||||
unsigned char c5 = input[i + 5]; model->contexts[1][ctx1].frequencies[c5]++; ctx1 = c5;
|
||||
unsigned char c6 = input[i + 6]; model->contexts[0][ctx0].frequencies[c6]++; ctx0 = c6;
|
||||
unsigned char c7 = input[i + 7]; model->contexts[1][ctx1].frequencies[c7]++; ctx1 = c7;
|
||||
}
|
||||
}
|
||||
|
||||
if (recordSize == 3)
|
||||
{
|
||||
int ctx0 = 0, ctx1 = 0, ctx2 = 0;
|
||||
for (int i = 0; i < n; i += 6)
|
||||
{
|
||||
unsigned char c0 = input[i + 0]; model->contexts[0][ctx0].frequencies[c0]++; ctx0 = c0;
|
||||
unsigned char c1 = input[i + 1]; model->contexts[1][ctx1].frequencies[c1]++; ctx1 = c1;
|
||||
unsigned char c2 = input[i + 2]; model->contexts[2][ctx2].frequencies[c2]++; ctx2 = c2;
|
||||
unsigned char c3 = input[i + 3]; model->contexts[0][ctx0].frequencies[c3]++; ctx0 = c3;
|
||||
unsigned char c4 = input[i + 4]; model->contexts[1][ctx1].frequencies[c4]++; ctx1 = c4;
|
||||
unsigned char c5 = input[i + 5]; model->contexts[2][ctx2].frequencies[c5]++; ctx2 = c5;
|
||||
}
|
||||
}
|
||||
|
||||
if (recordSize == 4)
|
||||
{
|
||||
int ctx0 = 0, ctx1 = 0, ctx2 = 0, ctx3 = 0;
|
||||
for (int i = 0; i < n; i += 8)
|
||||
{
|
||||
unsigned char c0 = input[i + 0]; model->contexts[0][ctx0].frequencies[c0]++; ctx0 = c0;
|
||||
unsigned char c1 = input[i + 1]; model->contexts[1][ctx1].frequencies[c1]++; ctx1 = c1;
|
||||
unsigned char c2 = input[i + 2]; model->contexts[2][ctx2].frequencies[c2]++; ctx2 = c2;
|
||||
unsigned char c3 = input[i + 3]; model->contexts[3][ctx3].frequencies[c3]++; ctx3 = c3;
|
||||
unsigned char c4 = input[i + 4]; model->contexts[0][ctx0].frequencies[c4]++; ctx0 = c4;
|
||||
unsigned char c5 = input[i + 5]; model->contexts[1][ctx1].frequencies[c5]++; ctx1 = c5;
|
||||
unsigned char c6 = input[i + 6]; model->contexts[2][ctx2].frequencies[c6]++; ctx2 = c6;
|
||||
unsigned char c7 = input[i + 7]; model->contexts[3][ctx3].frequencies[c7]++; ctx3 = c7;
|
||||
}
|
||||
}
|
||||
|
||||
if (recordSize > 4)
|
||||
{
|
||||
int Context[DETECTORS_MAX_RECORD_SIZE] = { 0 };
|
||||
for (int record = 0, i = 0; i < n; ++i)
|
||||
{
|
||||
model->contexts[record][Context[record]].frequencies[input[i]]++;
|
||||
Context[record] = input[i]; record++; if (record == recordSize) record = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Entropy[recordSize - 1] = bsc_estimate_reordering(model, recordSize);
|
||||
}
|
||||
|
||||
long long bestSize = Entropy[0] - (Entropy[0] >> 4) - (65536LL * 8 * 1024);
|
||||
|
||||
result = 1;
|
||||
for (int recordSize = 1; recordSize <= DETECTORS_MAX_RECORD_SIZE; ++recordSize)
|
||||
{
|
||||
if (bestSize > Entropy[recordSize - 1]) { bestSize = Entropy[recordSize - 1]; result = recordSize; }
|
||||
}
|
||||
|
||||
bsc_free(model);
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*/
|
||||
/* End detectors.cpp */
|
||||
/*-------------------------------------------------*/
|
182
bsc/libbsc/filters/preprocessing.cpp
Normal file
182
bsc/libbsc/filters/preprocessing.cpp
Normal file
|
@ -0,0 +1,182 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Data preprocessing functions */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "../filters.h"
|
||||
|
||||
#include "../platform/platform.h"
|
||||
#include "../libbsc.h"
|
||||
|
||||
int bsc_reverse_block(unsigned char * T, int n, int features)
|
||||
{
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
if (features & LIBBSC_FEATURE_MULTITHREADING)
|
||||
{
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < n / 2; ++i)
|
||||
{
|
||||
unsigned char tmp = T[i]; T[i] = T[n - 1 - i]; T[n - 1 - i] = tmp;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
for (int i = 0, j = n - 1; i < j; ++i, --j)
|
||||
{
|
||||
unsigned char tmp = T[i]; T[i] = T[j]; T[j] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
int bsc_reorder_forward(unsigned char * T, int n, int recordSize, int features)
|
||||
{
|
||||
if (recordSize <= 0) return LIBBSC_BAD_PARAMETER;
|
||||
if (recordSize == 1) return LIBBSC_NO_ERROR;
|
||||
|
||||
if (unsigned char * buffer = (unsigned char *)bsc_malloc(n))
|
||||
{
|
||||
memcpy(buffer, T, n);
|
||||
|
||||
unsigned char * RESTRICT S = buffer;
|
||||
unsigned char * RESTRICT D = T;
|
||||
|
||||
int chunk = (n / recordSize);
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
if (features & LIBBSC_FEATURE_MULTITHREADING)
|
||||
{
|
||||
switch (recordSize)
|
||||
{
|
||||
case 2:
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < chunk; ++i) { D[i] = S[2 * i]; D[chunk + i] = S[2 * i + 1]; } break;
|
||||
case 3:
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < chunk; ++i) { D[i] = S[3 * i]; D[chunk + i] = S[3 * i + 1]; D[chunk * 2 + i] = S[3 * i + 2]; } break;
|
||||
case 4:
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < chunk; ++i) { D[i] = S[4 * i]; D[chunk + i] = S[4 * i + 1]; D[chunk * 2 + i] = S[4 * i + 2]; D[chunk * 3 + i] = S[4 * i + 3]; } break;
|
||||
default:
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < chunk; ++i) { for (int j = 0; j < recordSize; ++j) D[j * chunk + i] = S[recordSize * i + j]; }
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
switch (recordSize)
|
||||
{
|
||||
case 2: for (int i = 0; i < chunk; ++i) { D[0] = S[0]; D[chunk] = S[1]; D++; S += 2; } break;
|
||||
case 3: for (int i = 0; i < chunk; ++i) { D[0] = S[0]; D[chunk] = S[1]; D[chunk * 2] = S[2]; D++; S += 3; } break;
|
||||
case 4: for (int i = 0; i < chunk; ++i) { D[0] = S[0]; D[chunk] = S[1]; D[chunk * 2] = S[2]; D[chunk * 3] = S[3]; D++; S += 4; } break;
|
||||
default:
|
||||
for (int i = 0; i < chunk; ++i) { for (int j = 0; j < recordSize; ++j) D[j * chunk] = S[j]; D++; S += recordSize; }
|
||||
}
|
||||
}
|
||||
|
||||
bsc_free(buffer); return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
int bsc_reorder_reverse(unsigned char * T, int n, int recordSize, int features)
|
||||
{
|
||||
if (recordSize <= 0) return LIBBSC_BAD_PARAMETER;
|
||||
if (recordSize == 1) return LIBBSC_NO_ERROR;
|
||||
|
||||
if (unsigned char * buffer = (unsigned char *)bsc_malloc(n))
|
||||
{
|
||||
memcpy(buffer, T, n);
|
||||
|
||||
unsigned char * RESTRICT S = buffer;
|
||||
unsigned char * RESTRICT D = T;
|
||||
|
||||
int chunk = (n / recordSize);
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
if (features & LIBBSC_FEATURE_MULTITHREADING)
|
||||
{
|
||||
switch (recordSize)
|
||||
{
|
||||
case 2:
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < chunk; ++i) { D[2 * i] = S[i]; D[2 * i + 1] = S[chunk + i]; } break;
|
||||
case 3:
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < chunk; ++i) { D[3 * i] = S[i]; D[3 * i + 1] = S[chunk + i]; D[3 * i + 2] = S[chunk * 2 + i]; } break;
|
||||
case 4:
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < chunk; ++i) { D[4 * i] = S[i]; D[4 * i + 1] = S[chunk + i]; D[4 * i + 2] = S[chunk * 2 + i]; D[4 * i + 3] = S[chunk * 3 + i]; } break;
|
||||
default:
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < chunk; ++i) { for (int j = 0; j < recordSize; ++j) D[recordSize * i + j] = S[j * chunk + i]; }
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
switch (recordSize)
|
||||
{
|
||||
case 2: for (int i = 0; i < chunk; ++i) { D[0] = S[0]; D[1] = S[chunk]; D += 2; S++; } break;
|
||||
case 3: for (int i = 0; i < chunk; ++i) { D[0] = S[0]; D[1] = S[chunk]; D[2] = S[chunk * 2]; D += 3; S++; } break;
|
||||
case 4: for (int i = 0; i < chunk; ++i) { D[0] = S[0]; D[1] = S[chunk]; D[2] = S[chunk * 2]; D[3] = S[chunk * 3]; D += 4; S++; } break;
|
||||
default:
|
||||
for (int i = 0; i < chunk; ++i) { for (int j = 0; j < recordSize; ++j) D[j] = S[j * chunk]; D += recordSize; S++; }
|
||||
}
|
||||
}
|
||||
|
||||
bsc_free(buffer); return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*/
|
||||
/* End preprocessing.cpp */
|
||||
/*-------------------------------------------------*/
|
756
bsc/libbsc/filters/tables.h
Normal file
756
bsc/libbsc/filters/tables.h
Normal file
|
@ -0,0 +1,756 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Static tables of constant values */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_FILTERS_TABLES_H
|
||||
#define _LIBBSC_FILTERS_TABLES_H
|
||||
|
||||
#include "../platform/platform.h"
|
||||
|
||||
static const unsigned int bsc_code_table[4096] =
|
||||
{
|
||||
0, 0, 65536, 103872, 131072, 152169, 169408, 183982, 196608, 207744, 217705, 226717,
|
||||
234944, 242512, 249518, 256041, 262144, 267875, 273280, 278392, 283241, 287854, 292253, 296456,
|
||||
300480, 304339, 308048, 311616, 315054, 318372, 321577, 324678, 327680, 330589, 333411, 336152,
|
||||
338816, 341406, 343928, 346384, 348777, 351112, 353390, 355615, 357789, 359914, 361992, 364025,
|
||||
366016, 367965, 369875, 371748, 373584, 375384, 377152, 378887, 380590, 382264, 383908, 385524,
|
||||
387113, 388676, 390214, 391727, 393216, 394681, 396125, 397547, 398947, 400328, 401688, 403029,
|
||||
404352, 405656, 406942, 408211, 409464, 410700, 411920, 413124, 414313, 415488, 416648, 417794,
|
||||
418926, 420045, 421151, 422244, 423325, 424393, 425450, 426494, 427528, 428550, 429561, 430562,
|
||||
431552, 432531, 433501, 434461, 435411, 436352, 437284, 438206, 439120, 440024, 440920, 441808,
|
||||
442688, 443559, 444423, 445278, 446126, 446967, 447800, 448626, 449444, 450256, 451060, 451858,
|
||||
452649, 453434, 454212, 454984, 455750, 456509, 457263, 458010, 458752, 459487, 460217, 460942,
|
||||
461661, 462374, 463083, 463786, 464483, 465176, 465864, 466546, 467224, 467897, 468565, 469229,
|
||||
469888, 470542, 471192, 471837, 472478, 473115, 473747, 474376, 475000, 475620, 476236, 476848,
|
||||
477456, 478060, 478660, 479257, 479849, 480438, 481024, 481606, 482184, 482759, 483330, 483898,
|
||||
484462, 485024, 485581, 486136, 486687, 487235, 487780, 488322, 488861, 489396, 489929, 490459,
|
||||
490986, 491509, 492030, 492548, 493064, 493576, 494086, 494593, 495097, 495599, 496098, 496594,
|
||||
497088, 497579, 498067, 498553, 499037, 499518, 499997, 500473, 500947, 501419, 501888, 502355,
|
||||
502820, 503282, 503742, 504200, 504656, 505109, 505560, 506009, 506456, 506901, 507344, 507785,
|
||||
508224, 508661, 509095, 509528, 509959, 510387, 510814, 511239, 511662, 512083, 512503, 512920,
|
||||
513336, 513750, 514162, 514572, 514980, 515387, 515792, 516195, 516596, 516996, 517394, 517791,
|
||||
518185, 518579, 518970, 519360, 519748, 520135, 520520, 520904, 521286, 521666, 522045, 522423,
|
||||
522799, 523173, 523546, 523917, 524288, 524656, 525023, 525389, 525753, 526116, 526478, 526838,
|
||||
527197, 527554, 527910, 528265, 528619, 528971, 529322, 529671, 530019, 530366, 530712, 531057,
|
||||
531400, 531742, 532082, 532422, 532760, 533097, 533433, 533768, 534101, 534434, 534765, 535095,
|
||||
535424, 535751, 536078, 536403, 536728, 537051, 537373, 537694, 538014, 538333, 538651, 538968,
|
||||
539283, 539598, 539912, 540224, 540536, 540846, 541156, 541464, 541772, 542078, 542384, 542688,
|
||||
542992, 543294, 543596, 543896, 544196, 544495, 544793, 545089, 545385, 545680, 545974, 546268,
|
||||
546560, 546851, 547142, 547431, 547720, 548008, 548295, 548581, 548866, 549150, 549434, 549717,
|
||||
549998, 550279, 550560, 550839, 551117, 551395, 551672, 551948, 552223, 552498, 552771, 553044,
|
||||
553316, 553588, 553858, 554128, 554397, 554665, 554932, 555199, 555465, 555730, 555995, 556259,
|
||||
556522, 556784, 557045, 557306, 557566, 557826, 558084, 558342, 558600, 558856, 559112, 559367,
|
||||
559622, 559876, 560129, 560381, 560633, 560884, 561135, 561384, 561634, 561882, 562130, 562377,
|
||||
562624, 562870, 563115, 563359, 563603, 563847, 564089, 564332, 564573, 564814, 565054, 565294,
|
||||
565533, 565771, 566009, 566247, 566483, 566719, 566955, 567190, 567424, 567658, 567891, 568124,
|
||||
568356, 568587, 568818, 569048, 569278, 569507, 569736, 569964, 570192, 570419, 570645, 570871,
|
||||
571096, 571321, 571545, 571769, 571992, 572215, 572437, 572659, 572880, 573101, 573321, 573541,
|
||||
573760, 573978, 574197, 574414, 574631, 574848, 575064, 575280, 575495, 575709, 575923, 576137,
|
||||
576350, 576563, 576775, 576987, 577198, 577409, 577619, 577829, 578039, 578248, 578456, 578664,
|
||||
578872, 579079, 579286, 579492, 579698, 579903, 580108, 580312, 580516, 580720, 580923, 581125,
|
||||
581328, 581530, 581731, 581932, 582132, 582332, 582532, 582731, 582930, 583129, 583327, 583524,
|
||||
583721, 583918, 584115, 584311, 584506, 584701, 584896, 585090, 585284, 585478, 585671, 585864,
|
||||
586056, 586248, 586440, 586631, 586822, 587012, 587202, 587392, 587581, 587770, 587959, 588147,
|
||||
588335, 588522, 588709, 588896, 589082, 589268, 589453, 589639, 589824, 590008, 590192, 590376,
|
||||
590559, 590742, 590925, 591107, 591289, 591471, 591652, 591833, 592014, 592194, 592374, 592554,
|
||||
592733, 592912, 593090, 593269, 593446, 593624, 593801, 593978, 594155, 594331, 594507, 594682,
|
||||
594858, 595033, 595207, 595382, 595555, 595729, 595902, 596075, 596248, 596421, 596593, 596764,
|
||||
596936, 597107, 597278, 597448, 597618, 597788, 597958, 598127, 598296, 598465, 598633, 598801,
|
||||
598969, 599137, 599304, 599471, 599637, 599804, 599970, 600135, 600301, 600466, 600631, 600795,
|
||||
600960, 601124, 601287, 601451, 601614, 601777, 601939, 602102, 602264, 602426, 602587, 602748,
|
||||
602909, 603070, 603230, 603390, 603550, 603710, 603869, 604028, 604187, 604345, 604504, 604662,
|
||||
604819, 604977, 605134, 605291, 605448, 605604, 605760, 605916, 606072, 606227, 606382, 606537,
|
||||
606692, 606846, 607000, 607154, 607308, 607461, 607614, 607767, 607920, 608072, 608224, 608376,
|
||||
608528, 608679, 608830, 608981, 609132, 609282, 609432, 609582, 609732, 609882, 610031, 610180,
|
||||
610329, 610477, 610625, 610774, 610921, 611069, 611216, 611364, 611510, 611657, 611804, 611950,
|
||||
612096, 612242, 612387, 612533, 612678, 612823, 612967, 613112, 613256, 613400, 613544, 613687,
|
||||
613831, 613974, 614117, 614260, 614402, 614544, 614686, 614828, 614970, 615111, 615253, 615394,
|
||||
615534, 615675, 615815, 615956, 616096, 616235, 616375, 616514, 616653, 616792, 616931, 617070,
|
||||
617208, 617346, 617484, 617622, 617759, 617897, 618034, 618171, 618307, 618444, 618580, 618716,
|
||||
618852, 618988, 619124, 619259, 619394, 619529, 619664, 619798, 619933, 620067, 620201, 620335,
|
||||
620468, 620602, 620735, 620868, 621001, 621134, 621266, 621399, 621531, 621663, 621795, 621926,
|
||||
622058, 622189, 622320, 622451, 622581, 622712, 622842, 622972, 623102, 623232, 623362, 623491,
|
||||
623620, 623749, 623878, 624007, 624136, 624264, 624392, 624520, 624648, 624776, 624903, 625031,
|
||||
625158, 625285, 625412, 625538, 625665, 625791, 625917, 626043, 626169, 626295, 626420, 626545,
|
||||
626671, 626796, 626920, 627045, 627170, 627294, 627418, 627542, 627666, 627790, 627913, 628036,
|
||||
628160, 628283, 628406, 628528, 628651, 628773, 628895, 629017, 629139, 629261, 629383, 629504,
|
||||
629625, 629747, 629868, 629988, 630109, 630230, 630350, 630470, 630590, 630710, 630830, 630950,
|
||||
631069, 631188, 631307, 631426, 631545, 631664, 631783, 631901, 632019, 632137, 632255, 632373,
|
||||
632491, 632608, 632726, 632843, 632960, 633077, 633194, 633310, 633427, 633543, 633660, 633776,
|
||||
633892, 634007, 634123, 634239, 634354, 634469, 634584, 634699, 634814, 634929, 635043, 635158,
|
||||
635272, 635386, 635500, 635614, 635728, 635841, 635955, 636068, 636181, 636294, 636407, 636520,
|
||||
636632, 636745, 636857, 636969, 637081, 637193, 637305, 637417, 637528, 637640, 637751, 637862,
|
||||
637973, 638084, 638195, 638306, 638416, 638527, 638637, 638747, 638857, 638967, 639077, 639186,
|
||||
639296, 639405, 639514, 639624, 639733, 639841, 639950, 640059, 640167, 640276, 640384, 640492,
|
||||
640600, 640708, 640816, 640923, 641031, 641138, 641245, 641352, 641459, 641566, 641673, 641780,
|
||||
641886, 641993, 642099, 642205, 642311, 642417, 642523, 642629, 642734, 642840, 642945, 643050,
|
||||
643155, 643260, 643365, 643470, 643575, 643679, 643784, 643888, 643992, 644096, 644200, 644304,
|
||||
644408, 644511, 644615, 644718, 644822, 644925, 645028, 645131, 645234, 645336, 645439, 645541,
|
||||
645644, 645746, 645848, 645950, 646052, 646154, 646256, 646357, 646459, 646560, 646661, 646763,
|
||||
646864, 646965, 647066, 647166, 647267, 647367, 647468, 647568, 647668, 647768, 647868, 647968,
|
||||
648068, 648168, 648267, 648367, 648466, 648566, 648665, 648764, 648863, 648962, 649060, 649159,
|
||||
649257, 649356, 649454, 649552, 649651, 649749, 649847, 649944, 650042, 650140, 650237, 650335,
|
||||
650432, 650529, 650626, 650723, 650820, 650917, 651014, 651110, 651207, 651303, 651400, 651496,
|
||||
651592, 651688, 651784, 651880, 651976, 652071, 652167, 652262, 652358, 652453, 652548, 652643,
|
||||
652738, 652833, 652928, 653023, 653117, 653212, 653306, 653400, 653495, 653589, 653683, 653777,
|
||||
653871, 653964, 654058, 654151, 654245, 654338, 654432, 654525, 654618, 654711, 654804, 654897,
|
||||
654989, 655082, 655175, 655267, 655360, 655452, 655544, 655636, 655728, 655820, 655912, 656004,
|
||||
656095, 656187, 656278, 656370, 656461, 656552, 656643, 656734, 656825, 656916, 657007, 657098,
|
||||
657188, 657279, 657369, 657460, 657550, 657640, 657730, 657820, 657910, 658000, 658090, 658179,
|
||||
658269, 658358, 658448, 658537, 658626, 658716, 658805, 658894, 658982, 659071, 659160, 659249,
|
||||
659337, 659426, 659514, 659602, 659691, 659779, 659867, 659955, 660043, 660131, 660218, 660306,
|
||||
660394, 660481, 660569, 660656, 660743, 660830, 660918, 661005, 661091, 661178, 661265, 661352,
|
||||
661438, 661525, 661611, 661698, 661784, 661870, 661957, 662043, 662129, 662214, 662300, 662386,
|
||||
662472, 662557, 662643, 662728, 662814, 662899, 662984, 663069, 663154, 663239, 663324, 663409,
|
||||
663494, 663579, 663663, 663748, 663832, 663917, 664001, 664085, 664169, 664253, 664337, 664421,
|
||||
664505, 664589, 664673, 664756, 664840, 664923, 665007, 665090, 665173, 665257, 665340, 665423,
|
||||
665506, 665589, 665671, 665754, 665837, 665919, 666002, 666084, 666167, 666249, 666331, 666414,
|
||||
666496, 666578, 666660, 666742, 666823, 666905, 666987, 667068, 667150, 667231, 667313, 667394,
|
||||
667475, 667557, 667638, 667719, 667800, 667881, 667962, 668042, 668123, 668204, 668284, 668365,
|
||||
668445, 668526, 668606, 668686, 668766, 668846, 668926, 669006, 669086, 669166, 669246, 669325,
|
||||
669405, 669485, 669564, 669644, 669723, 669802, 669881, 669961, 670040, 670119, 670198, 670277,
|
||||
670355, 670434, 670513, 670591, 670670, 670748, 670827, 670905, 670984, 671062, 671140, 671218,
|
||||
671296, 671374, 671452, 671530, 671608, 671685, 671763, 671841, 671918, 671996, 672073, 672150,
|
||||
672228, 672305, 672382, 672459, 672536, 672613, 672690, 672767, 672844, 672920, 672997, 673074,
|
||||
673150, 673227, 673303, 673379, 673456, 673532, 673608, 673684, 673760, 673836, 673912, 673988,
|
||||
674064, 674139, 674215, 674291, 674366, 674442, 674517, 674592, 674668, 674743, 674818, 674893,
|
||||
674968, 675043, 675118, 675193, 675268, 675343, 675418, 675492, 675567, 675641, 675716, 675790,
|
||||
675865, 675939, 676013, 676087, 676161, 676236, 676310, 676383, 676457, 676531, 676605, 676679,
|
||||
676752, 676826, 676900, 676973, 677046, 677120, 677193, 677266, 677340, 677413, 677486, 677559,
|
||||
677632, 677705, 677778, 677851, 677923, 677996, 678069, 678141, 678214, 678286, 678359, 678431,
|
||||
678503, 678576, 678648, 678720, 678792, 678864, 678936, 679008, 679080, 679152, 679223, 679295,
|
||||
679367, 679438, 679510, 679581, 679653, 679724, 679796, 679867, 679938, 680009, 680080, 680151,
|
||||
680222, 680293, 680364, 680435, 680506, 680577, 680647, 680718, 680789, 680859, 680930, 681000,
|
||||
681070, 681141, 681211, 681281, 681351, 681422, 681492, 681562, 681632, 681701, 681771, 681841,
|
||||
681911, 681981, 682050, 682120, 682189, 682259, 682328, 682398, 682467, 682536, 682606, 682675,
|
||||
682744, 682813, 682882, 682951, 683020, 683089, 683158, 683226, 683295, 683364, 683433, 683501,
|
||||
683570, 683638, 683707, 683775, 683843, 683912, 683980, 684048, 684116, 684184, 684252, 684320,
|
||||
684388, 684456, 684524, 684592, 684660, 684727, 684795, 684863, 684930, 684998, 685065, 685132,
|
||||
685200, 685267, 685334, 685402, 685469, 685536, 685603, 685670, 685737, 685804, 685871, 685938,
|
||||
686004, 686071, 686138, 686205, 686271, 686338, 686404, 686471, 686537, 686604, 686670, 686736,
|
||||
686802, 686869, 686935, 687001, 687067, 687133, 687199, 687265, 687331, 687396, 687462, 687528,
|
||||
687594, 687659, 687725, 687790, 687856, 687921, 687987, 688052, 688117, 688183, 688248, 688313,
|
||||
688378, 688443, 688508, 688573, 688638, 688703, 688768, 688833, 688898, 688962, 689027, 689092,
|
||||
689156, 689221, 689285, 689350, 689414, 689479, 689543, 689607, 689672, 689736, 689800, 689864,
|
||||
689928, 689992, 690056, 690120, 690184, 690248, 690312, 690376, 690439, 690503, 690567, 690630,
|
||||
690694, 690757, 690821, 690884, 690948, 691011, 691074, 691138, 691201, 691264, 691327, 691390,
|
||||
691453, 691516, 691579, 691642, 691705, 691768, 691831, 691893, 691956, 692019, 692081, 692144,
|
||||
692207, 692269, 692332, 692394, 692456, 692519, 692581, 692643, 692706, 692768, 692830, 692892,
|
||||
692954, 693016, 693078, 693140, 693202, 693264, 693326, 693387, 693449, 693511, 693572, 693634,
|
||||
693696, 693757, 693819, 693880, 693942, 694003, 694064, 694126, 694187, 694248, 694309, 694370,
|
||||
694431, 694492, 694553, 694614, 694675, 694736, 694797, 694858, 694919, 694980, 695040, 695101,
|
||||
695161, 695222, 695283, 695343, 695404, 695464, 695524, 695585, 695645, 695705, 695766, 695826,
|
||||
695886, 695946, 696006, 696066, 696126, 696186, 696246, 696306, 696366, 696426, 696486, 696545,
|
||||
696605, 696665, 696724, 696784, 696843, 696903, 696962, 697022, 697081, 697141, 697200, 697259,
|
||||
697319, 697378, 697437, 697496, 697555, 697614, 697673, 697732, 697791, 697850, 697909, 697968,
|
||||
698027, 698086, 698144, 698203, 698262, 698320, 698379, 698438, 698496, 698555, 698613, 698671,
|
||||
698730, 698788, 698846, 698905, 698963, 699021, 699079, 699137, 699196, 699254, 699312, 699370,
|
||||
699428, 699485, 699543, 699601, 699659, 699717, 699775, 699832, 699890, 699948, 700005, 700063,
|
||||
700120, 700178, 700235, 700293, 700350, 700407, 700465, 700522, 700579, 700636, 700694, 700751,
|
||||
700808, 700865, 700922, 700979, 701036, 701093, 701150, 701207, 701264, 701320, 701377, 701434,
|
||||
701491, 701547, 701604, 701660, 701717, 701774, 701830, 701886, 701943, 701999, 702056, 702112,
|
||||
702168, 702225, 702281, 702337, 702393, 702449, 702505, 702561, 702617, 702673, 702729, 702785,
|
||||
702841, 702897, 702953, 703009, 703064, 703120, 703176, 703232, 703287, 703343, 703398, 703454,
|
||||
703509, 703565, 703620, 703676, 703731, 703786, 703842, 703897, 703952, 704007, 704063, 704118,
|
||||
704173, 704228, 704283, 704338, 704393, 704448, 704503, 704558, 704613, 704668, 704722, 704777,
|
||||
704832, 704887, 704941, 704996, 705050, 705105, 705160, 705214, 705269, 705323, 705377, 705432,
|
||||
705486, 705540, 705595, 705649, 705703, 705757, 705812, 705866, 705920, 705974, 706028, 706082,
|
||||
706136, 706190, 706244, 706298, 706352, 706405, 706459, 706513, 706567, 706620, 706674, 706728,
|
||||
706781, 706835, 706888, 706942, 706995, 707049, 707102, 707156, 707209, 707262, 707316, 707369,
|
||||
707422, 707476, 707529, 707582, 707635, 707688, 707741, 707794, 707847, 707900, 707953, 708006,
|
||||
708059, 708112, 708165, 708218, 708270, 708323, 708376, 708428, 708481, 708534, 708586, 708639,
|
||||
708691, 708744, 708796, 708849, 708901, 708954, 709006, 709058, 709111, 709163, 709215, 709268,
|
||||
709320, 709372, 709424, 709476, 709528, 709580, 709632, 709684, 709736, 709788, 709840, 709892,
|
||||
709944, 709996, 710047, 710099, 710151, 710203, 710254, 710306, 710358, 710409, 710461, 710512,
|
||||
710564, 710615, 710667, 710718, 710770, 710821, 710872, 710924, 710975, 711026, 711077, 711129,
|
||||
711180, 711231, 711282, 711333, 711384, 711435, 711486, 711537, 711588, 711639, 711690, 711741,
|
||||
711792, 711843, 711893, 711944, 711995, 712046, 712096, 712147, 712197, 712248, 712299, 712349,
|
||||
712400, 712450, 712501, 712551, 712602, 712652, 712702, 712753, 712803, 712853, 712903, 712954,
|
||||
713004, 713054, 713104, 713154, 713204, 713254, 713304, 713355, 713404, 713454, 713504, 713554,
|
||||
713604, 713654, 713704, 713754, 713803, 713853, 713903, 713953, 714002, 714052, 714102, 714151,
|
||||
714201, 714250, 714300, 714349, 714399, 714448, 714498, 714547, 714596, 714646, 714695, 714744,
|
||||
714793, 714843, 714892, 714941, 714990, 715039, 715088, 715138, 715187, 715236, 715285, 715334,
|
||||
715383, 715431, 715480, 715529, 715578, 715627, 715676, 715725, 715773, 715822, 715871, 715919,
|
||||
715968, 716017, 716065, 716114, 716162, 716211, 716259, 716308, 716356, 716405, 716453, 716502,
|
||||
716550, 716598, 716646, 716695, 716743, 716791, 716839, 716888, 716936, 716984, 717032, 717080,
|
||||
717128, 717176, 717224, 717272, 717320, 717368, 717416, 717464, 717512, 717560, 717607, 717655,
|
||||
717703, 717751, 717798, 717846, 717894, 717941, 717989, 718037, 718084, 718132, 718179, 718227,
|
||||
718274, 718322, 718369, 718416, 718464, 718511, 718559, 718606, 718653, 718700, 718748, 718795,
|
||||
718842, 718889, 718936, 718983, 719031, 719078, 719125, 719172, 719219, 719266, 719313, 719360,
|
||||
719407, 719453, 719500, 719547, 719594, 719641, 719687, 719734, 719781, 719828, 719874, 719921,
|
||||
719968, 720014, 720061, 720107, 720154, 720200, 720247, 720293, 720340, 720386, 720433, 720479,
|
||||
720525, 720572, 720618, 720664, 720711, 720757, 720803, 720849, 720896, 720942, 720988, 721034,
|
||||
721080, 721126, 721172, 721218, 721264, 721310, 721356, 721402, 721448, 721494, 721540, 721585,
|
||||
721631, 721677, 721723, 721769, 721814, 721860, 721906, 721951, 721997, 722043, 722088, 722134,
|
||||
722179, 722225, 722270, 722316, 722361, 722407, 722452, 722498, 722543, 722588, 722634, 722679,
|
||||
722724, 722770, 722815, 722860, 722905, 722950, 722996, 723041, 723086, 723131, 723176, 723221,
|
||||
723266, 723311, 723356, 723401, 723446, 723491, 723536, 723581, 723626, 723671, 723715, 723760,
|
||||
723805, 723850, 723894, 723939, 723984, 724028, 724073, 724118, 724162, 724207, 724252, 724296,
|
||||
724341, 724385, 724430, 724474, 724518, 724563, 724607, 724652, 724696, 724740, 724785, 724829,
|
||||
724873, 724918, 724962, 725006, 725050, 725094, 725138, 725183, 725227, 725271, 725315, 725359,
|
||||
725403, 725447, 725491, 725535, 725579, 725623, 725667, 725711, 725754, 725798, 725842, 725886,
|
||||
725930, 725973, 726017, 726061, 726105, 726148, 726192, 726236, 726279, 726323, 726366, 726410,
|
||||
726454, 726497, 726541, 726584, 726627, 726671, 726714, 726758, 726801, 726844, 726888, 726931,
|
||||
726974, 727018, 727061, 727104, 727147, 727191, 727234, 727277, 727320, 727363, 727406, 727449,
|
||||
727493, 727536, 727579, 727622, 727665, 727708, 727750, 727793, 727836, 727879, 727922, 727965,
|
||||
728008, 728051, 728093, 728136, 728179, 728222, 728264, 728307, 728350, 728392, 728435, 728478,
|
||||
728520, 728563, 728605, 728648, 728690, 728733, 728775, 728818, 728860, 728903, 728945, 728988,
|
||||
729030, 729072, 729115, 729157, 729199, 729241, 729284, 729326, 729368, 729410, 729453, 729495,
|
||||
729537, 729579, 729621, 729663, 729705, 729747, 729789, 729831, 729873, 729915, 729957, 729999,
|
||||
730041, 730083, 730125, 730167, 730209, 730250, 730292, 730334, 730376, 730418, 730459, 730501,
|
||||
730543, 730584, 730626, 730668, 730709, 730751, 730793, 730834, 730876, 730917, 730959, 731000,
|
||||
731042, 731083, 731125, 731166, 731207, 731249, 731290, 731331, 731373, 731414, 731455, 731497,
|
||||
731538, 731579, 731620, 731662, 731703, 731744, 731785, 731826, 731867, 731909, 731950, 731991,
|
||||
732032, 732073, 732114, 732155, 732196, 732237, 732278, 732319, 732359, 732400, 732441, 732482,
|
||||
732523, 732564, 732604, 732645, 732686, 732727, 732767, 732808, 732849, 732890, 732930, 732971,
|
||||
733011, 733052, 733093, 733133, 733174, 733214, 733255, 733295, 733336, 733376, 733417, 733457,
|
||||
733498, 733538, 733578, 733619, 733659, 733699, 733740, 733780, 733820, 733861, 733901, 733941,
|
||||
733981, 734021, 734062, 734102, 734142, 734182, 734222, 734262, 734302, 734342, 734382, 734422,
|
||||
734462, 734502, 734542, 734582, 734622, 734662, 734702, 734742, 734782, 734822, 734861, 734901,
|
||||
734941, 734981, 735021, 735060, 735100, 735140, 735180, 735219, 735259, 735299, 735338, 735378,
|
||||
735417, 735457, 735497, 735536, 735576, 735615, 735655, 735694, 735734, 735773, 735813, 735852,
|
||||
735891, 735931, 735970, 736009, 736049, 736088, 736127, 736167, 736206, 736245, 736284, 736324,
|
||||
736363, 736402, 736441, 736480, 736520, 736559, 736598, 736637, 736676, 736715, 736754, 736793,
|
||||
736832, 736871, 736910, 736949, 736988, 737027, 737066, 737105, 737144, 737183, 737221, 737260,
|
||||
737299, 737338, 737377, 737415, 737454, 737493, 737532, 737570, 737609, 737648, 737686, 737725,
|
||||
737764, 737802, 737841, 737879, 737918, 737957, 737995, 738034, 738072, 738111, 738149, 738188,
|
||||
738226, 738264, 738303, 738341, 738380, 738418, 738456, 738495, 738533, 738571, 738610, 738648,
|
||||
738686, 738724, 738763, 738801, 738839, 738877, 738915, 738953, 738992, 739030, 739068, 739106,
|
||||
739144, 739182, 739220, 739258, 739296, 739334, 739372, 739410, 739448, 739486, 739524, 739562,
|
||||
739600, 739637, 739675, 739713, 739751, 739789, 739827, 739864, 739902, 739940, 739978, 740015,
|
||||
740053, 740091, 740128, 740166, 740204, 740241, 740279, 740317, 740354, 740392, 740429, 740467,
|
||||
740504, 740542, 740579, 740617, 740654, 740692, 740729, 740767, 740804, 740841, 740879, 740916,
|
||||
740954, 740991, 741028, 741066, 741103, 741140, 741177, 741215, 741252, 741289, 741326, 741363,
|
||||
741401, 741438, 741475, 741512, 741549, 741586, 741623, 741660, 741697, 741734, 741772, 741809,
|
||||
741846, 741883, 741919, 741956, 741993, 742030, 742067, 742104, 742141, 742178, 742215, 742252,
|
||||
742288, 742325, 742362, 742399, 742436, 742472, 742509, 742546, 742582, 742619, 742656, 742693,
|
||||
742729, 742766, 742802, 742839, 742876, 742912, 742949, 742985, 743022, 743058, 743095, 743131,
|
||||
743168, 743204, 743241, 743277, 743314, 743350, 743387, 743423, 743459, 743496, 743532, 743568,
|
||||
743605, 743641, 743677, 743713, 743750, 743786, 743822, 743858, 743895, 743931, 743967, 744003,
|
||||
744039, 744075, 744112, 744148, 744184, 744220, 744256, 744292, 744328, 744364, 744400, 744436,
|
||||
744472, 744508, 744544, 744580, 744616, 744652, 744688, 744724, 744759, 744795, 744831, 744867,
|
||||
744903, 744939, 744974, 745010, 745046, 745082, 745117, 745153, 745189, 745225, 745260, 745296,
|
||||
745332, 745367, 745403, 745438, 745474, 745510, 745545, 745581, 745616, 745652, 745687, 745723,
|
||||
745758, 745794, 745829, 745865, 745900, 745936, 745971, 746007, 746042, 746077, 746113, 746148,
|
||||
746183, 746219, 746254, 746289, 746325, 746360, 746395, 746430, 746466, 746501, 746536, 746571,
|
||||
746606, 746642, 746677, 746712, 746747, 746782, 746817, 746852, 746887, 746922, 746958, 746993,
|
||||
747028, 747063, 747098, 747133, 747168, 747202, 747237, 747272, 747307, 747342, 747377, 747412,
|
||||
747447, 747482, 747517, 747551, 747586, 747621, 747656, 747691, 747725, 747760, 747795, 747830,
|
||||
747864, 747899, 747934, 747968, 748003, 748038, 748072, 748107, 748142, 748176, 748211, 748245,
|
||||
748280, 748314, 748349, 748383, 748418, 748453, 748487, 748521, 748556, 748590, 748625, 748659,
|
||||
748694, 748728, 748762, 748797, 748831, 748866, 748900, 748934, 748969, 749003, 749037, 749071,
|
||||
749106, 749140, 749174, 749208, 749243, 749277, 749311, 749345, 749379, 749413, 749448, 749482,
|
||||
749516, 749550, 749584, 749618, 749652, 749686, 749720, 749754, 749788, 749822, 749856, 749890,
|
||||
749924, 749958, 749992, 750026, 750060, 750094, 750128, 750162, 750196, 750229, 750263, 750297,
|
||||
750331, 750365, 750399, 750432, 750466, 750500, 750534, 750567, 750601, 750635, 750668, 750702,
|
||||
750736, 750769, 750803, 750837, 750870, 750904, 750938, 750971, 751005, 751038, 751072, 751105,
|
||||
751139, 751173, 751206, 751240, 751273, 751307, 751340, 751373, 751407, 751440, 751474, 751507,
|
||||
751540, 751574, 751607, 751641, 751674, 751707, 751741, 751774, 751807, 751840, 751874, 751907,
|
||||
751940, 751974, 752007, 752040, 752073, 752106, 752140, 752173, 752206, 752239, 752272, 752305,
|
||||
752338, 752371, 752405, 752438, 752471, 752504, 752537, 752570, 752603, 752636, 752669, 752702,
|
||||
752735, 752768, 752801, 752834, 752867, 752899, 752932, 752965, 752998, 753031, 753064, 753097,
|
||||
753130, 753162, 753195, 753228, 753261, 753294, 753326, 753359, 753392, 753425, 753457, 753490,
|
||||
753523, 753555, 753588, 753621, 753653, 753686, 753719, 753751, 753784, 753816, 753849, 753882,
|
||||
753914, 753947, 753979, 754012, 754044, 754077, 754109, 754142, 754174, 754207, 754239, 754272,
|
||||
754304, 754337, 754369, 754401, 754434, 754466, 754498, 754531, 754563, 754595, 754628, 754660,
|
||||
754692, 754725, 754757, 754789, 754821, 754854, 754886, 754918, 754950, 754983, 755015, 755047,
|
||||
755079, 755111, 755143, 755176, 755208, 755240, 755272, 755304, 755336, 755368, 755400, 755432,
|
||||
755464, 755496, 755528, 755560, 755592, 755624, 755656, 755688, 755720, 755752, 755784, 755816,
|
||||
755848, 755880, 755912, 755943, 755975, 756007, 756039, 756071, 756103, 756134, 756166, 756198,
|
||||
756230, 756262, 756293, 756325, 756357, 756389, 756420, 756452, 756484, 756515, 756547, 756579,
|
||||
756610, 756642, 756674, 756705, 756737, 756768, 756800, 756832, 756863, 756895, 756926, 756958,
|
||||
756989, 757021, 757052, 757084, 757115, 757147, 757178, 757210, 757241, 757272, 757304, 757335,
|
||||
757367, 757398, 757429, 757461, 757492, 757524, 757555, 757586, 757617, 757649, 757680, 757711,
|
||||
757743, 757774, 757805, 757836, 757868, 757899, 757930, 757961, 757992, 758024, 758055, 758086,
|
||||
758117, 758148, 758179, 758210, 758242, 758273, 758304, 758335, 758366, 758397, 758428, 758459,
|
||||
758490, 758521, 758552, 758583, 758614, 758645, 758676, 758707, 758738, 758769, 758800, 758831,
|
||||
758862, 758892, 758923, 758954, 758985, 759016, 759047, 759078, 759108, 759139, 759170, 759201,
|
||||
759232, 759262, 759293, 759324, 759355, 759385, 759416, 759447, 759478, 759508, 759539, 759570,
|
||||
759600, 759631, 759662, 759692, 759723, 759753, 759784, 759815, 759845, 759876, 759906, 759937,
|
||||
759967, 759998, 760028, 760059, 760089, 760120, 760150, 760181, 760211, 760242, 760272, 760303,
|
||||
760333, 760364, 760394, 760424, 760455, 760485, 760516, 760546, 760576, 760607, 760637, 760667,
|
||||
760697, 760728, 760758, 760788, 760819, 760849, 760879, 760909, 760940, 760970, 761000, 761030,
|
||||
761060, 761091, 761121, 761151, 761181, 761211, 761241, 761272, 761302, 761332, 761362, 761392,
|
||||
761422, 761452, 761482, 761512, 761542, 761572, 761602, 761632, 761662, 761692, 761722, 761752,
|
||||
761782, 761812, 761842, 761872, 761902, 761932, 761962, 761992, 762022, 762051, 762081, 762111,
|
||||
762141, 762171, 762201, 762231, 762260, 762290, 762320, 762350, 762379, 762409, 762439, 762469,
|
||||
762498, 762528, 762558, 762588, 762617, 762647, 762677, 762706, 762736, 762766, 762795, 762825,
|
||||
762855, 762884, 762914, 762943, 762973, 763003, 763032, 763062, 763091, 763121, 763150, 763180,
|
||||
763209, 763239, 763268, 763298, 763327, 763357, 763386, 763416, 763445, 763475, 763504, 763533,
|
||||
763563, 763592, 763622, 763651, 763680, 763710, 763739, 763768, 763798, 763827, 763856, 763886,
|
||||
763915, 763944, 763974, 764003, 764032, 764061, 764091, 764120, 764149, 764178, 764207, 764237,
|
||||
764266, 764295, 764324, 764353, 764382, 764412, 764441, 764470, 764499, 764528, 764557, 764586,
|
||||
764615, 764644, 764673, 764703, 764732, 764761, 764790, 764819, 764848, 764877, 764906, 764935,
|
||||
764964, 764993, 765021, 765050, 765079, 765108, 765137, 765166, 765195, 765224, 765253, 765282,
|
||||
765311, 765339, 765368, 765397, 765426, 765455, 765484, 765512, 765541, 765570, 765599, 765627,
|
||||
765656, 765685, 765714, 765742, 765771, 765800, 765829, 765857, 765886, 765915, 765943, 765972,
|
||||
766001, 766029, 766058, 766087, 766115, 766144, 766172, 766201, 766230, 766258, 766287, 766315,
|
||||
766344, 766372, 766401, 766429, 766458, 766486, 766515, 766543, 766572, 766600, 766629, 766657,
|
||||
766686, 766714, 766743, 766771, 766800, 766828, 766856, 766885, 766913, 766941, 766970, 766998,
|
||||
767027, 767055, 767083, 767112, 767140, 767168, 767196, 767225, 767253, 767281, 767310, 767338,
|
||||
767366, 767394, 767422, 767451, 767479, 767507, 767535, 767563, 767592, 767620, 767648, 767676,
|
||||
767704, 767732, 767761, 767789, 767817, 767845, 767873, 767901, 767929, 767957, 767985, 768013,
|
||||
768041, 768069, 768097, 768125, 768153, 768181, 768209, 768237, 768265, 768293, 768321, 768349,
|
||||
768377, 768405, 768433, 768461, 768489, 768517, 768545, 768573, 768600, 768628, 768656, 768684,
|
||||
768712, 768740, 768768, 768795, 768823, 768851, 768879, 768907, 768934, 768962, 768990, 769018,
|
||||
769045, 769073, 769101, 769129, 769156, 769184, 769212, 769239, 769267, 769295, 769322, 769350,
|
||||
769378, 769405, 769433, 769461, 769488, 769516, 769543, 769571, 769599, 769626, 769654, 769681,
|
||||
769709, 769736, 769764, 769792, 769819, 769847, 769874, 769902, 769929, 769957, 769984, 770011,
|
||||
770039, 770066, 770094, 770121, 770149, 770176, 770204, 770231, 770258, 770286, 770313, 770340,
|
||||
770368, 770395, 770423, 770450, 770477, 770504, 770532, 770559, 770586, 770614, 770641, 770668,
|
||||
770696, 770723, 770750, 770777, 770805, 770832, 770859, 770886, 770913, 770941, 770968, 770995,
|
||||
771022, 771049, 771076, 771104, 771131, 771158, 771185, 771212, 771239, 771266, 771293, 771321,
|
||||
771348, 771375, 771402, 771429, 771456, 771483, 771510, 771537, 771564, 771591, 771618, 771645,
|
||||
771672, 771699, 771726, 771753, 771780, 771807, 771834, 771861, 771888, 771914, 771941, 771968,
|
||||
771995, 772022, 772049, 772076, 772103, 772130, 772156, 772183, 772210, 772237, 772264, 772291,
|
||||
772317, 772344, 772371, 772398, 772424, 772451, 772478, 772505, 772531, 772558, 772585, 772612,
|
||||
772638, 772665, 772692, 772718, 772745, 772772, 772798, 772825, 772852, 772878, 772905, 772932,
|
||||
772958, 772985, 773012, 773038, 773065, 773091, 773118, 773144, 773171, 773198, 773224, 773251,
|
||||
773277, 773304, 773330, 773357, 773383, 773410, 773436, 773463, 773489, 773516, 773542, 773569,
|
||||
773595, 773621, 773648, 773674, 773701, 773727, 773754, 773780, 773806, 773833, 773859, 773885,
|
||||
773912, 773938, 773964, 773991, 774017, 774043, 774070, 774096, 774122, 774149, 774175, 774201,
|
||||
774227, 774254, 774280, 774306, 774332, 774359, 774385, 774411, 774437, 774464, 774490, 774516,
|
||||
774542, 774568, 774594, 774621, 774647, 774673, 774699, 774725, 774751, 774777, 774804, 774830,
|
||||
774856, 774882, 774908, 774934, 774960, 774986, 775012, 775038, 775064, 775090, 775116, 775142,
|
||||
775168, 775194, 775220, 775246, 775272, 775298, 775324, 775350, 775376, 775402, 775428, 775454,
|
||||
775480, 775506, 775532, 775558, 775583, 775609, 775635, 775661, 775687, 775713, 775739, 775764,
|
||||
775790, 775816, 775842, 775868, 775894, 775919, 775945, 775971, 775997, 776022, 776048, 776074,
|
||||
776100, 776126, 776151, 776177, 776203, 776228, 776254, 776280, 776306, 776331, 776357, 776383,
|
||||
776408, 776434, 776460, 776485, 776511, 776536, 776562, 776588, 776613, 776639, 776665, 776690,
|
||||
776716, 776741, 776767, 776792, 776818, 776844, 776869, 776895, 776920, 776946, 776971, 776997,
|
||||
777022, 777048, 777073, 777099, 777124, 777150, 777175, 777201, 777226, 777251, 777277, 777302,
|
||||
777328, 777353, 777379, 777404, 777429, 777455, 777480, 777505, 777531, 777556, 777582, 777607,
|
||||
777632, 777658, 777683, 777708, 777733, 777759, 777784, 777809, 777835, 777860, 777885, 777910,
|
||||
777936, 777961, 777986, 778011, 778037, 778062, 778087, 778112, 778138, 778163, 778188, 778213,
|
||||
778238, 778263, 778289, 778314, 778339, 778364, 778389, 778414, 778439, 778465, 778490, 778515,
|
||||
778540, 778565, 778590, 778615, 778640, 778665, 778690, 778715, 778740, 778765, 778790, 778815,
|
||||
778840, 778866, 778891, 778916, 778940, 778965, 778990, 779015, 779040, 779065, 779090, 779115,
|
||||
779140, 779165, 779190, 779215, 779240, 779265, 779290, 779315, 779339, 779364, 779389, 779414,
|
||||
779439, 779464, 779489, 779513, 779538, 779563, 779588, 779613, 779638, 779662, 779687, 779712,
|
||||
779737, 779761, 779786, 779811, 779836, 779861, 779885, 779910, 779935, 779959, 779984, 780009,
|
||||
780034, 780058, 780083, 780108, 780132, 780157, 780182, 780206, 780231, 780256, 780280, 780305,
|
||||
780329, 780354, 780379, 780403, 780428, 780453, 780477, 780502, 780526, 780551, 780575, 780600,
|
||||
780624, 780649, 780674, 780698, 780723, 780747, 780772, 780796, 780821, 780845, 780870, 780894,
|
||||
780919, 780943, 780967, 780992, 781016, 781041, 781065, 781090, 781114, 781139, 781163, 781187,
|
||||
781212, 781236, 781261, 781285, 781309, 781334, 781358, 781382, 781407, 781431, 781455, 781480,
|
||||
781504, 781528, 781553, 781577, 781601, 781626, 781650, 781674, 781698, 781723, 781747, 781771,
|
||||
781795, 781820, 781844, 781868, 781892, 781917, 781941, 781965, 781989, 782013, 782038, 782062,
|
||||
782086, 782110, 782134, 782158, 782182, 782207, 782231, 782255, 782279, 782303, 782327, 782351,
|
||||
782375, 782400, 782424, 782448, 782472, 782496, 782520, 782544, 782568, 782592, 782616, 782640,
|
||||
782664, 782688, 782712, 782736, 782760, 782784, 782808, 782832, 782856, 782880, 782904, 782928,
|
||||
782952, 782976, 783000, 783024, 783048, 783072, 783096, 783119, 783143, 783167, 783191, 783215,
|
||||
783239, 783263, 783287, 783310, 783334, 783358, 783382, 783406, 783430, 783454, 783477, 783501,
|
||||
783525, 783549, 783573, 783596, 783620, 783644, 783668, 783691, 783715, 783739, 783763, 783786,
|
||||
783810, 783834, 783858, 783881, 783905, 783929, 783952, 783976, 784000, 784024, 784047, 784071,
|
||||
784095, 784118, 784142, 784165, 784189, 784213, 784236, 784260, 784284, 784307, 784331, 784354,
|
||||
784378, 784402, 784425, 784449, 784472, 784496, 784519, 784543, 784567, 784590, 784614, 784637,
|
||||
784661, 784684, 784708, 784731, 784755, 784778, 784802, 784825, 784849, 784872, 784896, 784919,
|
||||
784943, 784966, 784989, 785013, 785036, 785060, 785083, 785107, 785130, 785153, 785177, 785200,
|
||||
785223, 785247, 785270, 785294, 785317, 785340, 785364, 785387, 785410, 785434, 785457, 785480,
|
||||
785504, 785527, 785550, 785574, 785597, 785620, 785643, 785667, 785690, 785713, 785736, 785760,
|
||||
785783, 785806, 785829, 785853, 785876, 785899, 785922, 785946, 785969, 785992, 786015, 786038,
|
||||
786061, 786085, 786108, 786131, 786154, 786177, 786200, 786224, 786247, 786270, 786293, 786316,
|
||||
786339, 786362, 786385, 786408
|
||||
};
|
||||
|
||||
static const unsigned int bsc_delta_table[4096] =
|
||||
{
|
||||
0, 131072, 180544, 212672, 236557, 255603, 271426, 284990, 296832, 307354, 316837, 325441,
|
||||
333328, 340596, 347363, 353689, 359571, 365165, 370408, 375372, 380114, 384632, 388922, 393032,
|
||||
396955, 400773, 404384, 407880, 411276, 414522, 417708, 420742, 423677, 426537, 429346, 432056,
|
||||
434646, 437242, 439712, 442104, 444512, 446788, 449065, 451271, 453414, 455502, 457543, 459593,
|
||||
461517, 463465, 465398, 467220, 468984, 470856, 472577, 474255, 476008, 477616, 479252, 480864,
|
||||
482456, 484032, 485533, 487023, 488441, 489985, 491399, 492747, 494236, 495528, 496899, 498285,
|
||||
499544, 500820, 502117, 503439, 504636, 505860, 507036, 508244, 509488, 510608, 511766, 512882,
|
||||
514041, 515161, 516242, 517372, 518377, 519523, 520454, 521622, 522574, 523584, 524656, 525602,
|
||||
526515, 527591, 528541, 529461, 530452, 531416, 532250, 533262, 534040, 535000, 535936, 536848,
|
||||
537627, 538599, 539328, 540254, 541159, 541929, 542790, 543514, 544448, 545128, 546022, 546778,
|
||||
547634, 548350, 549168, 549968, 550625, 551513, 552132, 552986, 553567, 554387, 555192, 555850,
|
||||
556490, 557380, 557988, 558578, 559424, 560120, 560662, 561466, 562117, 562753, 563517, 564125,
|
||||
564718, 565442, 566007, 566705, 567391, 567915, 568726, 569224, 569860, 570484, 571096, 571696,
|
||||
572284, 572860, 573583, 573977, 574678, 575370, 575890, 576398, 577059, 577545, 578186, 578650,
|
||||
579440, 579714, 580486, 580908, 581491, 582065, 582630, 583186, 583556, 584270, 584799, 585319,
|
||||
585649, 586331, 586824, 587492, 587784, 588436, 588895, 589345, 589975, 590409, 590834, 591442,
|
||||
591851, 592251, 592837, 593417, 593794, 594360, 594721, 595273, 595819, 596157, 596689, 597215,
|
||||
597530, 598042, 598548, 599048, 599333, 599819, 600299, 600773, 601241, 601703, 602159, 602609,
|
||||
603053, 603273, 603922, 604348, 604547, 605181, 605589, 605991, 606387, 607003, 607162, 607768,
|
||||
608142, 608510, 608872, 609228, 609811, 610157, 610497, 610831, 611396, 611720, 612277, 612351,
|
||||
613139, 613201, 613740, 614032, 614563, 614845, 615368, 615640, 615906, 616416, 616923, 617175,
|
||||
617421, 617915, 618151, 618893, 618864, 619342, 619817, 620029, 620496, 620960, 621158, 621614,
|
||||
621802, 622250, 622695, 623137, 623307, 623741, 623901, 624327, 624750, 625170, 625587, 625725,
|
||||
626134, 626262, 626942, 627062, 627457, 627849, 628238, 628340, 629006, 629100, 629475, 629847,
|
||||
629927, 630581, 630653, 631303, 631367, 631719, 632068, 632414, 632757, 633097, 633434, 633468,
|
||||
634098, 634426, 634448, 635072, 635086, 635706, 635712, 636328, 636326, 636938, 636928, 637536,
|
||||
637518, 638122, 638096, 638696, 638979, 639259, 639217, 639809, 640080, 640348, 640936, 640876,
|
||||
641135, 641717, 641645, 642223, 642472, 642718, 642961, 643201, 643438, 644006, 644239, 644133,
|
||||
644695, 645257, 645141, 645359, 645915, 646129, 646340, 646548, 647098, 646956, 647502, 647700,
|
||||
648244, 648088, 648628, 648816, 649001, 649183, 649717, 649895, 650070, 650600, 650771, 650939,
|
||||
651104, 651266, 651788, 651946, 652466, 652254, 652770, 653286, 653064, 653576, 653717, 654227,
|
||||
654364, 654498, 654629, 655133, 655260, 655762, 655506, 656384, 656122, 656618, 656731, 657225,
|
||||
657334, 657440, 657543, 658031, 658519, 658227, 659102, 658804, 659286, 659374, 659854, 659938,
|
||||
660019, 660495, 660971, 660647, 661119, 661591, 661660, 661726, 662194, 662256, 662722, 662780,
|
||||
662835, 663297, 663348, 663808, 663855, 664313, 664356, 664812, 664851, 664887, 665339, 665371,
|
||||
665821, 665849, 666297, 666321, 666767, 666787, 667231, 667247, 667689, 667701, 668141, 668149,
|
||||
668154, 669024, 668592, 669026, 669460, 669456, 669888, 669880, 669869, 670297, 670725, 670709,
|
||||
671135, 671115, 671539, 671515, 671937, 671909, 672329, 672749, 672716, 672680, 673096, 673512,
|
||||
673471, 673885, 673840, 674252, 674203, 674613, 674560, 674968, 675376, 675318, 675257, 676129,
|
||||
676066, 676000, 676402, 676332, 676732, 677132, 677057, 677455, 677853, 677773, 677690, 678084,
|
||||
678478, 678872, 678783, 678691, 679081, 679471, 679374, 679762, 680150, 680048, 680434, 680328,
|
||||
680712, 681096, 680985, 681367, 681252, 681632, 682012, 681892, 682270, 682648, 682523, 682899,
|
||||
682770, 683144, 683518, 683384, 683756, 683618, 684499, 684359, 684216, 684584, 684952, 684804,
|
||||
685170, 685536, 685383, 685747, 686111, 685953, 686315, 686677, 686514, 686874, 687234, 687066,
|
||||
687424, 687252, 688139, 687433, 688320, 688142, 688496, 688850, 688667, 689019, 688832, 689722,
|
||||
689533, 689341, 690232, 689494, 690385, 690187, 690533, 690879, 691225, 691021, 690814, 691708,
|
||||
691499, 691841, 691628, 691968, 692308, 692648, 692429, 692767, 693105, 692881, 693217, 693553,
|
||||
693889, 693659, 693993, 693759, 694660, 694424, 694185, 695087, 694846, 695176, 694931, 695835,
|
||||
695588, 695338, 696243, 695991, 696317, 696061, 696968, 696710, 697034, 696772, 697094, 697416,
|
||||
697738, 697470, 697790, 698110, 698430, 698156, 698474, 698792, 698513, 699427, 699146, 698862,
|
||||
699777, 699491, 699805, 700119, 699828, 700140, 700452, 700764, 700467, 700777, 701087, 701397,
|
||||
701094, 701402, 701710, 702018, 701709, 702015, 702321, 702627, 702312, 702616, 702920, 703224,
|
||||
702903, 703205, 703507, 703809, 703482, 703782, 704082, 704382, 704682, 704348, 704646, 704944,
|
||||
704605, 704901, 705836, 704854, 705789, 705443, 706380, 705388, 706325, 706619, 706266, 706558,
|
||||
706850, 706492, 707433, 707073, 707363, 706999, 707942, 707576, 707864, 708152, 707781, 708727,
|
||||
708354, 708640, 708926, 708548, 708832, 709116, 709400, 709684, 709299, 710251, 709864, 709474,
|
||||
710427, 710035, 710990, 710596, 710199, 711155, 710756, 711034, 711312, 711590, 711868, 711462,
|
||||
711738, 712014, 712290, 711878, 712841, 712427, 712701, 712283, 713248, 712828, 713100, 713372,
|
||||
713644, 713916, 713489, 713759, 714029, 714299, 713866, 714838, 714403, 714671, 714939, 714499,
|
||||
715474, 715032, 715298, 715564, 715830, 715382, 716361, 715911, 716175, 716439, 715984, 716966,
|
||||
716509, 716771, 717033, 716571, 717556, 717092, 717352, 717612, 717872, 718132, 717661, 717919,
|
||||
718177, 718435, 718693, 718951, 718472, 718728, 718984, 719240, 719496, 719010, 720007, 719519,
|
||||
719773, 720027, 719534, 720534, 720039, 720291, 720543, 720795, 721047, 720545, 720795, 721801,
|
||||
721296, 720788, 721795, 722045, 721534, 721782, 722030, 722278, 722526, 722008, 722254, 723268,
|
||||
722747, 722993, 722468, 723484, 722957, 723201, 723445, 723689, 723933, 724177, 723642, 723884,
|
||||
724907, 724369, 723828, 724852, 725094, 724550, 724790, 725030, 725270, 725510, 725750, 725198,
|
||||
725436, 725674, 725912, 726150, 726388, 726626, 726065, 726301, 726537, 726773, 727009, 727245,
|
||||
726676, 727716, 727145, 727379, 727613, 727847, 727270, 728314, 727735, 728781, 728200, 728432,
|
||||
727847, 728895, 729127, 728539, 728769, 728999, 729229, 729459, 729689, 729093, 730148, 729550,
|
||||
729778, 730006, 730234, 730462, 729857, 730917, 730310, 730536, 730762, 730988, 731214, 730600,
|
||||
731665, 731049, 731273, 731497, 731721, 731945, 732169, 731545, 732616, 731990, 732212, 732434,
|
||||
732656, 732878, 733100, 732466, 733543, 732907, 733127, 733347, 733567, 733787, 733144, 734226,
|
||||
733581, 733799, 734884, 734236, 733585, 734671, 734889, 734235, 735324, 734668, 734884, 735100,
|
||||
735316, 735532, 734869, 735963, 735298, 735512, 735726, 735940, 736154, 736368, 736582, 735908,
|
||||
737009, 736333, 736545, 736757, 736969, 737181, 737393, 736709, 737816, 737130, 737340, 737550,
|
||||
737760, 737970, 738180, 738390, 737695, 738809, 738112, 738320, 738528, 738736, 738944, 739152,
|
||||
738447, 739567, 738860, 739982, 739273, 739479, 739685, 739891, 739176, 740302, 739585, 740713,
|
||||
739994, 740198, 740402, 740606, 740810, 741014, 740287, 741421, 740692, 740894, 742031, 741299,
|
||||
741501, 741703, 740966, 742106, 741367, 742509, 741768, 741968, 742168, 742368, 742568, 742768,
|
||||
742968, 742218, 743367, 742615, 743766, 743012, 743210, 743408, 743606, 742846, 744001, 743239,
|
||||
744396, 743632, 743828, 744988, 744221, 744417, 743646, 744808, 745004, 744230, 745395, 744619,
|
||||
744813, 745007, 745201, 745395, 745589, 745783, 744998, 746170, 745383, 746557, 745768, 745960,
|
||||
746152, 746344, 746536, 746728, 745931, 747111, 746312, 747494, 746693, 746883, 747073, 747263,
|
||||
747453, 747643, 747833, 747023, 748212, 747400, 747588, 748780, 747965, 748153, 748341, 748529,
|
||||
747708, 748904, 748081, 749279, 748454, 749654, 748827, 749013, 749199, 749385, 749571, 748737,
|
||||
749942, 750128, 749291, 750499, 749660, 749844, 750028, 750212, 750396, 750580, 750764, 749916,
|
||||
751131, 750281, 751498, 750646, 750828, 751010, 751192, 751374, 751556, 751738, 751920, 751058,
|
||||
752283, 751419, 752646, 751780, 751960, 752140, 752320, 752500, 752680, 752860, 751985, 753219,
|
||||
752342, 753578, 752699, 752877, 754116, 753234, 753412, 752526, 753767, 753945, 754123, 753233,
|
||||
754478, 753586, 753762, 755010, 754115, 754291, 754467, 754643, 754819, 753917, 755170, 755346,
|
||||
754441, 755697, 754790, 754964, 755138, 756398, 755487, 754573, 755834, 756008, 756182, 755264,
|
||||
756529, 755609, 756876, 755954, 756126, 757396, 756471, 756643, 755714, 756986, 757158, 757330,
|
||||
756397, 757673, 756738, 758016, 757079, 757249, 757419, 757589, 757759, 757929, 758099, 758269,
|
||||
758439, 757491, 758778, 757828, 759117, 758165, 758333, 758501, 758669, 758837, 759005, 759173,
|
||||
759341, 759509, 758546, 759844, 758879, 760179, 759212, 759378, 760681, 759711, 759877, 760043,
|
||||
760209, 759233, 760540, 760706, 759727, 761037, 760056, 761368, 760385, 760549, 761864, 760878,
|
||||
761042, 761206, 761370, 760378, 761697, 761861, 760866, 762188, 761191, 762515, 761516, 761678,
|
||||
763005, 762003, 762165, 762327, 762489, 762651, 761642, 762974, 763136, 762124, 763459, 762445,
|
||||
763782, 762766, 762926, 763086, 763246, 763406, 763566, 763726, 763886, 764046, 763019, 764365,
|
||||
764525, 763495, 764844, 763812, 763970, 764128, 765481, 764445, 764603, 764761, 764919, 763877,
|
||||
765234, 765392, 764347, 765707, 764660, 766022, 764973, 766337, 765286, 765442, 765598, 765754,
|
||||
765910, 766066, 766222, 766378, 765317, 766689, 766845, 765781, 767156, 766090, 766244, 767622,
|
||||
766553, 766707, 766861, 767015, 767169, 767323, 767477, 767631, 766552, 767938, 768092, 767010,
|
||||
768399, 767315, 767467, 768859, 767772, 767924, 768076, 768228, 768380, 768532, 768684, 768836,
|
||||
767739, 769139, 769291, 768191, 769594, 768492, 768642, 770048, 768943, 769093, 769243, 769393,
|
||||
769543, 769693, 769843, 769993, 770143, 770293, 769176, 770592, 769473, 770891, 769770, 771190,
|
||||
770067, 770215, 770363, 770511, 771936, 770808, 769677, 771103, 771251, 771399, 771547, 770411,
|
||||
771842, 771990, 770851, 770997, 772432, 771290, 771436, 772874, 771729, 771875, 772021, 772167,
|
||||
772313, 772459, 772605, 771451, 772896, 773042, 771885, 773333, 772174, 773624, 772463, 772607,
|
||||
774060, 772896, 773040, 773184, 773328, 773472, 773616, 773760, 773904, 772730, 774191, 774335,
|
||||
773158, 774622, 773443, 774909, 773728, 775196, 774013, 774155, 774297, 774439, 774581, 774723,
|
||||
774865, 775007, 775149, 775291, 775433, 774237, 775716, 775858, 774659, 776141, 774940, 775080,
|
||||
776565, 775361, 775501, 775641, 777130, 775922, 776062, 776202, 774989, 776481, 776621, 776761,
|
||||
776901, 775683, 777180, 775960, 777459, 776237, 777738, 776514, 776652, 778156, 776929, 777067,
|
||||
777205, 777343, 777481, 777619, 777757, 777895, 776658, 778170, 778308, 778446, 777205, 778721,
|
||||
777478, 778996, 777751, 777887, 779408, 778160, 778296, 778432, 778568, 778704, 778840, 778976,
|
||||
779112, 779248, 779384, 779520, 778259, 779791, 779927, 778663, 780198, 778932, 779066, 780604,
|
||||
779335, 779469, 781010, 779738, 779872, 780006, 780140, 780274, 780408, 780542, 780676, 779394,
|
||||
780943, 781077, 781211, 779925, 781478, 780190, 781745, 780455, 782012, 780720, 780852, 780984,
|
||||
782545, 781249, 781381, 781513, 781645, 781777, 781909, 782041, 780736, 782304, 782436, 782568,
|
||||
781259, 782831, 781520, 783094, 781781, 783357, 782042, 782172, 783751, 782433, 782563, 782693,
|
||||
782823, 782953, 783083, 783213, 783343, 783473, 783603, 783733, 782402, 783992, 784122, 782788,
|
||||
784381, 783045, 784640, 783302, 784899, 783559, 783687, 785287, 783944, 784072, 784200, 784328,
|
||||
784456, 784584, 784712, 784840, 784968, 785096, 785224, 783868, 785479, 785607, 784248, 785862,
|
||||
784501, 786117, 784754, 786372, 785007, 785133, 786754, 785386, 785512, 785638, 785764, 785890,
|
||||
786016, 786142, 786268, 786394, 786520, 786646, 785265, 786897, 787023, 785639, 787274, 787400,
|
||||
786013, 787651, 786262, 786386, 788027, 786635, 786759, 788403, 787008, 787132, 787256, 787380,
|
||||
787504, 787628, 787752, 787876, 788000, 788124, 786717, 788371, 788495, 787085, 788742, 788866,
|
||||
787453, 789113, 787698, 789360, 787943, 788065, 789730, 788310, 788432, 788554, 788676, 788798,
|
||||
788920, 789042, 789164, 789286, 789408, 789530, 789652, 789774, 789896, 788460, 790139, 788701,
|
||||
790382, 790504, 789063, 790747, 789304, 789424, 791111, 789665, 789785, 791475, 790026, 790146,
|
||||
790266, 790386, 790506, 790626, 790746, 790866, 790986, 791106, 791226, 791346, 789883, 791585,
|
||||
791705, 790239, 791944, 790476, 792183, 790713, 792422, 790950, 792661, 791187, 791305, 793019,
|
||||
791542, 791660, 791778, 791896, 792014, 792132, 792250, 792368, 792486, 792604, 792722, 792840,
|
||||
792958, 791466, 793193, 793311, 791816, 793546, 793664, 792166, 793899, 792399, 792515, 794251,
|
||||
792748, 792864, 794603, 793097, 793213, 793329, 793445, 795189, 793678, 793794, 793910, 794026,
|
||||
792509, 794257, 794373, 794489, 794605, 794721, 793198, 794952, 795068, 793542, 795299, 793771,
|
||||
795530, 794000, 795761, 794229, 794343, 796107, 794572, 794686, 794800, 796568, 795029, 795143,
|
||||
795257, 795371, 795485, 795599, 795713, 795827, 795941, 796055, 794504, 796282, 796396, 796510,
|
||||
794955, 796737, 795180, 796964, 797078, 795518, 795630, 797418, 795855, 797645, 796080, 796192,
|
||||
797985, 796417, 796529, 796641, 796753, 796865, 796977, 797089, 797201, 797313, 797425, 797537,
|
||||
797649, 797761, 797873, 796289, 798096, 798208, 798320, 796732, 798543, 796953, 798766, 797174,
|
||||
798989, 797395, 799212, 797616, 797726, 799546, 797947, 798057, 798167, 799991, 798388, 798498,
|
||||
798608, 798718, 798828, 798938, 799048, 799158, 799268, 799378, 799488, 797872, 799707, 799817,
|
||||
799927, 798307, 800146, 798524, 800365, 800475, 798850, 800694, 799067, 799175, 801022, 799392,
|
||||
799500, 801350, 799717, 799825, 799933, 801787, 800150, 800258, 800366, 800474, 800582, 800690,
|
||||
800798, 800906, 801014, 801122, 799473, 801337, 801445, 801553, 799900, 801768, 801876, 800220,
|
||||
802091, 800433, 802306, 800646, 802521, 800859, 802736, 801072, 801178, 803058, 801391, 801497,
|
||||
803380, 801710, 801816, 801922, 802028, 802134, 802240, 802346, 802452, 802558, 802664, 802770,
|
||||
802876, 802982, 803088, 801402, 803299, 803405, 801716, 803616, 803722, 802030, 803933, 802239,
|
||||
804144, 802448, 804355, 802657, 804566, 802866, 802970, 804882, 803179, 803283, 805198, 803492,
|
||||
803596, 803700, 803804, 803908, 804012, 804116, 804220, 804324, 804428, 804532, 804636, 804740,
|
||||
804844, 803122, 805051, 805155, 805259, 803533, 805466, 805570, 803841, 805777, 804046, 805984,
|
||||
804251, 806191, 804456, 806398, 804661, 804763, 806708, 804968, 805070, 805172, 807121, 805377,
|
||||
805479, 805581, 805683, 805785, 805887, 805989, 806091, 806193, 806295, 806397, 806499, 806601,
|
||||
806703, 804943, 806906, 807008, 807110, 805346, 807313, 805547, 807516, 807618, 805849, 807821,
|
||||
806050, 808024, 806251, 808227, 806452, 806552, 808531, 806753, 806853, 806953, 808936, 807154,
|
||||
807254, 807354, 807454, 807554, 807654, 807754, 809745, 806063, 808054, 808154, 808254, 808354,
|
||||
808454, 808554, 808654, 806854, 808853, 808953, 809053, 807249, 809252, 809352, 807545, 809551,
|
||||
807742, 809750, 807939, 809949, 808136, 810148, 808333, 808431, 810446, 808628, 808726, 808824,
|
||||
810843, 809021, 809119, 809217, 809315, 809413, 811438, 809610, 809708, 809806, 809904, 810002,
|
||||
808167, 810197, 810295, 810393, 810491, 810589, 810687, 808845, 810882, 810980, 809135, 811175,
|
||||
811273, 809425, 811468, 809618, 811663, 809811, 811858, 810004, 812053, 810197, 812248, 810390,
|
||||
810486, 810582, 812637, 810775, 810871, 810967, 813026, 811160, 811256, 811352, 811448, 811544,
|
||||
811640, 811736, 811832, 811928, 812024, 812120, 812216, 812312, 812408, 810526, 812599, 812695,
|
||||
812791, 810905, 812982, 813078, 811189, 813269, 813365, 811473, 813556, 811662, 813747, 811851,
|
||||
813938, 812040, 812134, 814224, 812323, 814415, 812512, 812606, 812700, 814796, 812889, 812983,
|
||||
813077, 813171, 813265, 815367, 813454, 813548, 813642, 813736, 813830, 813924, 814018, 814112,
|
||||
812189, 814299, 814393, 814487, 814581, 812653, 814768, 814862, 814956, 813024, 815143, 815237,
|
||||
813302, 815424, 813487, 815611, 813672, 815798, 813857, 815985, 814042, 816172, 814227, 814319,
|
||||
816452, 814504, 814596, 816732, 814781, 814873, 814965, 817105, 815150, 815242, 815334, 815426,
|
||||
815518, 815610, 815702, 815794, 815886, 815978, 816070, 816162, 816254, 816346, 814375, 816529,
|
||||
816621, 816713, 816805, 814829, 816988, 817080, 815101, 817263, 817355, 815373, 817538, 815554,
|
||||
817721, 815735, 817904, 815916, 818087, 816097, 818270, 816278, 816368, 818544, 816549, 816639,
|
||||
818818, 816820, 816910, 817000, 817090, 819274, 817271, 817361, 817451, 817541, 817631, 817721,
|
||||
817811, 817901, 817991, 818081, 818171, 818261, 818351, 818441, 818531, 816511, 818710, 818800,
|
||||
818890, 816866, 819069, 819159, 817132, 819338, 819428, 817398, 819607, 819697, 817664, 819876,
|
||||
817841, 820055, 818018, 818106, 820323, 818283, 820502, 818460, 818548, 820770, 818725, 818813,
|
||||
821038, 818990, 819078, 819166, 819254, 819342, 821573, 819519, 819607, 819695, 819783, 819871,
|
||||
819959, 820047, 820135, 820223, 820311, 820399, 820487, 818419, 820662, 820750, 820838, 820926,
|
||||
818853, 821101, 821189, 821277, 819200, 821452, 821540, 819460, 821715, 819633, 821890, 821978,
|
||||
819893, 822153, 820066, 820152, 822415, 820325, 822590, 820498, 820584, 822852, 820757, 820843,
|
||||
823114, 821016, 821102, 821188, 823463, 821361, 821447, 821533, 821619, 821705, 821791, 824073,
|
||||
821964, 822050, 822136, 822222, 822308, 820192, 822479, 822565, 822651, 822737, 822823, 822909,
|
||||
822995, 820871, 823166, 823252, 823338, 821210, 823509, 823595, 821464, 823766, 823852, 821718,
|
||||
824023, 821887, 824194, 822056, 824365, 822225, 824536, 822394, 824707, 822563, 824878, 822732,
|
||||
822816, 825134, 822985, 823069, 823153, 825475, 823322, 823406, 823490, 825816, 823659, 823743,
|
||||
823827, 823911, 823995, 824079, 824163, 824247, 824331, 824415, 824499, 824583, 824667, 824751,
|
||||
824835, 824919, 825003, 825087, 822910, 825254, 825338, 825422, 825506, 823324, 825673, 825757,
|
||||
823572, 825924, 826008, 823820, 826175, 826259, 824068, 826426, 824233, 826593, 824398, 826760,
|
||||
824563, 826927, 824728, 824810, 827177, 824975, 825057, 827427, 825222, 825304, 827677, 825469,
|
||||
825551, 825633, 828010, 825798, 825880, 825962, 826044, 826126, 828509, 826291, 826373, 826455,
|
||||
826537, 826619, 826701, 826783, 826865, 826947, 827029, 824799, 827192, 827274, 827356, 827438,
|
||||
827520, 825284, 827683, 827765, 827847, 825607, 828010, 828092, 828174, 825930, 828337, 826091,
|
||||
828500, 828582, 826333, 828745, 826494, 828908, 826655, 829071, 826816, 829234, 826977, 829397,
|
||||
827138, 827218, 829641, 827379, 827459, 829885, 827620, 827700, 830129, 827861, 827941, 828021,
|
||||
828101, 830535, 828262, 828342, 828422, 828502, 828582, 828662, 828742, 828822, 828902, 828982,
|
||||
829062, 829142, 829222, 829302, 829382, 829462, 829542, 829622, 829702, 827408, 829861, 829941,
|
||||
830021, 830101, 827802, 830260, 830340, 830420, 828117, 830579, 830659, 828353, 830818, 828510,
|
||||
830977, 831057, 828746, 831216, 828903, 831375, 829060, 831534, 829217, 831693, 829374, 829452,
|
||||
831931, 829609, 829687, 832169, 829844, 829922, 832407, 830079, 830157, 830235, 832724, 830392,
|
||||
830470, 830548, 830626, 833120, 830783, 830861, 830939, 831017, 831095, 831173, 831251, 831329,
|
||||
831407, 831485, 831563, 831641, 831719, 831797, 831875, 831953, 832031, 829675, 832186, 832264,
|
||||
832342, 832420, 830059, 832575, 832653, 832731, 830366, 832886, 832964, 830596, 833119, 833197,
|
||||
830826, 833352, 830979, 833507, 833585, 831209, 833740, 831362, 833895, 831515, 834050, 831668,
|
||||
831744, 834282, 831897, 834437, 832050, 832126, 834669, 832279, 832355, 834901, 832508, 832584,
|
||||
832660, 835210, 832813, 832889, 832965, 833041, 833117, 835673, 833270, 833346, 833422, 833498,
|
||||
833574, 833650, 833726, 833802, 833878, 833954, 834030, 834106, 834182, 834258, 834334, 834410,
|
||||
831989, 834561, 834637, 834713, 834789, 834865, 832438, 835016, 835092, 835168, 832737, 835319,
|
||||
835395, 832961, 835546, 835622, 833185, 835773, 835849, 833409, 836000, 833558, 836151, 833707,
|
||||
836302, 833856, 836453, 834005, 836604, 834154, 836755, 834303, 834377, 836981, 834526, 837132,
|
||||
834675, 834749, 837358, 834898, 834972, 835046, 837659, 835195, 835269, 835343, 835417, 838035,
|
||||
835566, 835640, 835714, 835788, 835862, 835936, 836010, 836084, 836158, 838786, 836307, 836381,
|
||||
836455, 833971, 836602, 836676, 836750, 836824, 836898, 836972, 837046, 837120, 837194, 834700,
|
||||
837341, 837415, 837489, 837563, 835064, 837710, 837784, 835282, 837931, 838005, 838079, 835573,
|
||||
838226, 835718, 838373, 838447, 835936, 838594, 836081, 838741, 836226, 838888, 836371, 839035,
|
||||
836516, 839182, 836661, 839329, 836806, 839476, 836951, 837023, 839696, 837168, 837240, 839916,
|
||||
837385, 837457, 837529, 840209, 837674, 837746, 837818, 840502, 837963, 838035, 838107, 838179,
|
||||
838251, 840941, 838396, 838468, 838540, 838612, 838684, 838756, 838828, 838900, 838972, 839044,
|
||||
839116, 839188, 839260, 839332, 839404, 839476, 839548, 836984, 839691, 839763, 839835, 839907,
|
||||
839979, 837409, 840122, 840194, 840266, 837692, 840409, 840481, 840553, 837975, 840696, 840768,
|
||||
838187, 840911, 838328, 841054, 841126, 838540, 841269, 838681, 841412, 838822, 841555, 838963,
|
||||
841698, 839104, 841841, 839245, 841984, 839386, 842127, 839527, 839597, 842341, 839738, 839808,
|
||||
842555, 839949, 840019, 842769, 840160, 840230, 840300, 843054, 840441, 840511, 840581, 840651,
|
||||
843410, 840792, 840862, 840932, 841002, 841072, 841142, 841212, 841282, 844050, 841423, 841493,
|
||||
841563, 841633, 841703, 841773, 839138, 841912, 841982, 842052, 842122, 842192, 842262, 842332,
|
||||
842402, 842472, 839827, 842611, 842681, 842751, 842821, 840171, 842960, 843030, 843100, 840446,
|
||||
843239, 843309, 840652, 843448, 843518, 840858, 843657, 843727, 841064, 843866, 841201, 844005,
|
||||
841338, 844144, 841475, 844283, 844353, 841681, 841749, 844561, 841886, 844700, 842023, 844839,
|
||||
842160, 842228, 845047, 842365, 845186, 842502, 842570, 845394, 842707, 842775, 842843, 845671,
|
||||
842980, 843048, 843116, 845948, 843253, 843321, 843389, 843457, 843525, 846363, 843662, 843730,
|
||||
843798, 843866, 843934, 844002, 844070, 844138, 844206, 844274, 844342, 844410, 844478, 844546,
|
||||
844614, 844682, 844750, 844818, 844886, 844954, 845022, 845090, 842365, 845225, 845293, 845361,
|
||||
845429, 845497, 842766, 845632, 845700, 845768, 843033, 845903, 845971, 843233, 846106, 846174,
|
||||
843433, 846309, 846377, 843633, 846512, 846580, 843833, 846715, 843966, 846850, 844099, 846985,
|
||||
847053, 844299, 847188, 844432, 847323, 844565, 844631, 847525, 844764, 847660, 844897, 844963,
|
||||
847862, 845096, 847997, 845229, 845295, 848199, 845428, 845494, 845560, 848468, 845693, 845759,
|
||||
848670, 845892, 845958, 846024, 846090, 849006, 846223, 846289, 846355, 846421, 846487, 846553,
|
||||
846619, 849543, 846752, 846818, 846884, 846950, 847016, 847082, 847148, 847214, 847280, 847346,
|
||||
847412, 847478, 847544, 847610, 844803, 847741, 847807, 847873, 847939, 848005, 848071, 848137,
|
||||
845322, 848268, 848334, 848400, 848466, 845646, 848597, 848663, 848729, 845905, 848860, 848926,
|
||||
846099, 849057, 849123, 846293, 849254, 849320, 846487, 849451, 846616, 849582, 849648, 846810,
|
||||
849779, 846939, 849910, 847068, 850041, 847197, 850172, 847326, 850303, 847455, 850434, 847584,
|
||||
850565, 847713, 847777, 850761, 847906, 847970, 850957, 848099, 848163, 851153, 848292, 848356,
|
||||
851349, 848485, 848549, 848613, 851610, 848742, 848806, 848870, 851871, 848999, 849063, 849127,
|
||||
849191, 849255, 852262, 849384, 849448, 849512, 849576, 849640, 849704, 849768, 849832, 849896,
|
||||
849960, 850024, 850088, 850152, 850216, 850280, 850344, 850408, 850472, 850536, 850600, 850664,
|
||||
850728, 850792, 847889, 850919, 850983, 851047, 851111, 851175, 848266, 851302, 851366, 851430,
|
||||
851494, 848580, 851621, 851685, 851749, 848831, 851876, 851940, 849019, 852067, 852131, 849207,
|
||||
852258, 852322, 849395, 852449, 849520, 852576, 852640, 849708, 852767, 849833, 852894, 849958,
|
||||
853021, 850083, 853148, 850208, 853275, 850333, 853402, 850458, 850520, 853592, 850645, 853719,
|
||||
850770, 850832, 853909, 850957, 854036, 851082, 851144, 851206, 854289, 851331, 851393, 854479,
|
||||
851518, 851580, 851642, 854732, 851767, 851829, 851891, 851953, 855048, 852078, 852140, 852202,
|
||||
852264, 852326, 852388, 855490, 852513, 852575, 852637, 852699, 852761, 852823, 852885, 852947,
|
||||
853009, 853071, 853133, 853195, 853257, 853319, 853381, 853443, 853505, 853567, 853629, 853691,
|
||||
850692, 853814, 853876, 853938, 854000, 854062, 854124, 851118, 854247, 854309, 854371, 854433,
|
||||
851422, 854556, 854618, 854680, 851665, 854803, 854865, 854927, 851908, 855050, 855112, 852090,
|
||||
855235, 855297, 852272, 855420, 852393, 855543, 855605, 852575, 855728, 852696, 855851, 852817,
|
||||
855974, 852938, 856097, 853059, 856220, 853180, 856343, 853301, 856466, 853422, 856589, 853543,
|
||||
856712, 853664, 853724, 856896, 853845, 857019, 853966, 854026, 857203, 854147, 854207, 854267,
|
||||
857448, 854388, 854448, 857632, 854569, 854629, 854689, 857877, 854810, 854870, 854930, 854990,
|
||||
858183, 855111, 855171, 855231, 855291, 855351, 858550, 855472, 855532, 855592, 855652, 855712,
|
||||
855772, 855832, 855892, 855952, 856012, 856072, 856132, 856192, 856252, 856312, 856372, 856432,
|
||||
856492, 856552, 856612, 856672, 856732, 856792, 856852, 856912, 853807, 857031, 857091, 857151,
|
||||
857211, 857271, 857331, 854219, 857450, 857510, 857570, 854454, 857689, 857749, 857809, 854689,
|
||||
857928, 857988, 858048, 854924, 858167, 858227, 855100, 858346, 858406, 855276, 858525, 858585,
|
||||
855452, 858704, 855569, 858823, 858883, 855745, 859002, 855862, 859121, 855979, 859240, 856096,
|
||||
859359, 856213, 859478, 856330, 859597, 856447, 859716, 856564, 859835, 856681, 856739, 860013,
|
||||
856856, 860132, 856973, 857031, 860310, 857148, 857206, 860488, 857323, 857381, 860666, 857498,
|
||||
857556, 860844, 857673, 857731, 857789, 861081, 857906, 857964, 858022, 858080, 861377, 858197,
|
||||
858255, 858313, 858371, 858429, 861732, 858546, 858604, 858662, 858720, 858778, 858836, 858894,
|
||||
858952, 859010, 862323, 859127, 859185, 859243, 859301, 859359, 859417, 859475, 859533, 859591,
|
||||
859649, 856441, 859764, 859822, 859880, 859938, 859996, 860054, 860112, 860170, 860228, 860286,
|
||||
857067, 860401, 860459, 860517, 860575, 860633, 857408, 860748, 860806, 860864, 857635, 860979,
|
||||
861037, 861095, 857862, 861210, 861268, 861326, 858089, 861441, 861499, 858259, 861614, 861672,
|
||||
858429, 861787, 861845, 858599, 861960, 858712, 862075, 862133, 858882, 862248, 858995, 862363,
|
||||
859108, 862478, 859221, 862593, 859334, 862708, 859447, 862823, 859560, 862938, 859673, 863053,
|
||||
859786, 863168, 859899, 863283, 860012, 860068, 863455, 860181, 860237, 863627, 860350, 863742,
|
||||
860463, 860519, 863914, 860632, 860688, 860744, 864143, 860857, 860913, 864315, 861026, 861082,
|
||||
861138, 861194, 864601, 861307, 861363, 861419, 861475, 864887, 861588, 861644, 861700, 861756,
|
||||
861812, 865230, 861925, 861981, 862037, 862093, 862149, 862205, 862261, 862317, 862373, 862429,
|
||||
862485, 862541, 862597, 862653, 862709, 862765, 862821, 862877, 862933, 862989, 863045, 863101,
|
||||
863157, 863213, 863269, 863325, 863381, 863437, 863493, 860157, 863604, 863660, 863716, 863772,
|
||||
863828, 863884, 860541, 863995, 864051, 864107, 864163, 860815, 864274, 864330, 864386, 861034,
|
||||
864497, 864553, 864609, 861253, 864720, 864776, 861417, 864887, 864943, 861581, 865054, 865110,
|
||||
861745, 865221, 865277, 861909, 865388, 862018, 865499, 865555, 862182, 865666, 862291, 865777,
|
||||
862400, 865888, 865944, 862564, 866055, 862673, 866166, 862782, 866277, 862891, 862945, 866443,
|
||||
863054, 866554, 863163, 866665, 863272, 866776, 863381, 863435, 866942, 863544, 863598, 867108,
|
||||
863707, 867219, 863816, 863870, 863924, 867440, 864033, 864087, 867606, 864196, 864250, 867772,
|
||||
864359, 864413, 864467, 867993, 864576, 864630, 864684, 864738, 868269, 864847, 864901, 864955,
|
||||
865009, 865063, 868600, 865172, 865226, 865280, 865334, 865388, 865442, 865496, 869041, 865605,
|
||||
865659, 865713, 865767, 865821, 865875, 865929, 865983, 866037, 866091, 866145, 866199, 866253,
|
||||
866307, 866361, 866415, 866469, 866523, 866577, 866631, 866685, 863226, 866792, 866846, 866900,
|
||||
866954, 867008, 867062, 867116, 867170, 863702, 867277, 867331, 867385, 867439, 867493, 864019,
|
||||
867600, 867654, 867708, 864230, 867815, 867869, 867923, 864441, 868030, 868084, 868138, 864652,
|
||||
868245, 868299, 864810, 868406, 868460, 864968, 868567, 868621, 865126, 868728, 868782, 865284,
|
||||
868889, 868943, 865442, 869050, 865547, 869157, 865652, 869264, 869318, 865810, 869425, 865915,
|
||||
869532, 866020, 869639, 866125, 869746, 866230, 869853, 866335, 869960, 866440, 870067, 866545,
|
||||
866597, 870227, 866702, 870334, 866807, 870441, 866912, 866964, 870601, 867069, 867121, 870761,
|
||||
867226, 867278, 870921, 867383, 867435, 871081, 867540, 867592, 871241, 867697, 867749, 867801,
|
||||
871454, 867906, 867958, 868010, 871667, 868115, 868167, 868219, 871880, 868324, 868376, 868428,
|
||||
868480, 868532, 872199, 868637, 868689, 868741, 868793, 868845, 868897, 872571, 869002, 869054,
|
||||
869106, 869158, 869210, 869262, 869314, 869366, 869418, 869470, 869522, 869574, 869626, 869678,
|
||||
869730, 869782, 869834, 869886, 869938, 869990, 870042, 870094, 870146, 870198, 870250, 870302,
|
||||
870354, 870406, 870458, 866858, 870561, 870613, 870665, 870717, 870769, 870821, 867214, 870924,
|
||||
870976, 871028, 871080, 871132, 867519, 871235, 871287, 871339, 867722, 871442, 871494, 871546,
|
||||
871598, 867976, 871701, 871753, 868128, 871856, 871908, 871960, 868331, 872063, 872115, 868483,
|
||||
872218, 872270, 868635, 872373, 868736, 872476, 872528, 868888, 872631, 872683, 869040, 872786,
|
||||
869141, 872889, 869242, 872992, 873044, 869394, 873147, 869495, 873250, 869596, 873353, 869697,
|
||||
873456, 869798, 873559, 869899, 873662, 870000, 873765, 870101, 870151, 873919, 870252, 874022,
|
||||
870353, 874125, 870454, 870504, 874279, 870605, 870655, 874433, 870756, 874536, 870857, 870907,
|
||||
874690, 871008, 871058, 871108, 874895, 871209, 871259, 875049, 871360, 871410, 871460, 875254,
|
||||
871561, 871611, 871661, 875459, 871762, 871812, 871862, 875664, 871963, 872013, 872063, 872113,
|
||||
872163, 875971, 872264, 872314, 872364, 872414, 872464, 872514, 876329, 872615, 872665, 872715,
|
||||
872765, 872815, 872865, 872915, 872965, 873015, 873065, 873115, 873165, 873215, 873265, 873315,
|
||||
877146, 873416, 873466, 869732, 873565, 873615, 873665, 873715, 873765, 873815, 873865, 873915,
|
||||
873965, 874015, 874065, 874115, 874165, 874215, 874265, 870515, 874364, 874414, 874464, 874514,
|
||||
874564, 874614, 870857, 874713, 874763, 874813, 874863, 874913, 871150, 875012, 875062, 875112,
|
||||
871345, 875211, 875261, 875311, 875361, 871589, 875460, 875510, 871735, 875609, 875659, 875709,
|
||||
871930, 875808, 875858, 872076, 875957, 876007, 872222, 876106, 876156, 872368, 876255, 872465,
|
||||
876354, 876404, 872611, 876503, 876553, 872757, 876652, 872854, 876751, 872951, 876850, 873048,
|
||||
876949, 876999, 873194, 877098, 873291, 877197, 873388, 877296, 873485, 877395, 873582, 877494,
|
||||
873679, 873727, 877642, 873824, 877741, 873921, 877840, 874018, 877939, 874115, 874163, 878087,
|
||||
874260, 878186, 874357, 874405, 878334, 874502, 874550, 878482, 874647, 874695, 878630, 874792,
|
||||
874840, 878778, 874937, 874985, 878926, 875082, 875130, 875178, 879123, 875275, 875323, 875371,
|
||||
879320, 875468, 875516, 875564, 879517, 875661, 875709, 875757, 875805, 879763, 875902, 875950,
|
||||
875998, 876046, 876094, 876142, 880107, 876239, 876287, 876335, 876383, 876431, 876479, 876527,
|
||||
880500, 876624, 876672, 876720, 876768, 876816, 876864, 876912, 876960, 877008, 877056, 877104,
|
||||
877152, 877200, 877248, 877296, 877344, 877392, 877440, 877488, 877536, 877584, 877632, 877680,
|
||||
877728, 877776, 877824, 877872, 877920, 877968, 874061, 878063, 878111, 878159, 878207, 878255,
|
||||
878303, 878351, 874436, 878446, 878494, 878542, 878590, 878638, 878686, 874764, 878781, 878829,
|
||||
878877, 878925, 874998, 879020, 879068, 879116, 875185, 879211, 879259, 879307, 875372, 879402,
|
||||
879450, 879498, 875559, 879593, 879641, 875699, 879736, 879784, 879832, 875886, 879927, 879975,
|
||||
876026, 880070, 876119, 880165, 880213, 876259, 880308, 880356, 876399, 880451, 876492, 880546,
|
||||
880594, 876632, 880689, 876725, 880784, 876818, 880879, 880927, 876958, 881022, 877051, 881117,
|
||||
877144, 881212, 877237, 881307, 877330, 881402, 877423, 881497, 877516, 881592, 877609, 881687,
|
||||
877702, 877748, 881829, 877841, 881924, 877934, 882019, 878027, 878073, 882161, 878166, 878212,
|
||||
882303, 878305, 882398, 878398, 878444, 882540, 878537, 878583, 882682, 878676, 878722, 882824,
|
||||
878815, 878861, 882966, 878954, 879000, 879046, 883155, 879139, 879185, 879231, 883344, 879324,
|
||||
879370, 879416, 883533, 879509, 879555, 879601, 883722, 879694, 879740, 879786, 879832, 879878,
|
||||
884005, 879971, 880017, 880063, 880109, 880155, 884288, 880248, 880294, 880340, 880386, 880432,
|
||||
880478, 880524, 880570, 884712
|
||||
};
|
||||
|
||||
static INLINE long long bsc_entropy(int n)
|
||||
{
|
||||
if (n < 0x1000) return (long long) n * bsc_code_table[n];
|
||||
if (n < 0x100000) return (long long) n * (8 * 65536 + bsc_code_table[n >> 8]);
|
||||
if (n < 0x10000000) return (long long) n * (16 * 65536 + bsc_code_table[n >> 16]);
|
||||
return (long long) n * (20 * 65536 + bsc_code_table[n >> 20]);
|
||||
}
|
||||
|
||||
static INLINE long long bsc_delta(int n)
|
||||
{
|
||||
if (n < 0x1000) return (long long) bsc_delta_table[n];
|
||||
if ((n & 0xff) != 0xff)
|
||||
{
|
||||
if (n < 0x100000) return (long long)(bsc_code_table[n >> 8] + 8 * 65536);
|
||||
if (n < 0x10000000) return (long long)(bsc_code_table[n >> 16] + 16 * 65536);
|
||||
return (long long)(bsc_code_table[n >> 20] + 20 * 65536);
|
||||
}
|
||||
return bsc_entropy(n + 1) - bsc_entropy(n);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End tables.h */
|
||||
/*-----------------------------------------------------------*/
|
165
bsc/libbsc/libbsc.h
Normal file
165
bsc/libbsc/libbsc.h
Normal file
|
@ -0,0 +1,165 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Interface to compression/decompression functions */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
/*--
|
||||
|
||||
Sort Transform is patented by Michael Schindler under US patent 6,199,064.
|
||||
However for research purposes this algorithm is included in this software.
|
||||
So if you are of the type who should worry about this (making money) worry away.
|
||||
The author shall have no liability with respect to the infringement of
|
||||
copyrights, trade secrets or any patents by this software. In no event will
|
||||
the author be liable for any lost revenue or profits or other special,
|
||||
indirect and consequential damages.
|
||||
|
||||
Sort Transform is disabled by default and can be enabled by defining the
|
||||
preprocessor macro LIBBSC_SORT_TRANSFORM_SUPPORT at compile time.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_LIBBSC_H
|
||||
#define _LIBBSC_LIBBSC_H
|
||||
|
||||
#define LIBBSC_NO_ERROR 0
|
||||
#define LIBBSC_BAD_PARAMETER -1
|
||||
#define LIBBSC_NOT_ENOUGH_MEMORY -2
|
||||
#define LIBBSC_NOT_COMPRESSIBLE -3
|
||||
#define LIBBSC_NOT_SUPPORTED -4
|
||||
#define LIBBSC_UNEXPECTED_EOB -5
|
||||
#define LIBBSC_DATA_CORRUPT -6
|
||||
|
||||
#define LIBBSC_GPU_ERROR -7
|
||||
#define LIBBSC_GPU_NOT_SUPPORTED -8
|
||||
#define LIBBSC_GPU_NOT_ENOUGH_MEMORY -9
|
||||
#define LIBBSC_SKIP_DATA -10
|
||||
|
||||
#define LIBBSC_BLOCKSORTER_NONE 0
|
||||
#define LIBBSC_BLOCKSORTER_BWT 1
|
||||
|
||||
#ifdef LIBBSC_SORT_TRANSFORM_SUPPORT
|
||||
|
||||
#define LIBBSC_BLOCKSORTER_ST3 3
|
||||
#define LIBBSC_BLOCKSORTER_ST4 4
|
||||
#define LIBBSC_BLOCKSORTER_ST5 5
|
||||
#define LIBBSC_BLOCKSORTER_ST6 6
|
||||
#define LIBBSC_BLOCKSORTER_ST7 7
|
||||
#define LIBBSC_BLOCKSORTER_ST8 8
|
||||
|
||||
#endif
|
||||
|
||||
#define LIBBSC_CODER_NONE 0
|
||||
#define LIBBSC_CODER_QLFC_STATIC 1
|
||||
#define LIBBSC_CODER_QLFC_ADAPTIVE 2
|
||||
|
||||
#define LIBBSC_FEATURE_NONE 0
|
||||
#define LIBBSC_FEATURE_FASTMODE 1
|
||||
#define LIBBSC_FEATURE_MULTITHREADING 2
|
||||
#define LIBBSC_FEATURE_LARGEPAGES 4
|
||||
#define LIBBSC_FEATURE_CUDA 8
|
||||
|
||||
#define LIBBSC_DEFAULT_LZPHASHSIZE 16
|
||||
#define LIBBSC_DEFAULT_LZPMINLEN 128
|
||||
#define LIBBSC_DEFAULT_BLOCKSORTER LIBBSC_BLOCKSORTER_BWT
|
||||
#define LIBBSC_DEFAULT_CODER LIBBSC_CODER_QLFC_STATIC
|
||||
#define LIBBSC_DEFAULT_FEATURES LIBBSC_FEATURE_FASTMODE | LIBBSC_FEATURE_MULTITHREADING
|
||||
|
||||
#define LIBBSC_HEADER_SIZE 28
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* You should call this function before you call any of the other functions in libbsc.
|
||||
* @param features - the set of additional features.
|
||||
* @return LIBBSC_NO_ERROR if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_init(int features);
|
||||
|
||||
/**
|
||||
* Compress a memory block.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param output - the output memory block of n + LIBBSC_HEADER_SIZE bytes.
|
||||
* @param n - the length of the input memory block.
|
||||
* @param lzpHashSize[0, 10..28] - the hash table size if LZP enabled, 0 otherwise.
|
||||
* @param lzpMinLen[0, 4..255] - the minimum match length if LZP enabled, 0 otherwise.
|
||||
* @param blockSorter[ST3..ST8, BWT] - the block sorting algorithm.
|
||||
* @param coder[MTF or QLFC] - the entropy coding algorithm.
|
||||
* @param features - the set of additional features.
|
||||
* @return the length of compressed memory block if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_compress(unsigned char * input, unsigned char * output, int n, int lzpHashSize, int lzpMinLen, int blockSorter, int coder, int features);
|
||||
|
||||
/**
|
||||
* Store a memory block.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param output - the output memory block of n + LIBBSC_HEADER_SIZE bytes.
|
||||
* @param n - the length of the input memory block.
|
||||
* @param features - the set of additional features.
|
||||
* @return the length of stored memory block if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_store(const unsigned char * input, unsigned char * output, int n, int features);
|
||||
|
||||
/**
|
||||
* Determinate the sizes of input and output memory blocks for bsc_decompress function.
|
||||
* @param blockHeader - the header of input(compressed) memory block of headerSize bytes.
|
||||
* @param headerSize - the length of header, should be at least LIBBSC_HEADER_SIZE bytes.
|
||||
* @param pBlockSize[out] - the length of the input memory block for bsc_decompress function.
|
||||
* @param pDataSize[out] - the length of the output memory block for bsc_decompress function.
|
||||
* @param features - the set of additional features.
|
||||
* @return LIBBSC_NO_ERROR if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_block_info(unsigned char * blockHeader, int headerSize, int * pBlockSize, int * pDataSize, int features);
|
||||
|
||||
/**
|
||||
* Decompress a memory block.
|
||||
* Note : You should call bsc_block_info function to determinate the sizes of input and output memory blocks.
|
||||
* @param input - the input memory block of inputSize bytes.
|
||||
* @param inputSize - the length of the input memory block.
|
||||
* @param output - the output memory block of outputSize bytes.
|
||||
* @param outputSize - the length of the output memory block.
|
||||
* @param features - the set of additional features.
|
||||
* @return LIBBSC_NO_ERROR if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_decompress(unsigned char * input, int inputSize, unsigned char * output, int outputSize, int features);
|
||||
int bsc_decompress_old(const unsigned char * input, int inputSize, unsigned char * output, int outputSize, int features);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------*/
|
||||
/* End libbsc.h */
|
||||
/*-------------------------------------------------*/
|
632
bsc/libbsc/libbsc/libbsc.cpp
Normal file
632
bsc/libbsc/libbsc/libbsc.cpp
Normal file
|
@ -0,0 +1,632 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Compression/decompression functions */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../platform/platform.h"
|
||||
#include "../libbsc.h"
|
||||
|
||||
#include "../adler32/adler32.h"
|
||||
#include "../bwt/bwt.h"
|
||||
#include "../lzp/lzp.h"
|
||||
#include "../coder/coder.h"
|
||||
|
||||
int bsc_init(int features)
|
||||
{
|
||||
int result = LIBBSC_NO_ERROR;
|
||||
|
||||
if (result == LIBBSC_NO_ERROR) result = bsc_platform_init(features);
|
||||
if (result == LIBBSC_NO_ERROR) result = bsc_coder_init(features);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int bsc_store(const unsigned char * input, unsigned char * output, int n, int features)
|
||||
{
|
||||
unsigned int adler32_data = bsc_adler32(input, n, features);
|
||||
|
||||
memmove(output + LIBBSC_HEADER_SIZE, input, n);
|
||||
*(int *)(output + 0) = n + LIBBSC_HEADER_SIZE;
|
||||
*(int *)(output + 4) = n;
|
||||
*(int *)(output + 8) = 0;
|
||||
*(int *)(output + 12) = 0;
|
||||
*(int *)(output + 16) = adler32_data;
|
||||
*(int *)(output + 20) = adler32_data;
|
||||
*(int *)(output + 24) = bsc_adler32(output, 24, features);
|
||||
return n + LIBBSC_HEADER_SIZE;
|
||||
}
|
||||
|
||||
int bsc_compress_inplace(unsigned char * data, int n, int lzpHashSize, int lzpMinLen, int blockSorter, int coder, int features)
|
||||
{
|
||||
int indexes[256];
|
||||
unsigned char num_indexes;
|
||||
|
||||
int mode = 0;
|
||||
|
||||
switch (blockSorter)
|
||||
{
|
||||
case LIBBSC_BLOCKSORTER_BWT : mode = LIBBSC_BLOCKSORTER_BWT; break;
|
||||
|
||||
default : return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
switch (coder)
|
||||
{
|
||||
case LIBBSC_CODER_QLFC_STATIC: mode += (LIBBSC_CODER_QLFC_STATIC << 5); break;
|
||||
case LIBBSC_CODER_QLFC_ADAPTIVE: mode += (LIBBSC_CODER_QLFC_ADAPTIVE << 5); break;
|
||||
|
||||
default : return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
if (lzpMinLen != 0 || lzpHashSize != 0)
|
||||
{
|
||||
if (lzpMinLen < 4 || lzpMinLen > 255) return LIBBSC_BAD_PARAMETER;
|
||||
if (lzpHashSize < 10 || lzpHashSize > 28) return LIBBSC_BAD_PARAMETER;
|
||||
mode += (lzpMinLen << 8);
|
||||
mode += (lzpHashSize << 16);
|
||||
}
|
||||
if (n < 0 || n > 1073741824) return LIBBSC_BAD_PARAMETER;
|
||||
if (n <= LIBBSC_HEADER_SIZE)
|
||||
{
|
||||
return bsc_store(data, data, n, features);
|
||||
}
|
||||
|
||||
unsigned int adler32_data = bsc_adler32(data, n, features);
|
||||
|
||||
int lzSize = n;
|
||||
if (mode != (mode & 0xff))
|
||||
{
|
||||
unsigned char * buffer = (unsigned char *)bsc_malloc(n);
|
||||
if (buffer == NULL) return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
|
||||
lzSize = bsc_lzp_compress(data, buffer, n, lzpHashSize, lzpMinLen, features);
|
||||
if (lzSize < LIBBSC_NO_ERROR)
|
||||
{
|
||||
lzSize = n; mode &= 0xff;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(data, buffer, lzSize);
|
||||
}
|
||||
|
||||
bsc_free(buffer);
|
||||
}
|
||||
|
||||
if (lzSize <= LIBBSC_HEADER_SIZE)
|
||||
{
|
||||
blockSorter = LIBBSC_BLOCKSORTER_BWT;
|
||||
mode = (mode & 0xffffffe0) | LIBBSC_BLOCKSORTER_BWT;
|
||||
}
|
||||
|
||||
int index = LIBBSC_BAD_PARAMETER; num_indexes = 0;
|
||||
switch (blockSorter)
|
||||
{
|
||||
case LIBBSC_BLOCKSORTER_BWT : index = bsc_bwt_encode(data, lzSize, &num_indexes, indexes, features); break;
|
||||
|
||||
default : return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
if (n < 64 * 1024) num_indexes = 0;
|
||||
|
||||
if (index < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
if (unsigned char * buffer = (unsigned char *)bsc_malloc(lzSize + 4096))
|
||||
{
|
||||
int result = bsc_coder_compress(data, buffer, lzSize, coder, features);
|
||||
if (result >= LIBBSC_NO_ERROR) memcpy(data + LIBBSC_HEADER_SIZE, buffer, result);
|
||||
bsc_free(buffer);
|
||||
if ((result < LIBBSC_NO_ERROR) || (result + 1 + 4 * num_indexes >= n))
|
||||
{
|
||||
return LIBBSC_NOT_COMPRESSIBLE;
|
||||
}
|
||||
{
|
||||
if (num_indexes > 0)
|
||||
{
|
||||
memcpy(data + LIBBSC_HEADER_SIZE + result, indexes, 4 * num_indexes);
|
||||
}
|
||||
data[LIBBSC_HEADER_SIZE + result + 4 * num_indexes] = num_indexes;
|
||||
result += 1 + 4 * num_indexes;
|
||||
}
|
||||
*(int *)(data + 0) = result + LIBBSC_HEADER_SIZE;
|
||||
*(int *)(data + 4) = n;
|
||||
*(int *)(data + 8) = mode;
|
||||
*(int *)(data + 12) = index;
|
||||
*(int *)(data + 16) = adler32_data;
|
||||
*(int *)(data + 20) = bsc_adler32(data + LIBBSC_HEADER_SIZE, result, features);
|
||||
*(int *)(data + 24) = bsc_adler32(data, 24, features);
|
||||
return result + LIBBSC_HEADER_SIZE;
|
||||
}
|
||||
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
int bsc_compress(unsigned char * input, unsigned char * output, int n, int lzpHashSize, int lzpMinLen, int blockSorter, int coder, int features)
|
||||
{
|
||||
if (input == output)
|
||||
{
|
||||
return bsc_compress_inplace(output, n, lzpHashSize, lzpMinLen, blockSorter, coder, features);
|
||||
}
|
||||
|
||||
int indexes[256];
|
||||
unsigned char num_indexes;
|
||||
|
||||
int mode = 0;
|
||||
|
||||
switch (blockSorter)
|
||||
{
|
||||
case LIBBSC_BLOCKSORTER_BWT : mode = LIBBSC_BLOCKSORTER_BWT; break;
|
||||
|
||||
default : return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
switch (coder)
|
||||
{
|
||||
case LIBBSC_CODER_QLFC_STATIC: mode += (LIBBSC_CODER_QLFC_STATIC << 5); break;
|
||||
case LIBBSC_CODER_QLFC_ADAPTIVE: mode += (LIBBSC_CODER_QLFC_ADAPTIVE << 5); break;
|
||||
|
||||
default : return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
if (lzpMinLen != 0 || lzpHashSize != 0)
|
||||
{
|
||||
if (lzpMinLen < 4 || lzpMinLen > 255) return LIBBSC_BAD_PARAMETER;
|
||||
if (lzpHashSize < 10 || lzpHashSize > 28) return LIBBSC_BAD_PARAMETER;
|
||||
mode += (lzpMinLen << 8);
|
||||
mode += (lzpHashSize << 16);
|
||||
}
|
||||
if (n < 0 || n > 1073741824) return LIBBSC_BAD_PARAMETER;
|
||||
if (n <= LIBBSC_HEADER_SIZE)
|
||||
{
|
||||
return (LIBBSC_SKIP_DATA);
|
||||
}
|
||||
int lzSize = 0;
|
||||
if (mode != (mode & 0xff))
|
||||
{
|
||||
lzSize = bsc_lzp_compress(input, output, n, lzpHashSize, lzpMinLen, features);
|
||||
if (lzSize < LIBBSC_NO_ERROR || n - lzSize <= LIBBSC_HEADER_SIZE)
|
||||
{
|
||||
mode &= 0xff;
|
||||
}
|
||||
}
|
||||
if (mode == (mode & 0xff))
|
||||
{
|
||||
lzSize = n; memcpy(output, input, n);
|
||||
}
|
||||
|
||||
if (lzSize <= LIBBSC_HEADER_SIZE)
|
||||
{
|
||||
blockSorter = LIBBSC_BLOCKSORTER_BWT;
|
||||
mode = (mode & 0xffffffe0) | LIBBSC_BLOCKSORTER_BWT;
|
||||
}
|
||||
|
||||
int index = LIBBSC_BAD_PARAMETER; num_indexes = 0;
|
||||
switch (blockSorter)
|
||||
{
|
||||
case LIBBSC_BLOCKSORTER_BWT : index = bsc_bwt_encode(output, lzSize, &num_indexes, indexes, features); break;
|
||||
|
||||
default : return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
if (n < 64 * 1024) num_indexes = 0;
|
||||
|
||||
if (index < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
int coded = 1;
|
||||
int result = bsc_coder_compress(output, input, lzSize, coder, features);
|
||||
if ((result < LIBBSC_NO_ERROR) || (result + 1 + 4 * num_indexes >= n)) {
|
||||
coded = 0;
|
||||
result = lzSize;
|
||||
/*
|
||||
* Original input has been destroyed so we have to decode BWT.
|
||||
*/
|
||||
bsc_bwt_decode(output, lzSize, index, num_indexes, indexes, features);
|
||||
coded = 0;
|
||||
if (mode == (mode & 0xff)) {
|
||||
/*
|
||||
* No coding, no LZP. No compression whatsoever.
|
||||
*/
|
||||
memcpy(input, output, n);
|
||||
return (LIBBSC_SKIP_DATA);
|
||||
}
|
||||
/*
|
||||
* At least LZP is successful.
|
||||
*/
|
||||
memmove(output + LIBBSC_HEADER_SIZE, output, result);
|
||||
} else {
|
||||
memcpy(output + LIBBSC_HEADER_SIZE, input, result);
|
||||
}
|
||||
if (coded > 0) {
|
||||
if (num_indexes > 0)
|
||||
{
|
||||
memcpy(output + LIBBSC_HEADER_SIZE + result, indexes, 4 * num_indexes);
|
||||
}
|
||||
output[LIBBSC_HEADER_SIZE + result + 4 * num_indexes] = num_indexes;
|
||||
result += 1 + 4 * num_indexes;
|
||||
}
|
||||
*(int *)(output + 0) = result + LIBBSC_HEADER_SIZE;
|
||||
*(int *)(output + 4) = n;
|
||||
*(int *)(output + 8) = mode;
|
||||
*(int *)(output + 12) = index;
|
||||
*(int *)(output + 16) = features;
|
||||
*(int *)(output + 20) = coded;
|
||||
*(int *)(output + 24) = bsc_adler32(output, 24, features);
|
||||
return result + LIBBSC_HEADER_SIZE;
|
||||
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
int bsc_block_info(unsigned char * blockHeader, int headerSize, int * pBlockSize, int * pDataSize, int features)
|
||||
{
|
||||
if (headerSize < LIBBSC_HEADER_SIZE)
|
||||
{
|
||||
return LIBBSC_UNEXPECTED_EOB;
|
||||
}
|
||||
|
||||
if (*(unsigned int *)(blockHeader + 24) != bsc_adler32(blockHeader, 24, features))
|
||||
{
|
||||
return LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
int blockSize = *(int *)(blockHeader + 0);
|
||||
int dataSize = *(int *)(blockHeader + 4);
|
||||
int mode = *(int *)(blockHeader + 8);
|
||||
int index = *(int *)(blockHeader + 12);
|
||||
|
||||
int lzpHashSize = (mode >> 16) & 0xff;
|
||||
int lzpMinLen = (mode >> 8) & 0xff;
|
||||
int coder = (mode >> 5) & 0x7;
|
||||
int blockSorter = (mode >> 0) & 0x1f;
|
||||
|
||||
int test_mode = 0;
|
||||
|
||||
switch (blockSorter)
|
||||
{
|
||||
case LIBBSC_BLOCKSORTER_BWT : test_mode = LIBBSC_BLOCKSORTER_BWT; break;
|
||||
|
||||
default : if (blockSorter > 0) return LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
switch (coder)
|
||||
{
|
||||
case LIBBSC_CODER_QLFC_STATIC: test_mode += (LIBBSC_CODER_QLFC_STATIC << 5); break;
|
||||
case LIBBSC_CODER_QLFC_ADAPTIVE: test_mode += (LIBBSC_CODER_QLFC_ADAPTIVE << 5); break;
|
||||
|
||||
default : return LIBBSC_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
if (lzpMinLen != 0 || lzpHashSize != 0)
|
||||
{
|
||||
if (lzpMinLen < 4 || lzpMinLen > 255) return LIBBSC_DATA_CORRUPT;
|
||||
if (lzpHashSize < 10 || lzpHashSize > 28) return LIBBSC_DATA_CORRUPT;
|
||||
test_mode += (lzpMinLen << 8);
|
||||
test_mode += (lzpHashSize << 16);
|
||||
}
|
||||
|
||||
if (test_mode != mode)
|
||||
{
|
||||
return LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
if (blockSize < LIBBSC_HEADER_SIZE || blockSize > LIBBSC_HEADER_SIZE + dataSize)
|
||||
{
|
||||
return LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
if (index < 0 || index > dataSize)
|
||||
{
|
||||
return LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
if (pBlockSize != NULL) *pBlockSize = blockSize;
|
||||
if (pDataSize != NULL) *pDataSize = dataSize;
|
||||
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
int bsc_decompress_inplace(unsigned char * data, int inputSize, int outputSize, int features)
|
||||
{
|
||||
int indexes[256];
|
||||
unsigned char num_indexes;
|
||||
|
||||
int blockSize = 0, dataSize = 0;
|
||||
|
||||
int info = bsc_block_info(data, inputSize, &blockSize, &dataSize, features);
|
||||
if (info != LIBBSC_NO_ERROR)
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
if (inputSize < blockSize || outputSize < dataSize)
|
||||
{
|
||||
return LIBBSC_UNEXPECTED_EOB;
|
||||
}
|
||||
|
||||
if (*(unsigned int *)(data + 20) != bsc_adler32(data + LIBBSC_HEADER_SIZE, blockSize - LIBBSC_HEADER_SIZE, features))
|
||||
{
|
||||
return LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
int mode = *(int *)(data + 8);
|
||||
if (mode == 0)
|
||||
{
|
||||
memmove(data, data + LIBBSC_HEADER_SIZE, dataSize);
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
int index = *(int *)(data + 12);
|
||||
unsigned int adler32_data = *(int *)(data + 16);
|
||||
|
||||
num_indexes = data[blockSize - 1];
|
||||
if (num_indexes > 0)
|
||||
{
|
||||
memcpy(indexes, data + blockSize - 1 - 4 * num_indexes, 4 * num_indexes);
|
||||
}
|
||||
|
||||
int lzpHashSize = (mode >> 16) & 0xff;
|
||||
int lzpMinLen = (mode >> 8) & 0xff;
|
||||
int coder = (mode >> 5) & 0x7;
|
||||
int blockSorter = (mode >> 0) & 0x1f;
|
||||
|
||||
int lzSize = LIBBSC_NO_ERROR;
|
||||
{
|
||||
unsigned char * buffer = (unsigned char *)bsc_malloc(blockSize);
|
||||
if (buffer == NULL) return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
|
||||
memcpy(buffer, data, blockSize);
|
||||
|
||||
lzSize = bsc_coder_decompress(buffer + LIBBSC_HEADER_SIZE, data, coder, features);
|
||||
|
||||
bsc_free(buffer);
|
||||
}
|
||||
if (lzSize < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return lzSize;
|
||||
}
|
||||
|
||||
int result;
|
||||
switch (blockSorter)
|
||||
{
|
||||
case LIBBSC_BLOCKSORTER_BWT : result = bsc_bwt_decode(data, lzSize, index, num_indexes, indexes, features); break;
|
||||
|
||||
default : return LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
if (result < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (mode != (mode & 0xff))
|
||||
{
|
||||
if (unsigned char * buffer = (unsigned char *)bsc_malloc(lzSize))
|
||||
{
|
||||
memcpy(buffer, data, lzSize);
|
||||
result = bsc_lzp_decompress(buffer, data, lzSize, lzpHashSize, lzpMinLen, features);
|
||||
bsc_free(buffer);
|
||||
if (result < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return result == dataSize ? (adler32_data == bsc_adler32(data, dataSize, features) ? LIBBSC_NO_ERROR : LIBBSC_DATA_CORRUPT) : LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
return lzSize == dataSize ? (adler32_data == bsc_adler32(data, dataSize, features) ? LIBBSC_NO_ERROR : LIBBSC_DATA_CORRUPT) : LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
int bsc_decompress(unsigned char * input, int inputSize, unsigned char * output, int outputSize, int features)
|
||||
{
|
||||
int indexes[256];
|
||||
unsigned char num_indexes;
|
||||
|
||||
if (input == output)
|
||||
{
|
||||
return bsc_decompress_inplace(output, inputSize, outputSize, features);
|
||||
}
|
||||
|
||||
int blockSize = 0, dataSize = 0;
|
||||
|
||||
int info = bsc_block_info(input, inputSize, &blockSize, &dataSize, features);
|
||||
if (info != LIBBSC_NO_ERROR)
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
if (inputSize < blockSize || outputSize < dataSize)
|
||||
{
|
||||
return LIBBSC_UNEXPECTED_EOB;
|
||||
}
|
||||
|
||||
int coded = *(int *)(input + 20);
|
||||
int mode = *(int *)(input + 8);
|
||||
if (mode == 0)
|
||||
{
|
||||
memcpy(output, input + LIBBSC_HEADER_SIZE, dataSize);
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
int index = *(int *)(input + 12);
|
||||
int features_stored = *(int *)(input + 16);
|
||||
if (features_stored != features) return LIBBSC_DATA_CORRUPT;
|
||||
|
||||
num_indexes = input[blockSize - 1];
|
||||
if (num_indexes > 0)
|
||||
{
|
||||
memcpy(indexes, input + blockSize - 1 - 4 * num_indexes, 4 * num_indexes);
|
||||
}
|
||||
|
||||
int lzpHashSize = (mode >> 16) & 0xff;
|
||||
int lzpMinLen = (mode >> 8) & 0xff;
|
||||
int coder = (mode >> 5) & 0x7;
|
||||
int blockSorter = (mode >> 0) & 0x1f;
|
||||
int result, lzSize;
|
||||
|
||||
if (coded) {
|
||||
lzSize = bsc_coder_decompress(input + LIBBSC_HEADER_SIZE, output, coder, features);
|
||||
if (lzSize < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return lzSize;
|
||||
}
|
||||
|
||||
switch (blockSorter)
|
||||
{
|
||||
case LIBBSC_BLOCKSORTER_BWT : result = bsc_bwt_decode(output, lzSize, index, num_indexes, indexes, features); break;
|
||||
|
||||
default : return LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
if (result < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
memcpy(output, input + LIBBSC_HEADER_SIZE, blockSize - LIBBSC_HEADER_SIZE);
|
||||
lzSize = blockSize - LIBBSC_HEADER_SIZE;
|
||||
}
|
||||
|
||||
result = lzSize;
|
||||
if (mode != (mode & 0xff))
|
||||
{
|
||||
memcpy(input, output, lzSize);
|
||||
result = bsc_lzp_decompress(input, output, lzSize, lzpHashSize, lzpMinLen, features);
|
||||
if (result < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return result == dataSize ? LIBBSC_NO_ERROR : LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
return result == dataSize ? LIBBSC_NO_ERROR : LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compatibility to decompress older archive versions.
|
||||
*/
|
||||
int bsc_decompress_old(const unsigned char * input, int inputSize, unsigned char * output, int outputSize, int features)
|
||||
{
|
||||
int indexes[256];
|
||||
unsigned char num_indexes;
|
||||
|
||||
if (input == output)
|
||||
{
|
||||
return bsc_decompress_inplace(output, inputSize, outputSize, features);
|
||||
}
|
||||
|
||||
int blockSize = 0, dataSize = 0;
|
||||
|
||||
int info = bsc_block_info((unsigned char *)input, inputSize, &blockSize, &dataSize, features);
|
||||
if (info != LIBBSC_NO_ERROR)
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
if (inputSize < blockSize || outputSize < dataSize)
|
||||
{
|
||||
return LIBBSC_UNEXPECTED_EOB;
|
||||
}
|
||||
|
||||
if (*(unsigned int *)(input + 20) != bsc_adler32(input + LIBBSC_HEADER_SIZE, blockSize - LIBBSC_HEADER_SIZE, features))
|
||||
{
|
||||
return LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
int mode = *(int *)(input + 8);
|
||||
if (mode == 0)
|
||||
{
|
||||
memcpy(output, input + LIBBSC_HEADER_SIZE, dataSize);
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
int index = *(int *)(input + 12);
|
||||
unsigned int adler32_data = *(int *)(input + 16);
|
||||
|
||||
num_indexes = input[blockSize - 1];
|
||||
if (num_indexes > 0)
|
||||
{
|
||||
memcpy(indexes, input + blockSize - 1 - 4 * num_indexes, 4 * num_indexes);
|
||||
}
|
||||
|
||||
int lzpHashSize = (mode >> 16) & 0xff;
|
||||
int lzpMinLen = (mode >> 8) & 0xff;
|
||||
int coder = (mode >> 5) & 0x7;
|
||||
int blockSorter = (mode >> 0) & 0x1f;
|
||||
|
||||
int lzSize = bsc_coder_decompress(input + LIBBSC_HEADER_SIZE, output, coder, features);
|
||||
if (lzSize < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return lzSize;
|
||||
}
|
||||
|
||||
int result;
|
||||
switch (blockSorter)
|
||||
{
|
||||
case LIBBSC_BLOCKSORTER_BWT : result = bsc_bwt_decode(output, lzSize, index, num_indexes, indexes, features); break;
|
||||
|
||||
default : return LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
if (result < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (mode != (mode & 0xff))
|
||||
{
|
||||
if (unsigned char * buffer = (unsigned char *)bsc_malloc(lzSize))
|
||||
{
|
||||
memcpy(buffer, output, lzSize);
|
||||
result = bsc_lzp_decompress(buffer, output, lzSize, lzpHashSize, lzpMinLen, features);
|
||||
bsc_free(buffer);
|
||||
if (result < LIBBSC_NO_ERROR)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return result == dataSize ? (adler32_data == bsc_adler32(output, dataSize, features) ? LIBBSC_NO_ERROR : LIBBSC_DATA_CORRUPT) : LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
return lzSize == dataSize ? (adler32_data == bsc_adler32(output, dataSize, features) ? LIBBSC_NO_ERROR : LIBBSC_DATA_CORRUPT) : LIBBSC_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*/
|
||||
/* End libbsc.cpp */
|
||||
/*-------------------------------------------------*/
|
426
bsc/libbsc/lzp/lzp.cpp
Normal file
426
bsc/libbsc/lzp/lzp.cpp
Normal file
|
@ -0,0 +1,426 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Lempel Ziv Prediction */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lzp.h"
|
||||
|
||||
#include "../platform/platform.h"
|
||||
#include "../libbsc.h"
|
||||
|
||||
#define LIBBSC_LZP_MATCH_FLAG 0xf2
|
||||
|
||||
static INLINE int bsc_lzp_num_blocks(int n)
|
||||
{
|
||||
if (n < 256 * 1024) return 1;
|
||||
if (n < 4 * 1024 * 1024) return 2;
|
||||
if (n < 16 * 1024 * 1024) return 4;
|
||||
|
||||
return 8;
|
||||
}
|
||||
|
||||
int bsc_lzp_encode_block(const unsigned char * input, const unsigned char * inputEnd, unsigned char * output, unsigned char * outputEnd, int hashSize, int minLen)
|
||||
{
|
||||
if (inputEnd - input < 16)
|
||||
{
|
||||
return LIBBSC_NOT_COMPRESSIBLE;
|
||||
}
|
||||
|
||||
if (int * lookup = (int *)bsc_zero_malloc((int)(1 << hashSize) * sizeof(int)))
|
||||
{
|
||||
unsigned int mask = (int)(1 << hashSize) - 1;
|
||||
const unsigned char * inputStart = input;
|
||||
const unsigned char * outputStart = output;
|
||||
const unsigned char * outputEOB = outputEnd - 4;
|
||||
|
||||
unsigned int context = 0;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
context = (context << 8) | (*output++ = *input++);
|
||||
}
|
||||
|
||||
const unsigned char * heuristic = input;
|
||||
const unsigned char * inputMinLenEnd = inputEnd - minLen - 8;
|
||||
while ((input < inputMinLenEnd) && (output < outputEOB))
|
||||
{
|
||||
unsigned int index = ((context >> 15) ^ context ^ (context >> 3)) & mask;
|
||||
int value = lookup[index]; lookup[index] = (int)(input - inputStart);
|
||||
if (value > 0)
|
||||
{
|
||||
const unsigned char * reference = inputStart + value;
|
||||
if ((*(unsigned int *)(input + minLen - 4) == *(unsigned int *)(reference + minLen - 4)) && (*(unsigned int *)(input) == *(unsigned int *)(reference)))
|
||||
{
|
||||
if ((heuristic > input) && (*(unsigned int *)heuristic != *(unsigned int *)(reference + (heuristic - input))))
|
||||
{
|
||||
goto LIBBSC_LZP_MATCH_NOT_FOUND;
|
||||
}
|
||||
|
||||
int len = 4;
|
||||
for (; input + len < inputMinLenEnd; len += 4)
|
||||
{
|
||||
if (*(unsigned int *)(input + len) != *(unsigned int *)(reference + len)) break;
|
||||
}
|
||||
if (len < minLen)
|
||||
{
|
||||
if (heuristic < input + len) heuristic = input + len;
|
||||
goto LIBBSC_LZP_MATCH_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (input[len] == reference[len]) len++;
|
||||
if (input[len] == reference[len]) len++;
|
||||
if (input[len] == reference[len]) len++;
|
||||
|
||||
input += len; context = input[-1] | (input[-2] << 8) | (input[-3] << 16) | (input[-4] << 24);
|
||||
|
||||
*output++ = LIBBSC_LZP_MATCH_FLAG;
|
||||
|
||||
len -= minLen; while (len >= 254) { len -= 254; *output++ = 254; if (output >= outputEOB) break; }
|
||||
|
||||
*output++ = (unsigned char)(len);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
LIBBSC_LZP_MATCH_NOT_FOUND:
|
||||
|
||||
unsigned char next = *output++ = *input++; context = (context << 8) | next;
|
||||
if (next == LIBBSC_LZP_MATCH_FLAG) *output++ = 255;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context = (context << 8) | (*output++ = *input++);
|
||||
}
|
||||
}
|
||||
|
||||
while ((input < inputEnd) && (output < outputEOB))
|
||||
{
|
||||
unsigned int index = ((context >> 15) ^ context ^ (context >> 3)) & mask;
|
||||
int value = lookup[index]; lookup[index] = (int)(input - inputStart);
|
||||
if (value > 0)
|
||||
{
|
||||
unsigned char next = *output++ = *input++; context = (context << 8) | next;
|
||||
if (next == LIBBSC_LZP_MATCH_FLAG) *output++ = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
context = (context << 8) | (*output++ = *input++);
|
||||
}
|
||||
}
|
||||
|
||||
bsc_free(lookup);
|
||||
|
||||
return (output >= outputEOB) ? LIBBSC_NOT_COMPRESSIBLE : (int)(output - outputStart);
|
||||
}
|
||||
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
int bsc_lzp_decode_block(const unsigned char * input, const unsigned char * inputEnd, unsigned char * output, int hashSize, int minLen)
|
||||
{
|
||||
if (inputEnd - input < 4)
|
||||
{
|
||||
return LIBBSC_UNEXPECTED_EOB;
|
||||
}
|
||||
|
||||
if (int * lookup = (int *)bsc_zero_malloc((int)(1 << hashSize) * sizeof(int)))
|
||||
{
|
||||
unsigned int mask = (int)(1 << hashSize) - 1;
|
||||
const unsigned char * outputStart = output;
|
||||
|
||||
unsigned int context = 0;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
context = (context << 8) | (*output++ = *input++);
|
||||
}
|
||||
|
||||
while (input < inputEnd)
|
||||
{
|
||||
unsigned int index = ((context >> 15) ^ context ^ (context >> 3)) & mask;
|
||||
int value = lookup[index]; lookup[index] = (int)(output - outputStart);
|
||||
if (*input == LIBBSC_LZP_MATCH_FLAG && value > 0)
|
||||
{
|
||||
input++;
|
||||
if (*input != 255)
|
||||
{
|
||||
int len = minLen; while (true) { len += *input; if (*input++ != 254) break; }
|
||||
|
||||
const unsigned char * reference = outputStart + value;
|
||||
unsigned char * outputEnd = output + len;
|
||||
|
||||
if (output - reference < 4)
|
||||
{
|
||||
int offset[4] = {0, 3, 2, 3};
|
||||
|
||||
*output++ = *reference++;
|
||||
*output++ = *reference++;
|
||||
*output++ = *reference++;
|
||||
*output++ = *reference++;
|
||||
|
||||
reference -= offset[output - reference];
|
||||
}
|
||||
|
||||
while (output < outputEnd) { *(unsigned int *)output = *(unsigned int*)reference; output += 4; reference += 4; }
|
||||
|
||||
output = outputEnd; context = output[-1] | (output[-2] << 8) | (output[-3] << 16) | (output[-4] << 24);
|
||||
}
|
||||
else
|
||||
{
|
||||
input++; context = (context << 8) | (*output++ = LIBBSC_LZP_MATCH_FLAG);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context = (context << 8) | (*output++ = *input++);
|
||||
}
|
||||
}
|
||||
|
||||
bsc_free(lookup);
|
||||
|
||||
return (int)(output - outputStart);
|
||||
}
|
||||
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
int bsc_lzp_compress_serial(const unsigned char * input, unsigned char * output, int n, int hashSize, int minLen)
|
||||
{
|
||||
if (bsc_lzp_num_blocks(n) == 1)
|
||||
{
|
||||
int result = bsc_lzp_encode_block(input, input + n, output + 1, output + n - 1, hashSize, minLen);
|
||||
if (result >= LIBBSC_NO_ERROR) result = (output[0] = 1, result + 1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int nBlocks = bsc_lzp_num_blocks(n);
|
||||
int chunkSize = n / nBlocks;
|
||||
int outputPtr = 1 + 8 * nBlocks;
|
||||
|
||||
output[0] = nBlocks;
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int inputStart = blockId * chunkSize;
|
||||
int inputSize = blockId != nBlocks - 1 ? chunkSize : n - inputStart;
|
||||
int outputSize = inputSize; if (outputSize > n - outputPtr) outputSize = n - outputPtr;
|
||||
|
||||
int result = bsc_lzp_encode_block(input + inputStart, input + inputStart + inputSize, output + outputPtr, output + outputPtr + outputSize, hashSize, minLen);
|
||||
if (result < LIBBSC_NO_ERROR)
|
||||
{
|
||||
if (outputPtr + inputSize >= n) return LIBBSC_NOT_COMPRESSIBLE;
|
||||
result = inputSize; memcpy(output + outputPtr, input + inputStart, inputSize);
|
||||
}
|
||||
|
||||
*(int *)(output + 1 + 8 * blockId + 0) = inputSize;
|
||||
*(int *)(output + 1 + 8 * blockId + 4) = result;
|
||||
|
||||
outputPtr += result;
|
||||
}
|
||||
|
||||
return outputPtr;
|
||||
}
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
int bsc_lzp_compress_parallel(const unsigned char * input, unsigned char * output, int n, int hashSize, int minLen)
|
||||
{
|
||||
if (unsigned char * buffer = (unsigned char *)bsc_malloc(n * sizeof(unsigned char)))
|
||||
{
|
||||
int compressionResult[ALPHABET_SIZE];
|
||||
|
||||
int nBlocks = bsc_lzp_num_blocks(n);
|
||||
int result = LIBBSC_NO_ERROR;
|
||||
int chunkSize = n / nBlocks;
|
||||
|
||||
int numThreads = omp_get_max_threads();
|
||||
if (numThreads > nBlocks) numThreads = nBlocks;
|
||||
|
||||
output[0] = nBlocks;
|
||||
#pragma omp parallel num_threads(numThreads) if(numThreads > 1)
|
||||
{
|
||||
if (omp_get_num_threads() == 1)
|
||||
{
|
||||
result = bsc_lzp_compress_serial(input, output, n, hashSize, minLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma omp for schedule(dynamic)
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int blockStart = blockId * chunkSize;
|
||||
int blockSize = blockId != nBlocks - 1 ? chunkSize : n - blockStart;
|
||||
|
||||
compressionResult[blockId] = bsc_lzp_encode_block(input + blockStart, input + blockStart + blockSize, buffer + blockStart, buffer + blockStart + blockSize, hashSize, minLen);
|
||||
if (compressionResult[blockId] < LIBBSC_NO_ERROR) compressionResult[blockId] = blockSize;
|
||||
|
||||
*(int *)(output + 1 + 8 * blockId + 0) = blockSize;
|
||||
*(int *)(output + 1 + 8 * blockId + 4) = compressionResult[blockId];
|
||||
}
|
||||
|
||||
#pragma omp single
|
||||
{
|
||||
result = 1 + 8 * nBlocks;
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
result += compressionResult[blockId];
|
||||
}
|
||||
|
||||
if (result >= n) result = LIBBSC_NOT_COMPRESSIBLE;
|
||||
}
|
||||
|
||||
if (result >= LIBBSC_NO_ERROR)
|
||||
{
|
||||
#pragma omp for schedule(dynamic)
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int blockStart = blockId * chunkSize;
|
||||
int blockSize = blockId != nBlocks - 1 ? chunkSize : n - blockStart;
|
||||
|
||||
int outputPtr = 1 + 8 * nBlocks;
|
||||
for (int p = 0; p < blockId; ++p) outputPtr += compressionResult[p];
|
||||
|
||||
if (compressionResult[blockId] != blockSize)
|
||||
{
|
||||
memcpy(output + outputPtr, buffer + blockStart, compressionResult[blockId]);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(output + outputPtr, input + blockStart, compressionResult[blockId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bsc_free(buffer);
|
||||
|
||||
return result;
|
||||
}
|
||||
return LIBBSC_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int bsc_lzp_compress(const unsigned char * input, unsigned char * output, int n, int hashSize, int minLen, int features)
|
||||
{
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
if ((bsc_lzp_num_blocks(n) != 1) && (features & LIBBSC_FEATURE_MULTITHREADING))
|
||||
{
|
||||
return bsc_lzp_compress_parallel(input, output, n, hashSize, minLen);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return bsc_lzp_compress_serial(input, output, n, hashSize, minLen);
|
||||
}
|
||||
|
||||
int bsc_lzp_decompress(const unsigned char * input, unsigned char * output, int n, int hashSize, int minLen, int features)
|
||||
{
|
||||
int nBlocks = input[0];
|
||||
|
||||
if (nBlocks == 1)
|
||||
{
|
||||
return bsc_lzp_decode_block(input + 1, input + n, output, hashSize, minLen);
|
||||
}
|
||||
|
||||
int decompressionResult[ALPHABET_SIZE];
|
||||
|
||||
#ifdef LIBBSC_OPENMP
|
||||
|
||||
if (features & LIBBSC_FEATURE_MULTITHREADING)
|
||||
{
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int inputPtr = 0; for (int p = 0; p < blockId; ++p) inputPtr += *(int *)(input + 1 + 8 * p + 4);
|
||||
int outputPtr = 0; for (int p = 0; p < blockId; ++p) outputPtr += *(int *)(input + 1 + 8 * p + 0);
|
||||
|
||||
inputPtr += 1 + 8 * nBlocks;
|
||||
|
||||
int inputSize = *(int *)(input + 1 + 8 * blockId + 4);
|
||||
int outputSize = *(int *)(input + 1 + 8 * blockId + 0);
|
||||
|
||||
if (inputSize != outputSize)
|
||||
{
|
||||
decompressionResult[blockId] = bsc_lzp_decode_block(input + inputPtr, input + inputPtr + inputSize, output + outputPtr, hashSize, minLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
decompressionResult[blockId] = inputSize; memcpy(output + outputPtr, input + inputPtr, inputSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
int inputPtr = 0; for (int p = 0; p < blockId; ++p) inputPtr += *(int *)(input + 1 + 8 * p + 4);
|
||||
int outputPtr = 0; for (int p = 0; p < blockId; ++p) outputPtr += *(int *)(input + 1 + 8 * p + 0);
|
||||
|
||||
inputPtr += 1 + 8 * nBlocks;
|
||||
|
||||
int inputSize = *(int *)(input + 1 + 8 * blockId + 4);
|
||||
int outputSize = *(int *)(input + 1 + 8 * blockId + 0);
|
||||
|
||||
if (inputSize != outputSize)
|
||||
{
|
||||
decompressionResult[blockId] = bsc_lzp_decode_block(input + inputPtr, input + inputPtr + inputSize, output + outputPtr, hashSize, minLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
decompressionResult[blockId] = inputSize; memcpy(output + outputPtr, input + inputPtr, inputSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int dataSize = 0, result = LIBBSC_NO_ERROR;
|
||||
for (int blockId = 0; blockId < nBlocks; ++blockId)
|
||||
{
|
||||
if (decompressionResult[blockId] < LIBBSC_NO_ERROR) result = decompressionResult[blockId];
|
||||
dataSize += decompressionResult[blockId];
|
||||
}
|
||||
|
||||
return (result == LIBBSC_NO_ERROR) ? dataSize : result;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End lzp.cpp */
|
||||
/*-----------------------------------------------------------*/
|
74
bsc/libbsc/lzp/lzp.h
Normal file
74
bsc/libbsc/lzp/lzp.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Interface to Lempel Ziv Prediction functions */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_LZP_H
|
||||
#define _LIBBSC_LZP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Preprocess a memory block by LZP algorithm.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param output - the output memory block of n bytes.
|
||||
* @param n - the length of the input/output memory blocks.
|
||||
* @param hashSize - the hash table size.
|
||||
* @param minLen - the minimum match length.
|
||||
* @param features - the set of additional features.
|
||||
* @return The length of preprocessed memory block if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_lzp_compress(const unsigned char * input, unsigned char * output, int n, int hashSize, int minLen, int features);
|
||||
|
||||
/**
|
||||
* Reconstructs the original memory block after LZP algorithm.
|
||||
* @param input - the input memory block of n bytes.
|
||||
* @param output - the output memory block.
|
||||
* @param n - the length of the input memory block.
|
||||
* @param hashSize - the hash table size.
|
||||
* @param minLen - the minimum match length.
|
||||
* @param features - the set of additional features.
|
||||
* @return The length of original memory block if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_lzp_decompress(const unsigned char * input, unsigned char * output, int n, int hashSize, int minLen, int features);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End lzp.h */
|
||||
/*-----------------------------------------------------------*/
|
135
bsc/libbsc/platform/platform.cpp
Normal file
135
bsc/libbsc/platform/platform.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Platform specific functions and constants */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "../libbsc.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
SIZE_T g_LargePageSize = 0;
|
||||
#endif
|
||||
|
||||
int bsc_platform_init(int features)
|
||||
{
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
if (features & LIBBSC_FEATURE_LARGEPAGES)
|
||||
{
|
||||
HANDLE hToken = 0;
|
||||
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
|
||||
{
|
||||
LUID luid;
|
||||
if (LookupPrivilegeValue(NULL, TEXT("SeLockMemoryPrivilege"), &luid))
|
||||
{
|
||||
TOKEN_PRIVILEGES tp;
|
||||
|
||||
tp.PrivilegeCount = 1;
|
||||
tp.Privileges[0].Luid = luid;
|
||||
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
|
||||
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), 0, 0);
|
||||
}
|
||||
|
||||
CloseHandle(hToken);
|
||||
}
|
||||
|
||||
{
|
||||
if (HMODULE hKernel = GetModuleHandle(TEXT("kernel32.dll")))
|
||||
{
|
||||
typedef SIZE_T (WINAPI * GetLargePageMinimumProcT)();
|
||||
|
||||
GetLargePageMinimumProcT largePageMinimumProc = (GetLargePageMinimumProcT)GetProcAddress(hKernel, "GetLargePageMinimum");
|
||||
if (largePageMinimumProc != NULL)
|
||||
{
|
||||
SIZE_T largePageSize = largePageMinimumProc();
|
||||
|
||||
if ((largePageSize & (largePageSize - 1)) != 0) largePageSize = 0;
|
||||
|
||||
g_LargePageSize = largePageSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return LIBBSC_NO_ERROR;
|
||||
}
|
||||
|
||||
void * bsc_malloc(size_t size)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
if ((g_LargePageSize != 0) && (size >= 256 * 1024))
|
||||
{
|
||||
void * address = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
|
||||
if (address != NULL) return address;
|
||||
}
|
||||
return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
#else
|
||||
return malloc(size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void * bsc_zero_malloc(size_t size)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
if ((g_LargePageSize != 0) && (size >= 256 * 1024))
|
||||
{
|
||||
void * address = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
|
||||
if (address != NULL) return address;
|
||||
}
|
||||
return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
#else
|
||||
return calloc(1, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void bsc_free(void * address)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
VirtualFree(address, 0, MEM_RELEASE);
|
||||
#else
|
||||
free(address);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End platform.cpp */
|
||||
/*-----------------------------------------------------------*/
|
108
bsc/libbsc/platform/platform.h
Normal file
108
bsc/libbsc/platform/platform.h
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
/* Block Sorting, Lossless Data Compression Library. */
|
||||
/* Interface to platform specific functions and constants */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
|
||||
This file is a part of bsc and/or libbsc, a program and a library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
Copyright (c) 2009-2012 Ilya Grebnov <ilya.grebnov@gmail.com>
|
||||
|
||||
See file AUTHORS for a full list of contributors.
|
||||
|
||||
The bsc and libbsc is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The bsc and libbsc is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the bsc and libbsc. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
Please see the files COPYING and COPYING.LIB for full copyright information.
|
||||
|
||||
See also the bsc and libbsc web site:
|
||||
http://libbsc.com/ for more information.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _LIBBSC_PLATFORM_H
|
||||
#define _LIBBSC_PLATFORM_H
|
||||
|
||||
#if defined(_OPENMP) && defined(LIBBSC_OPENMP_SUPPORT)
|
||||
#include <omp.h>
|
||||
#define LIBBSC_OPENMP
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define INLINE __inline__
|
||||
#elif defined(_MSC_VER)
|
||||
#define INLINE __forceinline
|
||||
#elif defined(__IBMC__)
|
||||
#define INLINE _Inline
|
||||
#elif defined(__cplusplus)
|
||||
#define INLINE inline
|
||||
#else
|
||||
#define INLINE /* */
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
|
||||
#define RESTRICT __restrict__
|
||||
#elif defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)
|
||||
#define RESTRICT __restrict
|
||||
#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
#define RESTRICT __restrict
|
||||
#elif defined(__CUDACC__) && (CUDA_VERSION >= 3000)
|
||||
#define RESTRICT __restrict__
|
||||
#else
|
||||
#define RESTRICT /* */
|
||||
#endif
|
||||
|
||||
#define ALPHABET_SIZE (256)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* You should call this function before you call any of the other platform specific functions.
|
||||
* @param features - the set of additional features.
|
||||
* @return LIBBSC_NO_ERROR if no error occurred, error code otherwise.
|
||||
*/
|
||||
int bsc_platform_init(int features);
|
||||
|
||||
/**
|
||||
* Allocates memory blocks.
|
||||
* @param size - bytes to allocate.
|
||||
* @return a pointer to allocated space or NULL if there is insufficient memory available.
|
||||
*/
|
||||
void * bsc_malloc(size_t size);
|
||||
|
||||
/**
|
||||
* Allocates memory blocks and initializes all its bits to zero.
|
||||
* @param size - bytes to allocate.
|
||||
* @return a pointer to allocated space or NULL if there is insufficient memory available.
|
||||
*/
|
||||
void * bsc_zero_malloc(size_t size);
|
||||
|
||||
/**
|
||||
* Deallocates or frees a memory block.
|
||||
* @param address - previously allocated memory block to be freed.
|
||||
*/
|
||||
void bsc_free(void * address);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
/* End platform.h */
|
||||
/*-----------------------------------------------------------*/
|
111
bsc/makefile
Normal file
111
bsc/makefile
Normal file
|
@ -0,0 +1,111 @@
|
|||
SHELL = /bin/sh
|
||||
|
||||
CC = g++
|
||||
AR = ar
|
||||
RANLIB = ranlib
|
||||
|
||||
CFLAGS = -g -Wall -fPIC
|
||||
|
||||
# Sort Transform is patented by Michael Schindler under US patent 6,199,064.
|
||||
# However for research purposes this algorithm is included in this software.
|
||||
# So if you are of the type who should worry about this (making money) worry away.
|
||||
# The author shall have no liability with respect to the infringement of
|
||||
# copyrights, trade secrets or any patents by this software. In no event will
|
||||
# the author be liable for any lost revenue or profits or other special,
|
||||
# indirect and consequential damages.
|
||||
|
||||
# Sort Transform is disabled by default and can be enabled by defining the
|
||||
# preprocessor macro LIBBSC_SORT_TRANSFORM_SUPPORT at compile time.
|
||||
|
||||
#CFLAGS += -DLIBBSC_SORT_TRANSFORM_SUPPORT
|
||||
|
||||
# Comment out CFLAGS line below for compatability mode for 32bit file sizes
|
||||
# (less than 2GB) and systems that have compilers that treat int as 64bit
|
||||
# natively (ie: modern AIX)
|
||||
CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
|
||||
|
||||
# Comment out CFLAGS line below to disable optimizations
|
||||
CFLAGS += -O3 -fomit-frame-pointer -fstrict-aliasing
|
||||
|
||||
# Comment out CFLAGS line below to disable OpenMP optimizations
|
||||
CFLAGS += -fopenmp -DLIBBSC_OPENMP_SUPPORT
|
||||
|
||||
# Comment out CFLAGS line below to enable debug output
|
||||
CFLAGS += -DNDEBUG
|
||||
|
||||
# Where you want bsc installed when you do 'make install'
|
||||
PREFIX = /usr
|
||||
|
||||
OBJS = \
|
||||
adler32.o \
|
||||
divsufsort.o \
|
||||
bwt.o \
|
||||
coder.o \
|
||||
qlfc.o \
|
||||
qlfc_model.o \
|
||||
detectors.o \
|
||||
preprocessing.o \
|
||||
libbsc.o \
|
||||
lzp.o \
|
||||
platform.o \
|
||||
|
||||
all: libbsc.a bsc
|
||||
|
||||
bsc: libbsc.a bsc.cpp
|
||||
$(CC) $(CFLAGS) bsc.cpp -o bsc -L. -lbsc
|
||||
|
||||
libbsc.a: $(OBJS)
|
||||
rm -f libbsc.a
|
||||
$(AR) cq libbsc.a $(OBJS)
|
||||
@if ( test -f $(RANLIB) -o -f /usr/bin/ranlib -o \
|
||||
-f /bin/ranlib -o -f /usr/ccs/bin/ranlib ) ; then \
|
||||
echo $(RANLIB) libbsc.a ; \
|
||||
$(RANLIB) libbsc.a ; \
|
||||
fi
|
||||
|
||||
install: libbsc.a bsc
|
||||
if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi
|
||||
if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi
|
||||
if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi
|
||||
cp -f bsc $(PREFIX)/bin/bsc
|
||||
chmod a+x $(PREFIX)/bin/bsc
|
||||
cp -f libbsc/libbsc.h $(PREFIX)/include
|
||||
chmod a+r $(PREFIX)/include/libbsc.h
|
||||
cp -f libbsc.a $(PREFIX)/lib
|
||||
chmod a+r $(PREFIX)/lib/libbsc.a
|
||||
|
||||
clean:
|
||||
rm -f *.o libbsc.a bsc
|
||||
|
||||
adler32.o: libbsc/adler32/adler32.cpp
|
||||
$(CC) $(CFLAGS) -c libbsc/adler32/adler32.cpp
|
||||
|
||||
divsufsort.o: libbsc/bwt/divsufsort/divsufsort.c
|
||||
$(CC) $(CFLAGS) -c libbsc/bwt/divsufsort/divsufsort.c
|
||||
|
||||
bwt.o: libbsc/bwt/bwt.cpp
|
||||
$(CC) $(CFLAGS) -c libbsc/bwt/bwt.cpp
|
||||
|
||||
coder.o: libbsc/coder/coder.cpp
|
||||
$(CC) $(CFLAGS) -c libbsc/coder/coder.cpp
|
||||
|
||||
qlfc.o: libbsc/coder/qlfc/qlfc.cpp
|
||||
$(CC) $(CFLAGS) -c libbsc/coder/qlfc/qlfc.cpp
|
||||
|
||||
qlfc_model.o: libbsc/coder/qlfc/qlfc_model.cpp
|
||||
$(CC) $(CFLAGS) -c libbsc/coder/qlfc/qlfc_model.cpp
|
||||
|
||||
detectors.o: libbsc/filters/detectors.cpp
|
||||
$(CC) $(CFLAGS) -c libbsc/filters/detectors.cpp
|
||||
|
||||
preprocessing.o: libbsc/filters/preprocessing.cpp
|
||||
$(CC) $(CFLAGS) -c libbsc/filters/preprocessing.cpp
|
||||
|
||||
libbsc.o: libbsc/libbsc/libbsc.cpp
|
||||
$(CC) $(CFLAGS) -c libbsc/libbsc/libbsc.cpp
|
||||
|
||||
lzp.o: libbsc/lzp/lzp.cpp
|
||||
$(CC) $(CFLAGS) -c libbsc/lzp/lzp.cpp
|
||||
|
||||
platform.o: libbsc/platform/platform.cpp
|
||||
$(CC) $(CFLAGS) -c libbsc/platform/platform.cpp
|
21
config
21
config
|
@ -31,9 +31,9 @@ ${prog} [<options>]
|
|||
--enable-debug Enable debug mode compilation (default: disabled).
|
||||
--disable-allocator Disable use of internal memory allocator mechanism (default: enabled).
|
||||
--enable-debug-stats Enable printing of some verbose debug info (default: disabled).
|
||||
--with-libbsc=<path to libbsc source>
|
||||
Enable support for libbsc (See: libbsc.com). Full path to the libbsc
|
||||
source tree must be provided. It links the library statically.
|
||||
--with-libbsc=<path to libbsc source> (Default: Internal copy)
|
||||
Full path to external libbsc source tree can be provided. It links the
|
||||
library statically.
|
||||
--with-openssl=<path to OpenSSL installation tree> (Default: System)
|
||||
This defaults to the system's OpenSSL library. You can use this option
|
||||
if you want to use an alternate OpenSSL installation.
|
||||
|
@ -60,12 +60,12 @@ debug=0
|
|||
allocator=1
|
||||
debug_stats=0
|
||||
prefix=/usr
|
||||
libbsc_dir=
|
||||
libbsc_lib=
|
||||
libbsclflags=
|
||||
libbscwrapobj=
|
||||
libbscgenopt=
|
||||
libbsccppflags=
|
||||
libbsc_dir=./bsc
|
||||
libbsc_lib=${libbsc_dir}/libbsc.a
|
||||
libbsclflags='\$\(LIBBSCLFLAGS\)'
|
||||
libbscwrapobj='\$\(LIBBSCWRAPOBJ\)'
|
||||
libbscgenopt='\$\(LIBBSCGEN_OPT\)'
|
||||
libbsccppflags='\$\(LIBBSCCPPFLAGS\)'
|
||||
openssl_prefix=
|
||||
openssl_libdir=
|
||||
openssl_incdir=
|
||||
|
@ -162,7 +162,8 @@ do
|
|||
libbscgenopt='\$\(LIBBSCGEN_OPT\)'
|
||||
libbsccppflags='\$\(LIBBSCCPPFLAGS\)'
|
||||
else
|
||||
echo "Libbsc not found in ${path}, not enabling libbsc support.\n"
|
||||
echo "Libbsc not found in ${path}.\n"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--with-openssl=*)
|
||||
|
|
|
@ -40,6 +40,7 @@ struct libbsc_params {
|
|||
int lzpMinLen;
|
||||
int bscCoder;
|
||||
int features;
|
||||
int oldversion;
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -68,6 +69,13 @@ libbsc_stats(int show)
|
|||
{
|
||||
}
|
||||
|
||||
int
|
||||
libbsc_buf_extra(uint64_t buflen)
|
||||
{
|
||||
return (4096);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* BSC uses OpenMP where it does not control thread count
|
||||
* deterministically. We only use multithread capability in BSC
|
||||
|
@ -124,6 +132,10 @@ libbsc_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
|||
bscdat->lzpMinLen = 200;
|
||||
bscdat->bscCoder = LIBBSC_CODER_QLFC_ADAPTIVE;
|
||||
}
|
||||
|
||||
if (file_version < 9) {
|
||||
bscdat->oldversion = 1;
|
||||
}
|
||||
*data = bscdat;
|
||||
rv = bsc_init(bscdat->features);
|
||||
if (rv != LIBBSC_NO_ERROR) {
|
||||
|
@ -176,7 +188,10 @@ libbsc_decompress(void *src, uint64_t srclen, void *dst, uint64_t *dstlen,
|
|||
int rv;
|
||||
struct libbsc_params *bscdat = (struct libbsc_params *)data;
|
||||
|
||||
rv = bsc_decompress(src, srclen, dst, *dstlen, bscdat->features);
|
||||
if (bscdat->oldversion)
|
||||
rv = bsc_decompress_old(src, srclen, dst, *dstlen, bscdat->features);
|
||||
else
|
||||
rv = bsc_decompress(src, srclen, dst, *dstlen, bscdat->features);
|
||||
if (rv != LIBBSC_NO_ERROR) {
|
||||
libbsc_err(rv);
|
||||
return (-1);
|
||||
|
|
|
@ -40,7 +40,7 @@ extern "C" {
|
|||
#define CHUNK_FLAG_SZ 1
|
||||
#define ALGO_SZ 8
|
||||
#define MIN_CHUNK 2048
|
||||
#define VERSION 8
|
||||
#define VERSION 9
|
||||
#define FLAG_DEDUP 1
|
||||
#define FLAG_DEDUP_FIXED 2
|
||||
#define FLAG_SINGLE_CHUNK 4
|
||||
|
|
Loading…
Reference in a new issue