mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-30 22:51:16 +01:00
A little bit more sane binary search
This commit is contained in:
parent
cb8c19a2bc
commit
14a9c0a8cb
@ -1,4 +1,4 @@
|
|||||||
#include "bitstream.h"
|
#include "bitstream.h"
|
||||||
#include "nodfile.h"
|
#include "nodfile.h"
|
||||||
|
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ bool NODFile::nodeBlock(Handle &hdl, quint32 nodeOffset,
|
|||||||
quint32 offsetSize = (_indexFlags & 3) + 1;
|
quint32 offsetSize = (_indexFlags & 3) + 1;
|
||||||
|
|
||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
quint32 m = ((low + high) / 2);
|
int m = ((low + high) / 2);
|
||||||
quint32 offset = _indexRecordSize * m + _indexOffset;
|
quint32 offset = _indexRecordSize * m + _indexOffset;
|
||||||
quint32 blockOffset, prevBlockOffset;
|
quint32 blockOffset, prevBlockOffset;
|
||||||
|
|
||||||
@ -507,40 +507,32 @@ bool NODFile::linkType(Handle &hdl, const BlockInfo &blockInfo, quint8 linkId,
|
|||||||
quint32 offset = ((blockInfo.hdr.s10 * blockInfo.hdr.se + 7) >> 3) + 0x13
|
quint32 offset = ((blockInfo.hdr.s10 * blockInfo.hdr.se + 7) >> 3) + 0x13
|
||||||
+ blockInfo.offset + _blockOffset + ((blockInfo.hdr.s0 >> 0xb) & 1)
|
+ blockInfo.offset + _blockOffset + ((blockInfo.hdr.s0 >> 0xb) & 1)
|
||||||
+ blockInfo.hdr.s11 * 3;
|
+ blockInfo.hdr.s11 * 3;
|
||||||
quint32 low = 0;
|
int low = 0;
|
||||||
quint32 high = blockInfo.hdr.s12 - 1;
|
int high = blockInfo.hdr.s12 - 1;
|
||||||
quint32 pos = blockInfo.hdr.s12;
|
|
||||||
quint16 val;
|
quint16 val;
|
||||||
|
|
||||||
if (high > 1) {
|
while (low <= high) {
|
||||||
do {
|
int m = ((low + high) / 2);
|
||||||
pos = (low + high) / 2;
|
|
||||||
|
|
||||||
if (!(seek(hdl, offset + _blockRecordSize * pos)
|
if (!(seek(hdl, offset + _blockRecordSize * m) && readUInt16(hdl, val)))
|
||||||
&& readUInt16(hdl, val)))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((val >> 8) <= linkId)
|
if ((val >> 8) < linkId)
|
||||||
low = pos;
|
low = m + 1;
|
||||||
else
|
else if ((val >> 8) > linkId)
|
||||||
high = pos;
|
high = m - 1;
|
||||||
} while (low + 1 < high);
|
else {
|
||||||
|
type = (val & 0x3f) << 8;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(seek(hdl, offset + _blockRecordSize * low) && readUInt16(hdl, val)))
|
if (high < 0)
|
||||||
return false;
|
return false;
|
||||||
|
if (blockInfo.hdr.s12 > 1 && !(seek(hdl, offset + _blockRecordSize * high)
|
||||||
type = val & 0x3f;
|
|
||||||
|
|
||||||
if ((low < high) && (pos != high)) {
|
|
||||||
if (!(seek(hdl, offset + _blockRecordSize * high)
|
|
||||||
&& readUInt16(hdl, val)))
|
&& readUInt16(hdl, val)))
|
||||||
return false;
|
return false;
|
||||||
if ((val >> 8) <= linkId)
|
type = (val & 0x3f) << 8;
|
||||||
type = (val & 0x3f);
|
|
||||||
}
|
|
||||||
|
|
||||||
type <<= 8;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user