search.hh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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. #ifndef I4_SEARCH_HH
  9. #define I4_SEARCH_HH
  10. #include "arch.hh"
  11. // binary search template for sorted array
  12. //
  13. // if found, returns i4_T and location of item in loc
  14. // if not found, returns i4_F and location of insertion point in loc
  15. //
  16. typedef int (*i4_bsearch_compare_function_type)(const void *key, const void *member);
  17. i4_bool i4_base_bsearch(const void *member, w32 &loc,
  18. const void *array, w32 member_size, w32 size,
  19. i4_bsearch_compare_function_type compare);
  20. template <class Key, class T>
  21. i4_bool i4_bsearch(const Key* member, w32 &loc,
  22. const T* array, w32 size, int (*compare)(const Key*, const T*))
  23. {
  24. return i4_base_bsearch(member, loc, array, sizeof(T), size,
  25. (i4_bsearch_compare_function_type)compare);
  26. }
  27. #endif