private function sortMappings() { $this->tcpPortMap =& sortArrayByStartValue($this->tcpPortMap); $this->udpPortMap =& sortArrayByStartValue($this->udpPortMap); }
public function sortAndRecalculate() { $newMapping = sortArrayByStartValue($this->_map); $mapKeys = array_keys($newMapping); $mapCount = count($newMapping); for ($i = 0; $i < $mapCount; $i++) { $current =& $newMapping[$mapKeys[$i]]; for ($j = $i + 1; $j < $mapCount; $j++) { $compare =& $newMapping[$mapKeys[$j]]; if ($compare['start'] > $current['end'] + 1) { break; } $current['end'] = $compare['end']; unset($newMapping[$mapKeys[$j]]); $i++; } } $this->_map =& $newMapping; }
function &mergeOverlappingIP4Mapping(&$ip4mapping) { $newMapping = sortArrayByStartValue($ip4mapping); $mapKeys = array_keys($newMapping); $mapCount = count($newMapping); for ($i = 0; $i < $mapCount; $i++) { $current =& $newMapping[$mapKeys[$i]]; //print " - handling ".long2ip($current['start'])."-".long2ip($current['end'])."\n"; for ($j = $i + 1; $j < $mapCount; $j++) { $compare =& $newMapping[$mapKeys[$j]]; //print " - vs ".long2ip($compare['start'])."-".long2ip($compare['end'])."\n"; if ($compare['start'] > $current['end'] + 1) { break; } $current['end'] = $compare['end']; //print " MERGED ->".long2ip($current['start'])."-".long2ip($current['end'])." \n"; unset($newMapping[$mapKeys[$j]]); $i++; } } return $newMapping; }