public function testCheckIntersection() { $ipSeg = new ipSegment(3, 5); $this->assertFalse($ipSeg->checkIntersection(new ipSegment(1, 2))); $this->assertTrue($ipSeg->checkIntersection(new ipSegment(1, 3))); $this->assertTrue($ipSeg->checkIntersection(new ipSegment(1, 4))); $this->assertTrue($ipSeg->checkIntersection(new ipSegment(3, 4))); $this->assertTrue($ipSeg->checkIntersection(new ipSegment(4, 4))); $this->assertTrue($ipSeg->checkIntersection(new ipSegment(4, 5))); $this->assertTrue($ipSeg->checkIntersection(new ipSegment(5, 6))); $this->assertFalse($ipSeg->checkIntersection(new ipSegment(6, 7))); }
private function writeHashIndex() { $this->hashListPtr = array(); $curData = $this->dbData->resetData(); $ipSeg = new ipSegment($curData[dbDataProcessor::IP_START_POS], $curData[dbDataProcessor::IP_END_POS]); $ipSeg2 = new ipSegment(0, 0); $count = ($this->hashMax - $this->hashMin) / $this->hashStep; for ($i = 0; $i < $count; $i++) { $hashSegmentStart = $this->hashMin + $this->hashStep * $i; $ipSeg2->setStartIp($hashSegmentStart); $ipSeg2->setEndIp($hashSegmentStart + $this->hashStep - 1); //Проверяем вхождение $hashList = array(); while ($ipSeg->checkIntersection($ipSeg2)) { $hashList[] = $this->dbData->getCurrentKey(); if ($curData[dbDataProcessor::IP_END_POS] > $hashSegmentStart + $this->hashStep - 0.001) { break; // Продлеваем текущий интервал на следующий шаг } $curData = $this->dbData->getNext(); $ipSeg->setStartIp($curData[dbDataProcessor::IP_START_POS]); $ipSeg->setEndIp($curData[dbDataProcessor::IP_END_POS]); if ($curData === false) { break; } } $hashListPtr[] = $this->dbStream->tell(); $this->writeInt(count($hashList)); foreach ($hashList as $dataKey) { $this->writeInt($this->dbData->getStartIpByKey($dataKey)); $this->writeInt($this->dbData->getEndIpByKey($dataKey)); $this->writeInt($this->dataFilePtr[$dataKey]); } unset($hashList); if ($curData === false) { break; } } //Записываем указатели на Хэши foreach ($hashListPtr as $hashPtr) { $this->writeInt($hashPtr); } //Записываем параметры хэш функции $this->writeInt($this->hashMin); $this->writeInt($this->hashMax); $this->writeInt($this->hashStep); }