search.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. #include "inc/search.hh"
  9. i4_bool i4_base_bsearch(const void *member, w32 &loc,
  10. const void *array, w32 member_size, w32 size,
  11. int (*compare)(const void *a, const void *b))
  12. {
  13. w32 l=0,r=size,m;
  14. int c;
  15. while (l<r)
  16. {
  17. m = (l+r)/2;
  18. if ((c = compare(member, (void*)((w8*)array+member_size*m)))==0)
  19. {
  20. loc = m;
  21. return i4_T;
  22. }
  23. else if (c<0)
  24. r = m;
  25. else
  26. l = m+1;
  27. }
  28. loc = l;
  29. if (l<size && compare(member, (void*)((w8*)array+member_size*l))==0)
  30. return i4_T;
  31. return i4_F;
  32. }