libcdio-paranoia  10.2+0.94+2git
isort.h
Go to the documentation of this file.
1 /*
2  $Id: isort_8h_source.html,v 1.3 2017/08/23 00:53:57 rocky Exp $
3 
4  Copyright (C) 2004, 2005, 2008 Rocky Bernstein <rocky@gnu.org>
5  Copyright (C) 1998 Monty xiphmont@mit.edu
6 
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef _ISORT_H_
22 #define _ISORT_H_
23 
24 typedef struct sort_link{
25  struct sort_link *next;
26 } sort_link_t;
27 
28 typedef struct sort_info {
29  int16_t *vector; /* vector (storage doesn't belong to us) */
30 
31  long *abspos; /* pointer for side effects */
32  long size; /* vector size */
33 
34  long maxsize; /* maximum vector size */
35 
36  long sortbegin; /* range of contiguous sorted area */
37  long lo,hi; /* current post, overlap range */
38  int val; /* ...and val */
39 
40  /* sort structs */
41  sort_link_t **head; /* sort buckets (65536) */
42 
43  long *bucketusage; /* of used buckets (65536) */
44  long lastbucket;
46 
47 } sort_info_t;
48 
55 extern sort_info_t *sort_alloc(long int size);
56 
63 extern void sort_unsortall(sort_info_t *i);
64 
80 extern void sort_setup(sort_info_t *i, int16_t *vector, long int *abspos,
81  long int size, long int sortlo, long int sorthi);
82 
83 /* =========================================================================
84  * sort_free()
85  *
86  * Releases all memory consumed by a sort_info object.
87  */
88 extern void sort_free(sort_info_t *i);
89 
101 extern sort_link_t *sort_getmatch(sort_info_t *i, long post, long overlap,
102  int value);
103 
114 
115 /* ===========================================================================
116  * is()
117  *
118  * This macro returns the size of the vector indexed by the given sort_info_t.
119  */
120 #define is(i) (i->size)
121 
122 /* ===========================================================================
123  * ib()
124  *
125  * This macro returns the absolute position of the first sample in the vector
126  * indexed by the given sort_info_t.
127  */
128 #define ib(i) (*i->abspos)
129 
130 /* ===========================================================================
131  * ie()
132  *
133  * This macro returns the absolute position of the sample after the last
134  * sample in the vector indexed by the given sort_info_t.
135  */
136 #define ie(i) (i->size+*i->abspos)
137 
138 /* ===========================================================================
139  * iv()
140  *
141  * This macro returns the vector indexed by the given sort_info_t.
142  */
143 #define iv(i) (i->vector)
144 
145 /* ===========================================================================
146  * ipos()
147  *
148  * This macro returns the relative position (offset) within the indexed vector
149  * at which the given match was found.
150  *
151  * It uses a little-known and frightening aspect of C pointer arithmetic:
152  * subtracting a pointer is not an arithmetic subtraction, but rather the
153  * additive inverse. In other words, since
154  * q = p + n returns a pointer to the nth object in p,
155  * q - p = p + n - p, and
156  * q - p = n, not the difference of the two addresses.
157  */
158 #define ipos(i,l) (l-i->revindex)
159 
160 #endif /* _ISORT_H_ */
161 
void sort_free(sort_info_t *i)
Definition: isort.c:118
long maxsize
Definition: isort.h:34
int val
Definition: isort.h:38
long * abspos
Definition: isort.h:31
sort_info_t * sort_alloc(long int size)
struct sort_link sort_link_t
struct sort_info sort_info_t
long lo
Definition: isort.h:37
long lastbucket
Definition: isort.h:44
sort_link_t ** head
Definition: isort.h:41
Definition: isort.h:28
long sortbegin
Definition: isort.h:36
sort_link_t * sort_getmatch(sort_info_t *i, long post, long overlap, int value)
Definition: isort.c:232
void sort_setup(sort_info_t *i, int16_t *vector, long int *abspos, long int size, long int sortlo, long int sorthi)
Definition: isort.c:199
long size
Definition: isort.h:32
sort_link_t * sort_nextmatch(sort_info_t *i, sort_link_t *prev)
Definition: isort.c:289
long * bucketusage
Definition: isort.h:43
sort_link_t * revindex
Definition: isort.h:45
int16_t * vector
Definition: isort.h:29
void sort_unsortall(sort_info_t *i)
Definition: isort.c:85