content buffer directly as vectorIndex
This commit is contained in:
parent
ca6b26c53a
commit
9659a920e9
|
|
@ -133,7 +133,7 @@ class XdbSearcher
|
||||||
// read the segment index
|
// read the segment index
|
||||||
$buff = $this->read($p, self::SegmentIndexSize);
|
$buff = $this->read($p, self::SegmentIndexSize);
|
||||||
if ($buff == null) {
|
if ($buff == null) {
|
||||||
throw new Exception("failed to read segment index at ${$p}");
|
throw new Exception("failed to read segment index at ${p}");
|
||||||
}
|
}
|
||||||
|
|
||||||
$sip = self::getLong($buff, 0);
|
$sip = self::getLong($buff, 0);
|
||||||
|
|
@ -296,16 +296,6 @@ class XdbSearcher
|
||||||
return self::loadVectorIndex($handle);
|
return self::loadVectorIndex($handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// load vector index from the specified buffer
|
|
||||||
public static function loadVectorIndexFromBuff($cBuff) {
|
|
||||||
$len = self::VectorIndexRows * self::VectorIndexCols * self::SegmentIndexSize;
|
|
||||||
if (strlen($cBuff) < (self::HeaderInfoLength + $len)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return substr($cBuff, self::HeaderInfoLength, $len);
|
|
||||||
}
|
|
||||||
|
|
||||||
// load the xdb content from a file handle
|
// load the xdb content from a file handle
|
||||||
public static function loadContent($handle) {
|
public static function loadContent($handle) {
|
||||||
if (fseek($handle, 0, SEEK_END) == -1) {
|
if (fseek($handle, 0, SEEK_END) == -1) {
|
||||||
|
|
|
||||||
|
|
@ -29,22 +29,6 @@ function testLoadVectorIndex() {
|
||||||
printf("vector index loaded: length=%d\n", strlen($vIndex));
|
printf("vector index loaded: length=%d\n", strlen($vIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testLoadVectorIndexFromBuff() {
|
|
||||||
$cBuff = XdbSearcher::loadContentFromFile('../../data/ip2region.xdb');
|
|
||||||
if ($cBuff == null) {
|
|
||||||
printf("failed to load content from file\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$vIndex = XdbSearcher::loadVectorIndexFromBuff($cBuff);
|
|
||||||
if ($vIndex == null) {
|
|
||||||
printf("failed to load content from file\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("vector index loaded, length=%d\n", strlen($vIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testLoadContent() {
|
function testLoadContent() {
|
||||||
$cBuff = XdbSearcher::loadContentFromFile('../../data/ip2region.xdb');
|
$cBuff = XdbSearcher::loadContentFromFile('../../data/ip2region.xdb');
|
||||||
if ($cBuff == null) {
|
if ($cBuff == null) {
|
||||||
|
|
@ -67,12 +51,6 @@ testLoadVectorIndex();
|
||||||
printf("done, cost: %0.5f ms\n\n", XdbSearcher::now() - $now);
|
printf("done, cost: %0.5f ms\n\n", XdbSearcher::now() - $now);
|
||||||
|
|
||||||
|
|
||||||
printf("testing loadVectorIndexFromBuff ... \n");
|
|
||||||
$now = XdbSearcher::now();
|
|
||||||
testLoadVectorIndexFromBuff();
|
|
||||||
printf("done, cost: %0.5f ms\n\n", XdbSearcher::now() - $now);
|
|
||||||
|
|
||||||
|
|
||||||
printf("testing loadContent ... \n");
|
printf("testing loadContent ... \n");
|
||||||
$now = XdbSearcher::now();
|
$now = XdbSearcher::now();
|
||||||
testLoadContent();
|
testLoadContent();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue