Path: blob/main/contrib/libdivsufsort/include/divsufsort_private.h
39482 views
/*1* divsufsort_private.h for libdivsufsort2* Copyright (c) 2003-2008 Yuta Mori All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person5* obtaining a copy of this software and associated documentation6* files (the "Software"), to deal in the Software without7* restriction, including without limitation the rights to use,8* copy, modify, merge, publish, distribute, sublicense, and/or sell9* copies of the Software, and to permit persons to whom the10* Software is furnished to do so, subject to the following11* conditions:12*13* The above copyright notice and this permission notice shall be14* included in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES18* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT20* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,21* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING22* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR23* OTHER DEALINGS IN THE SOFTWARE.24*/2526#ifndef _DIVSUFSORT_PRIVATE_H27#define _DIVSUFSORT_PRIVATE_H 12829#ifdef __cplusplus30extern "C" {31#endif /* __cplusplus */3233#if HAVE_CONFIG_H34# include "config.h"35#endif36#include <assert.h>37#include <stdio.h>38#if HAVE_STRING_H39# include <string.h>40#endif41#if HAVE_STDLIB_H42# include <stdlib.h>43#endif44#if HAVE_MEMORY_H45# include <memory.h>46#endif47#if HAVE_STDDEF_H48# include <stddef.h>49#endif50#if HAVE_STRINGS_H51# include <strings.h>52#endif53#if HAVE_INTTYPES_H54# include <inttypes.h>55#else56# if HAVE_STDINT_H57# include <stdint.h>58# endif59#endif60#if defined(BUILD_DIVSUFSORT64)61# include "divsufsort64.h"62# ifndef SAIDX_T63# define SAIDX_T64# define saidx_t saidx64_t65# endif /* SAIDX_T */66# ifndef PRIdSAIDX_T67# define PRIdSAIDX_T PRIdSAIDX64_T68# endif /* PRIdSAIDX_T */69# define divsufsort divsufsort6470# define divbwt divbwt6471# define divsufsort_version divsufsort64_version72# define bw_transform bw_transform6473# define inverse_bw_transform inverse_bw_transform6474# define sufcheck sufcheck6475# define sa_search sa_search6476# define sa_simplesearch sa_simplesearch6477# define sssort sssort6478# define trsort trsort6479#else80# include "divsufsort.h"81#endif828384/*- Constants -*/85#if !defined(UINT8_MAX)86# define UINT8_MAX (255)87#endif /* UINT8_MAX */88#if defined(ALPHABET_SIZE) && (ALPHABET_SIZE < 1)89# undef ALPHABET_SIZE90#endif91#if !defined(ALPHABET_SIZE)92# define ALPHABET_SIZE (UINT8_MAX + 1)93#endif94/* for divsufsort.c */95#define BUCKET_A_SIZE (ALPHABET_SIZE)96#define BUCKET_B_SIZE (ALPHABET_SIZE * ALPHABET_SIZE)97/* for sssort.c */98#if defined(SS_INSERTIONSORT_THRESHOLD)99# if SS_INSERTIONSORT_THRESHOLD < 1100# undef SS_INSERTIONSORT_THRESHOLD101# define SS_INSERTIONSORT_THRESHOLD (1)102# endif103#else104# define SS_INSERTIONSORT_THRESHOLD (8)105#endif106#if defined(SS_BLOCKSIZE)107# if SS_BLOCKSIZE < 0108# undef SS_BLOCKSIZE109# define SS_BLOCKSIZE (0)110# elif 32768 <= SS_BLOCKSIZE111# undef SS_BLOCKSIZE112# define SS_BLOCKSIZE (32767)113# endif114#else115# define SS_BLOCKSIZE (1024)116#endif117/* minstacksize = log(SS_BLOCKSIZE) / log(3) * 2 */118#if SS_BLOCKSIZE == 0119# if defined(BUILD_DIVSUFSORT64)120# define SS_MISORT_STACKSIZE (96)121# else122# define SS_MISORT_STACKSIZE (64)123# endif124#elif SS_BLOCKSIZE <= 4096125# define SS_MISORT_STACKSIZE (16)126#else127# define SS_MISORT_STACKSIZE (24)128#endif129#if defined(BUILD_DIVSUFSORT64)130# define SS_SMERGE_STACKSIZE (64)131#else132# define SS_SMERGE_STACKSIZE (32)133#endif134/* for trsort.c */135#define TR_INSERTIONSORT_THRESHOLD (8)136#if defined(BUILD_DIVSUFSORT64)137# define TR_STACKSIZE (96)138#else139# define TR_STACKSIZE (64)140#endif141142143/*- Macros -*/144#ifndef SWAP145# define SWAP(_a, _b) do { t = (_a); (_a) = (_b); (_b) = t; } while(0)146#endif /* SWAP */147#ifndef MIN148# define MIN(_a, _b) (((_a) < (_b)) ? (_a) : (_b))149#endif /* MIN */150#ifndef MAX151# define MAX(_a, _b) (((_a) > (_b)) ? (_a) : (_b))152#endif /* MAX */153#define STACK_PUSH(_a, _b, _c, _d)\154do {\155assert(ssize < STACK_SIZE);\156stack[ssize].a = (_a), stack[ssize].b = (_b),\157stack[ssize].c = (_c), stack[ssize++].d = (_d);\158} while(0)159#define STACK_PUSH5(_a, _b, _c, _d, _e)\160do {\161assert(ssize < STACK_SIZE);\162stack[ssize].a = (_a), stack[ssize].b = (_b),\163stack[ssize].c = (_c), stack[ssize].d = (_d), stack[ssize++].e = (_e);\164} while(0)165#define STACK_POP(_a, _b, _c, _d)\166do {\167assert(0 <= ssize);\168if(ssize == 0) { return; }\169(_a) = stack[--ssize].a, (_b) = stack[ssize].b,\170(_c) = stack[ssize].c, (_d) = stack[ssize].d;\171} while(0)172#define STACK_POP5(_a, _b, _c, _d, _e)\173do {\174assert(0 <= ssize);\175if(ssize == 0) { return; }\176(_a) = stack[--ssize].a, (_b) = stack[ssize].b,\177(_c) = stack[ssize].c, (_d) = stack[ssize].d, (_e) = stack[ssize].e;\178} while(0)179/* for divsufsort.c */180#define BUCKET_A(_c0) bucket_A[(_c0)]181#if ALPHABET_SIZE == 256182#define BUCKET_B(_c0, _c1) (bucket_B[((_c1) << 8) | (_c0)])183#define BUCKET_BSTAR(_c0, _c1) (bucket_B[((_c0) << 8) | (_c1)])184#else185#define BUCKET_B(_c0, _c1) (bucket_B[(_c1) * ALPHABET_SIZE + (_c0)])186#define BUCKET_BSTAR(_c0, _c1) (bucket_B[(_c0) * ALPHABET_SIZE + (_c1)])187#endif188189190/*- Private Prototypes -*/191/* sssort.c */192void193sssort(const sauchar_t *Td, const saidx_t *PA,194saidx_t *first, saidx_t *last,195saidx_t *buf, saidx_t bufsize,196saidx_t depth, saidx_t n, saint_t lastsuffix);197/* trsort.c */198void199trsort(saidx_t *ISA, saidx_t *SA, saidx_t n, saidx_t depth);200201202#ifdef __cplusplus203} /* extern "C" */204#endif /* __cplusplus */205206#endif /* _DIVSUFSORT_PRIVATE_H */207208209