Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

SxGeo diapasons search on C#

tolikpunkoff Sep 22nd, 2018 79 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. private uint SearchDB(byte[] db, uint ipn, uint min, uint max)
  2. {            
  3.     if (max - min > 1)
  4.     {
  5.         while (max - min > 8)
  6.         {
  7.             uint offset = (min + max) >> 1;
  8.             uint x = getUintFrom3b(bSubstr(db, offset * Header.block_len, 3));
  9.             if (ipn > getUintFrom3b(bSubstr(db, offset * Header.block_len, 3)))
  10.                 min = offset;
  11.             else
  12.                 max = offset;                    
  13.         }
  14.  
  15.         while (ipn >= getUintFrom3b(bSubstr(db, min * Header.block_len, 3))
  16.             && ++min < max) { }
  17.     }
  18.     else
  19.     {
  20.         min++;
  21.     }
  22.  
  23.     uint ans = 0;
  24.  
  25.     if (Header.IdLen == 3) //БД с городами
  26.     {
  27.         ans = getUintFrom3b(
  28.             bSubstr(db, min * Header.block_len - Header.IdLen, Header.IdLen));
  29.     }
  30.     else //только ID стран
  31.     {
  32.         ans = bSubstr(db, min * Header.block_len - Header.IdLen, Header.IdLen)[0];
  33.     }
  34.  
  35.     return ans;
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top