This repository has been archived on 2025-05-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
libcdio-osx/lib/paranoia/isort.h

124 lines
4.3 KiB
C
Raw Normal View History

/*
$Id: isort.h,v 1.4 2005/10/15 03:18:42 rocky Exp $
2005-01-07 02:42:29 +00:00
Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ISORT_H_
#define _ISORT_H_
typedef struct sort_link{
struct sort_link *next;
} sort_link_t;
2005-01-07 02:42:29 +00:00
typedef struct sort_info {
int16_t *vector; /* vector (storage doesn't belong to us) */
long *abspos; /* pointer for side effects */
long size; /* vector size */
long maxsize; /* maximum vector size */
long sortbegin; /* range of contiguous sorted area */
long lo,hi; /* current post, overlap range */
int val; /* ...and val */
/* sort structs */
sort_link_t **head; /* sort buckets (65536) */
long *bucketusage; /* of used buckets (65536) */
long lastbucket;
sort_link_t *revindex;
2005-01-07 02:42:29 +00:00
} sort_info_t;
/*! ========================================================================
* sort_alloc()
*
* Allocates and initializes a new, empty sort_info object, which can
* be used to index up to (size) samples from a vector.
*/
extern sort_info_t *sort_alloc(long int size);
/*! ========================================================================
* sort_unsortall() (internal)
*
* This function resets the index for further use with a different
* vector or range, without the overhead of an unnecessary free/alloc.
*/
2005-01-07 02:42:29 +00:00
extern void sort_unsortall(sort_info_t *i);
/*! ========================================================================
* sort_setup()
*
* This function initializes a previously allocated sort_info_t. The
* sort_info_t is associated with a vector of samples of length
* (size), whose position begins at (*abspos) within the CD's stream
* of samples. Only the range of samples between (sortlo, sorthi)
* will eventually be indexed for fast searching. (sortlo, sorthi)
* are absolute sample positions.
*
* ???: Why is abspos a pointer? Why not just store a copy?
*
* Note: size *must* be <= the size given to the preceding sort_alloc(),
* but no error checking is done here.
*/
extern void sort_setup(sort_info_t *i, int16_t *vector, long int *abspos,
long int size, long int sortlo, long int sorthi);
/* =========================================================================
* sort_free()
*
* Releases all memory consumed by a sort_info object.
*/
2005-01-07 02:42:29 +00:00
extern void sort_free(sort_info_t *i);
/*! ========================================================================
* sort_getmatch()
*
* This function returns a sort_link_t pointer which refers to the
* first sample equal to (value) in the vector. It only searches for
* hits within (overlap) samples of (post), where (post) is an offset
* within the vector. The caller can determine the position of the
* matched sample using ipos(sort_info *, sort_link *).
*
* This function returns NULL if no matches were found.
*/
extern sort_link_t *sort_getmatch(sort_info_t *i, long post, long overlap,
int value);
/*! ========================================================================
* sort_nextmatch()
*
* This function returns a sort_link_t pointer which refers to the
* next sample matching the criteria previously passed to
* sort_getmatch(). See sort_getmatch() for details.
*
* This function returns NULL if no further matches were found.
*/
extern sort_link_t *sort_nextmatch(sort_info_t *i, sort_link_t *prev);
#define is(i) (i->size)
#define ib(i) (*i->abspos)
#define ie(i) (i->size+*i->abspos)
#define iv(i) (i->vector)
#define ipos(i,l) (l-i->revindex)
#endif /* _ISORT_H_ */