[80] | 1 | /********************************************************************** <BR>
|
---|
| 2 | This file is part of Crack dot Com's free source code release of
|
---|
| 3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
| 4 | information about compiling & licensing issues visit this URL</a>
|
---|
| 5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
| 6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
| 7 | ***********************************************************************/
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | #ifndef I4_SEARCH_HH
|
---|
| 11 | #define I4_SEARCH_HH
|
---|
| 12 |
|
---|
| 13 | #include "arch.hh"
|
---|
| 14 |
|
---|
| 15 | // binary search template for sorted array
|
---|
| 16 | //
|
---|
| 17 | // if found, returns i4_T and location of item in loc
|
---|
| 18 | // if not found, returns i4_F and location of insertion point in loc
|
---|
| 19 | //
|
---|
| 20 |
|
---|
| 21 | typedef int (*i4_bsearch_compare_function_type)(const void *key, const void *member);
|
---|
| 22 |
|
---|
| 23 | i4_bool i4_base_bsearch(const void *member, w32 &loc,
|
---|
| 24 | const void *array, w32 member_size, w32 size,
|
---|
| 25 | i4_bsearch_compare_function_type compare);
|
---|
| 26 |
|
---|
| 27 | template <class Key, class T>
|
---|
| 28 | i4_bool i4_bsearch(const Key* member, w32 &loc,
|
---|
| 29 | const T* array, w32 size, int (*compare)(const Key*, const T*))
|
---|
| 30 | {
|
---|
| 31 | return i4_base_bsearch(member, loc, array, sizeof(T), size,
|
---|
| 32 | (i4_bsearch_compare_function_type)compare);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | #endif
|
---|