Search for ranges that overlap the specified value or range.

@param mixed $interval Either a RangeInterface or a value.

@return array
501676
public function search($interval)
    {
        if (is_null($this->top_node)) {
            return array();
        }

        $result = $this->find_intervals($interval);
        $result = array_values($result);

        usort($result, function (RangeInterface $a, RangeInterface $b) {
            $x = $a->getStart();
            $y = $b->getStart();

            $comparedValue = $this->compare($x, $y);

            if ($comparedValue == 0) {
                $x = $a->getEnd();
                $y = $b->getEnd();
                $comparedValue = $this->compare($x, $y);
            }

            return $comparedValue;
        });

        return $result;
    }
1128455
def get_overlaps(self) -> "IntervalList":
        
        overlaps = IntervalList()
        for i in range(len(self.intervals)):
            for j in range(i + 1, len(self.intervals)):
                first = self.intervals[i]
                second = self.intervals[j]
                ol = first.intersection(second)
                if ol is not None:
                    overlaps.add(ol)
        return overlaps
941149
protected function define_ranges() {

        $nparts = $this->get_number_parts();

        $rangeduration = ($this->analysable->get_end() - $this->analysable->get_start()) / $nparts;

        $ranges = array();
        for ($i = 0; $i < $nparts; $i++) {
            $end = $this->analysable->get_start() + intval($rangeduration * ($i + 1));
            if ($i === ($nparts - 1)) {
                // Better to use the end for the last one as we are using floor above.
                $end = $this->analysable->get_end();
            }
            $ranges[$i] = array(
                'start' => $this->analysable->get_start(),
                'end' => $end,
                'time' => $end
            );
        }

        return $ranges;
    }
4939
public function gap(DateRange $range)
	{
		return self::cast($this->range->gap($range->range));
	}
1302803
protected function calculateUnits(DateInterval $interval)
    {
        $units = array_filter(array(
            'years'   => (int) $interval->y,
            'months'  => (int) $interval->m,
            'days'    => (int) $interval->d,
            'hours'   => (int) $interval->h,
            'minutes' => (int) $interval->i,
            'seconds' => (int) $interval->s,
        ));

        if (empty($units)) {
            return array();
        } else if ((int) $this->config['truncate'] > 0) {
            return array_slice($units, 0, (int) $this->config['truncate']);
        }

        return $units;
    }
1224351
protected List<Intervalable> checkForOverlaps(Intervalable interval, Direction direction)
    {

        List<Intervalable> overlaps = new ArrayList<Intervalable>();
        for (Intervalable currentInterval : this.intervals)
        {
            switch (direction)
            {
                case LEFT:
                    if (currentInterval.getStart() <= interval.getEnd())
                    {
                        overlaps.add(currentInterval);
                    }
                    break;
                case RIGHT:
                    if (currentInterval.getEnd() >= interval.getStart())
                    {
                        overlaps.add(currentInterval);
                    }
                    break;
            }
        }
        return overlaps;
    }
817204
public function subtract($interval) : self
    {
        $instance = clone $this;
        
        $instance->date->sub(self::resolveDateInterval($interval));
        
        return $instance;
    }
1347432
public function rangeLimit(int $max, int $limit) : array
        {
                $response =  $this->_redis->zrevrangebyscore($this->_key, $max, '-inf','WITHSCORES', 'LIMIT', 0, $limit);
                $result   = [];
                for($i=0,$num=count($response);$i<$num;$i++) {
                        $result[$response[$i]] = intval($response[++$i]);
                }
                return $result;
        }
743467
public static function range($step = 10, $max = 100)
    {
        $step = intval($step);
        $max = intval($max);

        if ($step < 1)
        {
            return [];
        }

        $array = [];
        for ($i = $step; $i <= $max; $i += $step)
        {
            $array[$i] = $i;
        }

        return $array;
    }
710789
protected function isInRange($range, $value)
    {
        $parts = explode('-', $range);

        return $value >= $parts[0] && $value <= $parts[1];
    }
817359
protected static function intervalHasTime(DateInterval $interval)
    {
        // The array_key_exists and get_object_vars are used as a workaround to check microsecond support.
        // Both isset and property_exists will fail on PHP 7.0.14 - 7.0.21 due to the following bug:
        // https://bugs.php.net/bug.php?id=74852
        return $interval->h || $interval->i || $interval->s || array_key_exists('f', get_object_vars($interval)) && $interval->f;
    }
419470
public function getLines(LineRangeInterface $range)
    {
        $this->assertRangeIsInsideBuffer($range);

        return array_slice(
            $this->contents,
            $range->getStart()->getNumber(),
            $range->getLength()
        );
    }
1100632
public function interval($interval = null)
    {
        if (is_null($interval)) {
            return (int) $this->interval;
        }

        $this->interval = (int) $interval;

        return $this;
    }
548295
private function extractRange($range)
    {
        if (\preg_match('/^\d+$/', $range)) {
            return [$range, $range + 1];
        }

        $matches = [];
        if ($range !== '..' && \preg_match('/^(\d*)\.\.(\d*)$/', $range, $matches)) {
            $start = $matches[1] ? \intval($matches[1]) : 0;
            $end   = $matches[2] ? \intval($matches[2]) + 1 : PHP_INT_MAX;

            return [$start, $end];
        }

        throw new \InvalidArgumentException('Unexpected range: ' . $range);
    }
267195
public function findVisitPages(Range $interval): array
	{
		$result = [];
		$subQuery = 'SELECT '
			. '[url], '
			. 'DATE([inserted]) datefield, '
			. 'COUNT([uid]) num '
			. 'FROM %table '
			. 'WHERE DATE([inserted]) BETWEEN DATE(%dt) AND DATE(%dt) '
			. 'GROUP BY [url], [uid], ROUND(UNIX_TIMESTAMP([inserted]) / %i)';
		$rows = $this->connection->query('SELECT [datefield], [url], COUNT([num]) visits, SUM([num]) views FROM (' . $subQuery . ') sub GROUP BY [url]', $this->getTableName(), $interval->from, $interval->to, $this->minTimeBetweenVisits * 60);

		foreach ($rows as $row) {
			$data = new stdClass;
			$data->datefield = $row->datefield;
			$data->visits = $row->visits;
			$data->views = $row->views;

			$url = new Url($row->url);
			$data->page = substr($url->getPath(), 1) ?: '';
			if (!empty($url->query)) {
				$data->page .= '?' . $url->getQuery();
			}
			if (!empty($url->fragment)) {
				$data->page .= '#' . $url->getFragment();
			}
			$result[] = $data;
		}
		return $result;
	}
231044
public static function range($max, $start = 1, $step = 1)
    {
        if ($step < 1) {
            return [];
        }

        $array = [];
        for ($i = $start; $i <= $max; $i += $step) {
            $array[] = $i;
        }

        return $array;
    }
1087617
final public static function recalculateInterval($interval)
    {
        try {
            $from = new \DateTimeImmutable();
            $to = $from->add($interval);
            $diff = $to->diff($from);
            foreach ($diff as $k => $v) {
                $interval->$k = $v;
            }

        } catch (\Exception $e) {
        }

        return $interval;
    }