Files
Sparkle/Vendor/bsdiff/sais.h
T
Zorg 616cc70775 Change bsdiff's suffix sort algorithm to sais. Fixes #132
Although #132 is marked as closed, the issue is still real. bsdiff can crash or hang when creating diffs on some files. In particular, bsdiff hangs/crashes in its recursive split function.

As you can see from:
http://stackoverflow.com/a/20305493/871119
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=409664

bsdiff 4.3 uses qsufsort for its suffix sorting algorithm, which has a bug causing the hanging/crashing. Our solution is to change the algorithm to use sais for suffix sorting:
https://sites.google.com/site/yuta256/sais

Notes:
*I had to change sais_index_type #define from int to off_t in sais.h/c and in some other places, to eliminate all warnings. Compiles cleanly with clang's -Weverything
*sais is claimed to be more efficient than other algorithms including qsufsort. If a more efficient (and stable) algorithm comes out, we may be able to swap it out in the future.
2015-04-05 15:01:49 -04:00

60 lines
2.0 KiB
C

/*
* sais.h for sais-lite
* Copyright (c) 2008-2010 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 _SAIS_H
#define _SAIS_H 1
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <sys/types.h>
#define sais_index_type off_t
/* find the suffix array SA of T[0..n-1]
use a working space (excluding T and SA) of at most 2n+O(lg n) */
sais_index_type
sais(const unsigned char *T, sais_index_type *SA, int n);
/* find the suffix array SA of T[0..n-1] in {0..k-1}^n
use a working space (excluding T and SA) of at most MAX(4k,2n) */
sais_index_type
sais_int(const int *T, sais_index_type *SA, int n, int k);
/* burrows-wheeler transform */
sais_index_type
sais_bwt(const unsigned char *T, unsigned char *U, sais_index_type *A, int n);
sais_index_type
sais_int_bwt(const sais_index_type *T, sais_index_type *U, sais_index_type *A, int n, int k);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* _SAIS_H */