source: golgotha/src/i4/inc/search.hh

Last change on this file was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 1.3 KB
Line 
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
21typedef int (*i4_bsearch_compare_function_type)(const void *key, const void *member);
22
23i4_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
27template <class Key, class T>
28i4_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
Note: See TracBrowser for help on using the repository browser.