Advertisement
tolikpunkoff

SxGeo diapasons search on C#

Sep 22nd, 2018
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement