Back to home page

Redis cross reference

 
 

    


0001 /*
0002  * Copyright (c) 2000-2007 Marc Alexander Lehmann <schmorp@schmorp.de>
0003  * 
0004  * Redistribution and use in source and binary forms, with or without modifica-
0005  * tion, are permitted provided that the following conditions are met:
0006  * 
0007  *   1.  Redistributions of source code must retain the above copyright notice,
0008  *       this list of conditions and the following disclaimer.
0009  * 
0010  *   2.  Redistributions in binary form must reproduce the above copyright
0011  *       notice, this list of conditions and the following disclaimer in the
0012  *       documentation and/or other materials provided with the distribution.
0013  * 
0014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
0015  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
0016  * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
0017  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
0018  * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0019  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
0020  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
0021  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
0022  * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
0023  * OF THE POSSIBILITY OF SUCH DAMAGE.
0024  *
0025  * Alternatively, the contents of this file may be used under the terms of
0026  * the GNU General Public License ("GPL") version 2 or any later version,
0027  * in which case the provisions of the GPL are applicable instead of
0028  * the above. If you wish to allow the use of your version of this file
0029  * only under the terms of the GPL and not to allow others to use your
0030  * version of this file under the BSD license, indicate your decision
0031  * by deleting the provisions above and replace them with the notice
0032  * and other provisions required by the GPL. If you do not delete the
0033  * provisions above, a recipient may use your version of this file under
0034  * either the BSD or the GPL.
0035  */
0036 
0037 #ifndef LZFP_h
0038 #define LZFP_h
0039 
0040 #define STANDALONE 1 /* at the moment, this is ok. */
0041 
0042 #ifndef STANDALONE
0043 # include "lzf.h"
0044 #endif
0045 
0046 /*
0047  * Size of hashtable is (1 << HLOG) * sizeof (char *)
0048  * decompression is independent of the hash table size
0049  * the difference between 15 and 14 is very small
0050  * for small blocks (and 14 is usually a bit faster).
0051  * For a low-memory/faster configuration, use HLOG == 13;
0052  * For best compression, use 15 or 16 (or more, up to 23).
0053  */
0054 #ifndef HLOG
0055 # define HLOG 16
0056 #endif
0057 
0058 /*
0059  * Sacrifice very little compression quality in favour of compression speed.
0060  * This gives almost the same compression as the default code, and is
0061  * (very roughly) 15% faster. This is the preferred mode of operation.
0062  */
0063 #ifndef VERY_FAST
0064 # define VERY_FAST 1
0065 #endif
0066 
0067 /*
0068  * Sacrifice some more compression quality in favour of compression speed.
0069  * (roughly 1-2% worse compression for large blocks and
0070  * 9-10% for small, redundant, blocks and >>20% better speed in both cases)
0071  * In short: when in need for speed, enable this for binary data,
0072  * possibly disable this for text data.
0073  */
0074 #ifndef ULTRA_FAST
0075 # define ULTRA_FAST 0
0076 #endif
0077 
0078 /*
0079  * Unconditionally aligning does not cost very much, so do it if unsure
0080  */
0081 #ifndef STRICT_ALIGN
0082 # define STRICT_ALIGN !(defined(__i386) || defined (__amd64))
0083 #endif
0084 
0085 /*
0086  * You may choose to pre-set the hash table (might be faster on some
0087  * modern cpus and large (>>64k) blocks, and also makes compression
0088  * deterministic/repeatable when the configuration otherwise is the same).
0089  */
0090 #ifndef INIT_HTAB
0091 # define INIT_HTAB 0
0092 #endif
0093 
0094 /*
0095  * Avoid assigning values to errno variable? for some embedding purposes
0096  * (linux kernel for example), this is necessary. NOTE: this breaks
0097  * the documentation in lzf.h.
0098  */
0099 #ifndef AVOID_ERRNO
0100 # define AVOID_ERRNO 0
0101 #endif
0102 
0103 /*
0104  * Whether to pass the LZF_STATE variable as argument, or allocate it
0105  * on the stack. For small-stack environments, define this to 1.
0106  * NOTE: this breaks the prototype in lzf.h.
0107  */
0108 #ifndef LZF_STATE_ARG
0109 # define LZF_STATE_ARG 0
0110 #endif
0111 
0112 /*
0113  * Whether to add extra checks for input validity in lzf_decompress
0114  * and return EINVAL if the input stream has been corrupted. This
0115  * only shields against overflowing the input buffer and will not
0116  * detect most corrupted streams.
0117  * This check is not normally noticeable on modern hardware
0118  * (<1% slowdown), but might slow down older cpus considerably.
0119  */
0120 #ifndef CHECK_INPUT
0121 # define CHECK_INPUT 1
0122 #endif
0123 
0124 /*****************************************************************************/
0125 /* nothing should be changed below */
0126 
0127 typedef unsigned char u8;
0128 
0129 typedef const u8 *LZF_STATE[1 << (HLOG)];
0130 
0131 #if !STRICT_ALIGN
0132 /* for unaligned accesses we need a 16 bit datatype. */
0133 # include <limits.h>
0134 # if USHRT_MAX == 65535
0135     typedef unsigned short u16;
0136 # elif UINT_MAX == 65535
0137     typedef unsigned int u16;
0138 # else
0139 #  undef STRICT_ALIGN
0140 #  define STRICT_ALIGN 1
0141 # endif
0142 #endif
0143 
0144 #if ULTRA_FAST
0145 # if defined(VERY_FAST)
0146 #  undef VERY_FAST
0147 # endif
0148 #endif
0149 
0150 #if INIT_HTAB
0151 # ifdef __cplusplus
0152 #  include <cstring>
0153 # else
0154 #  include <string.h>
0155 # endif
0156 #endif
0157 
0158 #endif
0159