2 * divsufsort_private.h for libdivsufsort
3 * Copyright (c) 2003-2008 Yuta Mori All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
27 #ifndef _DIVSUFSORT_PRIVATE_H
28 #define _DIVSUFSORT_PRIVATE_H 1
32 #endif /* __cplusplus */
55 # include <inttypes.h>
61 #if defined(BUILD_DIVSUFSORT64)
62 # include "divsufsort64.h"
65 # define saidx_t saidx64_t
68 # define PRIdSAIDX_T PRIdSAIDX64_T
69 # endif /* PRIdSAIDX_T */
70 # define divsufsort divsufsort64
71 # define divbwt divbwt64
72 # define divsufsort_version divsufsort64_version
73 # define bw_transform bw_transform64
74 # define inverse_bw_transform inverse_bw_transform64
75 # define sufcheck sufcheck64
76 # define sa_search sa_search64
77 # define sa_simplesearch sa_simplesearch64
78 # define sssort sssort64
79 # define trsort trsort64
81 # include "divsufsort.h"
86 #if !defined(UINT8_MAX)
87 # define UINT8_MAX (255)
88 #endif /* UINT8_MAX */
89 #if defined(ALPHABET_SIZE) && (ALPHABET_SIZE < 1)
92 #if !defined(ALPHABET_SIZE)
93 # define ALPHABET_SIZE (UINT8_MAX + 1)
95 /* for divsufsort.c */
96 #define BUCKET_A_SIZE (ALPHABET_SIZE)
97 #define BUCKET_B_SIZE (ALPHABET_SIZE * ALPHABET_SIZE)
99 #if defined(SS_INSERTIONSORT_THRESHOLD)
100 # if SS_INSERTIONSORT_THRESHOLD < 1
101 # undef SS_INSERTIONSORT_THRESHOLD
102 # define SS_INSERTIONSORT_THRESHOLD (1)
105 # define SS_INSERTIONSORT_THRESHOLD (8)
107 #if defined(SS_BLOCKSIZE)
108 # if SS_BLOCKSIZE < 0
110 # define SS_BLOCKSIZE (0)
111 # elif 32768 <= SS_BLOCKSIZE
113 # define SS_BLOCKSIZE (32767)
116 # define SS_BLOCKSIZE (1024)
118 /* minstacksize = log(SS_BLOCKSIZE) / log(3) * 2 */
119 #if SS_BLOCKSIZE == 0
120 # if defined(BUILD_DIVSUFSORT64)
121 # define SS_MISORT_STACKSIZE (96)
123 # define SS_MISORT_STACKSIZE (64)
125 #elif SS_BLOCKSIZE <= 4096
126 # define SS_MISORT_STACKSIZE (16)
128 # define SS_MISORT_STACKSIZE (24)
130 #if defined(BUILD_DIVSUFSORT64)
131 # define SS_SMERGE_STACKSIZE (64)
133 # define SS_SMERGE_STACKSIZE (32)
136 #define TR_INSERTIONSORT_THRESHOLD (8)
137 #if defined(BUILD_DIVSUFSORT64)
138 # define TR_STACKSIZE (96)
140 # define TR_STACKSIZE (64)
146 # define SWAP(_a, _b) do { t = (_a); (_a) = (_b); (_b) = t; } while(0)
149 # define MIN(_a, _b) (((_a) < (_b)) ? (_a) : (_b))
152 # define MAX(_a, _b) (((_a) > (_b)) ? (_a) : (_b))
154 #define STACK_PUSH(_a, _b, _c, _d)\
156 assert(ssize < STACK_SIZE);\
157 stack[ssize].a = (_a), stack[ssize].b = (_b),\
158 stack[ssize].c = (_c), stack[ssize++].d = (_d);\
160 #define STACK_PUSH5(_a, _b, _c, _d, _e)\
162 assert(ssize < STACK_SIZE);\
163 stack[ssize].a = (_a), stack[ssize].b = (_b),\
164 stack[ssize].c = (_c), stack[ssize].d = (_d), stack[ssize++].e = (_e);\
166 #define STACK_POP(_a, _b, _c, _d)\
169 if(ssize == 0) { return; }\
170 (_a) = stack[--ssize].a, (_b) = stack[ssize].b,\
171 (_c) = stack[ssize].c, (_d) = stack[ssize].d;\
173 #define STACK_POP5(_a, _b, _c, _d, _e)\
176 if(ssize == 0) { return; }\
177 (_a) = stack[--ssize].a, (_b) = stack[ssize].b,\
178 (_c) = stack[ssize].c, (_d) = stack[ssize].d, (_e) = stack[ssize].e;\
180 /* for divsufsort.c */
181 #define BUCKET_A(_c0) bucket_A[(_c0)]
182 #if ALPHABET_SIZE == 256
183 #define BUCKET_B(_c0, _c1) (bucket_B[((_c1) << 8) | (_c0)])
184 #define BUCKET_BSTAR(_c0, _c1) (bucket_B[((_c0) << 8) | (_c1)])
186 #define BUCKET_B(_c0, _c1) (bucket_B[(_c1) * ALPHABET_SIZE + (_c0)])
187 #define BUCKET_BSTAR(_c0, _c1) (bucket_B[(_c0) * ALPHABET_SIZE + (_c1)])
191 /*- Private Prototypes -*/
194 sssort(const sauchar_t *Td, const saidx_t *PA,
195 saidx_t *first, saidx_t *last,
196 saidx_t *buf, saidx_t bufsize,
197 saidx_t depth, saidx_t n, saint_t lastsuffix);
200 trsort(saidx_t *ISA, saidx_t *SA, saidx_t n, saidx_t depth);
205 #endif /* __cplusplus */
207 #endif /* _DIVSUFSORT_PRIVATE_H */