Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private uint SearchDB(byte[] db, uint ipn, uint min, uint max)
- {
- if (max - min > 1)
- {
- while (max - min > 8)
- {
- uint offset = (min + max) >> 1;
- uint x = getUintFrom3b(bSubstr(db, offset * Header.block_len, 3));
- if (ipn > getUintFrom3b(bSubstr(db, offset * Header.block_len, 3)))
- min = offset;
- else
- max = offset;
- }
- while (ipn >= getUintFrom3b(bSubstr(db, min * Header.block_len, 3))
- && ++min < max) { }
- }
- else
- {
- min++;
- }
- uint ans = 0;
- if (Header.IdLen == 3) //БД с городами
- {
- ans = getUintFrom3b(
- bSubstr(db, min * Header.block_len - Header.IdLen, Header.IdLen));
- }
- else //только ID стран
- {
- ans = bSubstr(db, min * Header.block_len - Header.IdLen, Header.IdLen)[0];
- }
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement