public int GetPackFileOffset(Sha sha) { int levelTwo = SearchLevelTwo(sha, sha.FirstByte); if (levelTwo == -1) throw new ObjectNotFoundException(sha.SHAString); return System.Net.IPAddress.HostToNetworkOrder(BitConverter.ToInt32(offsets[sha.FirstByte], levelTwo << 2)); }
private int SearchLevelTwo(Sha sha, int index) { int[] data = shas[index]; int high = offsets[index].Length >> 2; if (high == 0) return -1; int low = 0; while (low < high) { int mid = (low + high) >> 1; int mid4 = mid << 2; int cmp; cmp = sha.CompareTo(data, mid4 + mid); if (cmp < 0) high = mid; else if (cmp == 0) return mid; else low = mid + 1; } return -1; }