a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Copyright (c) 2000-2007 Marc Alexander Lehmann <schmorp@schmorp.de>
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Redistribution and use in source and binary forms, with or without modifica-
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * tion, are permitted provided that the following conditions are met:
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * 1. Redistributions of source code must retain the above copyright notice,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * this list of conditions and the following disclaimer.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * 2. Redistributions in binary form must reproduce the above copyright
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * notice, this list of conditions and the following disclaimer in the
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * documentation and/or other materials provided with the distribution.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * OF THE POSSIBILITY OF SUCH DAMAGE.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Alternatively, the contents of this file may be used under the terms of
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * the GNU General Public License ("GPL") version 2 or any later version,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * in which case the provisions of the GPL are applicable instead of
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * the above. If you wish to allow the use of your version of this file
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * only under the terms of the GPL and not to allow others to use your
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * version of this file under the BSD license, indicate your decision
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * by deleting the provisions above and replace them with the notice
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * and other provisions required by the GPL. If you do not delete the
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * provisions above, a recipient may use your version of this file under
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * either the BSD or the GPL.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef LZFP_h
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#define LZFP_h
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#define STANDALONE 1 /* at the moment, this is ok. */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef STANDALONE
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# include "lzf.h"
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Size of hashtable is (1 << HLOG) * sizeof (char *)
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * decompression is independent of the hash table size
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * the difference between 15 and 14 is very small
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * for small blocks (and 14 is usually a bit faster).
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * For a low-memory/faster configuration, use HLOG == 13;
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * For best compression, use 15 or 16 (or more, up to 23).
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef HLOG
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# define HLOG 16
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Sacrifice very little compression quality in favour of compression speed.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * This gives almost the same compression as the default code, and is
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * (very roughly) 15% faster. This is the preferred mode of operation.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef VERY_FAST
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# define VERY_FAST 1
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Sacrifice some more compression quality in favour of compression speed.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * (roughly 1-2% worse compression for large blocks and
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * 9-10% for small, redundant, blocks and >>20% better speed in both cases)
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * In short: when in need for speed, enable this for binary data,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * possibly disable this for text data.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef ULTRA_FAST
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# define ULTRA_FAST 0
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Unconditionally aligning does not cost very much, so do it if unsure
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef STRICT_ALIGN
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# define STRICT_ALIGN !(defined(__i386) || defined (__amd64))
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * You may choose to pre-set the hash table (might be faster on some
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * modern cpus and large (>>64k) blocks, and also makes compression
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * deterministic/repeatable when the configuration otherwise is the same).
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef INIT_HTAB
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# define INIT_HTAB 0
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Avoid assigning values to errno variable? for some embedding purposes
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * (linux kernel for example), this is neccessary. NOTE: this breaks
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * the documentation in lzf.h.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef AVOID_ERRNO
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# define AVOID_ERRNO 0
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Wether to pass the LZF_STATE variable as argument, or allocate it
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * on the stack. For small-stack environments, define this to 1.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * NOTE: this breaks the prototype in lzf.h.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef LZF_STATE_ARG
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# define LZF_STATE_ARG 0
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Wether to add extra checks for input validity in lzf_decompress
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * and return EINVAL if the input stream has been corrupted. This
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * only shields against overflowing the input buffer and will not
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * detect most corrupted streams.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * This check is not normally noticable on modern hardware
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * (<1% slowdown), but might slow down older cpus considerably.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef CHECK_INPUT
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# define CHECK_INPUT 1
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*****************************************************************************/
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/* nothing should be changed below */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsynctypedef unsigned char u8;
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsynctypedef const u8 *LZF_STATE[1 << (HLOG)];
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#if !STRICT_ALIGN
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/* for unaligned accesses we need a 16 bit datatype. */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# include <limits.h>
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# if USHRT_MAX == 65535
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync typedef unsigned short u16;
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# elif UINT_MAX == 65535
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync typedef unsigned int u16;
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# else
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# undef STRICT_ALIGN
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# define STRICT_ALIGN 1
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#if ULTRA_FAST
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# if defined(VERY_FAST)
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# undef VERY_FAST
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#if INIT_HTAB
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# ifdef __cplusplus
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# include <cstring>
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# else
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# include <string.h>
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync# endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync