2 This file is part of the software library CADLIB written by Conrad Ziesler
3 Copyright 2003, Conrad Ziesler, all rights reserved.
5 *************************
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* list_search.h, list container that supports arbitary (binary) search
26 #ifndef __LIST_SEARCH_H__
27 #define __LIST_SEARCH_H__
33 typedef struct list_psearch_st
36 int (*cmpf
)(const void *user
, const void *a
, const void *b
);
42 typedef struct list_search_st
48 typedef struct list_search_iterator_st
53 }list_search_iterator_t
;
55 #define list_search(lp) (&((lp)->list))
57 #define list_search_data(a,b) list_data(list_search((a)),(b))
58 #define list_search_vdata(a,b) list_vdata(list_search((a)),(b))
59 #define list_search_iterate(l,i,p) for((p)=list_search_data((l),(i)=0);(p)!=NULL;(p)=list_search_data((l),++(i)))
60 #define list_search_add(a,b) list_add(list_search((a)),(b))
61 #define list_search_qty(a) list_qty(list_search((a)))
62 #define list_search_index(a,b) list_index(list_search((a)),(b))
63 #define list_search_reset(a) list_reset(list_search((a)))
64 #define list_search_iterate_backwards(l,i,p) for((p)=list_search_data((l),(i)=(list_search((l))->q-1));(p)!=NULL;(p)=list_search_data((l),--(i)))
67 void list_search_init(list_search_t
*lp
, int size
, int mode
);
68 int list_search_addrule(list_search_t
*lp
, int (*cmpf
)(const void *user
, const void *a
, const void *b
),void *user
);
69 void list_search_resort(list_search_t
*lp
);
70 int list_search_find(list_search_t
*lp
, int which
, void *key
, list_search_iterator_t
*sip
);
71 int list_search_findnext(list_search_iterator_t
*sip
);
72 void list_search_empty(list_search_t
*lp
);
76 void list_search_qsort (list_search_t
*lsp
, list_psearch_t
*psp
);