Optimizes the supplied route tree

@param RouteTree $routeTree

@return RouteTree
197737
public function optimize(RouteTree $routeTree)
    {
        $segmentDepthNodeMap = $routeTree->getSegmentDepthNodesMap();

        foreach ($segmentDepthNodeMap as $segmentDepth => $nodes) {
            $segmentDepthNodeMap[$segmentDepth] = $this->optimizeNodes($nodes);
        }

        return new RouteTree($routeTree->getRootRouteData(), $segmentDepthNodeMap);
    }
500812
function update($route) {
        $route->pattern = $this->parser->trimPath($route->pattern);
        return parent::update($route);
    }
718652
public function getTreeCollection(Tree $selectedTree = null)
    {
        $collection = new StandardTreeCollection();
        $sites = $this->siteService->getList();

        // Do we use the locales as our entry, or do we use the site?
        if ($this->useLocales($sites)) {
            foreach ($sites as $site) {
                foreach ($site->getLocales() as $locale) {
                    if ($this->checkPermissions($locale)) {
                        $entry = new LocaleEntry($locale);
                        if ($selectedTree && $entry->getSiteTreeID() == $selectedTree->getSiteTreeID()) {
                            $entry->setIsSelected(true);
                        }
                        $collection->addEntry($entry);
                    }
                }
            }
        } else {
            foreach ($sites as $site) {
                if ($this->checkPermissions($site)) {
                    $entry = new SiteEntry($site);
                    if ($selectedTree && $entry->getSiteTreeID() == $selectedTree->getSiteTreeID()) {
                        $entry->setIsSelected(true);
                    }
                    $collection->addEntry($entry);
                }
            }
        }

        if ($this->useGroups($sites)) {
            foreach ($sites as $site) {
                $collection->addEntryGroup(new SiteGroup($site));
            }
        }

        return $collection;
    }
1164014
public function select2Place(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $page  = (int) $request->get('page');
        $query = $request->get('q', '');

        return response($this->placeSearch($tree, $page, $query, true));
    }
1045118
public function setParentInstance(SiteTree $parent)
    {
        $this->parentInstance = $parent;
        
        $this->setStyleIDFrom($parent);
        
        return $this;
    }
1130030
public static function recursiveConfigurableTree(array &$tree, array $available_config, array $current_config = []) {
    $subtree = ['#available_config' => $available_config];

    foreach ($available_config as $id => $config) {
      $subtree_available_config = $available_config;
      unset($subtree_available_config[$id]);

      foreach ($config['values'] as $option) {
        $value = $option['value_id'];
        $subtree_current_config = array_merge($current_config, [$id => $value]);

        if (count($subtree_available_config) > 0) {
          $subtree["$id:$value"] = Configurable::recursiveConfigurableTree(
            $tree,
            $subtree_available_config,
            $subtree_current_config
          );
        }
        else {
          $subtree["$id:$value"] = Configurable::findProductInTreeWithConfig(
            $tree,
            $subtree_current_config
          );
        }
      }
    }

    return $subtree;
  }
823009
function cachedTemplateTree( $keyData, $uri, $res, $templatePath, &$extraParameters, $timestamp )
    {
        $key = $this->cacheKey( $keyData, $res, $templatePath, $extraParameters );
        if ( eZTemplateTreeCache::canRestoreCache( $key, $timestamp, $templatePath ) )
            eZTemplateTreeCache::restoreCache( $key, $templatePath );
        return eZTemplateTreeCache::cachedTree( $key, $uri, $res, $templatePath, $extraParameters );
    }
1014242
public function fillTreeNodes($tree)
    {
        $ids = $this->getIdsForTree($tree);

        /** @var array $nodes_array */
        $nodes_array = $this->findBy(['id' => $ids]);

        $nodes = [];

        foreach ($nodes_array as $nodes_array_item) {
            /* @var $nodes_array_item \Compo\Sonata\AdminBundle\Entity\IdEntityTrait */
            $nodes[$nodes_array_item->getId()] = $nodes_array_item;
        }

        $tree = $this->fillTreeNodesForItems($tree, $nodes);

        return $tree;
    }
275927
public function listMenu(Tree $tree): ?Menu
    {
        if ($this->listIsEmpty($tree)) {
            return null;
        }
        
        return new Menu(
            $this->listTitle(),
            $this->listUrl($tree),
            $this->listMenuClass(),
            $this->listUrlAttributes()
        );
    }
410855
protected function calendarDayMenu(Tree $tree): Menu
    {
        return new Menu(I18N::translate('Day'), route('calendar', [
            'view' => 'day',
            'ged'  => $tree->name(),
        ]), 'menu-calendar-day', ['rel' => 'nofollow']);
    }
363562
private function wizardStepExport(Tree $tree): ResponseInterface
    {
        // We store the data in PHP temporary storage.
        $stream = fopen('php://temp', 'wb+');

        if ($stream === false) {
            throw new RuntimeException('Failed to create temporary stream');
        }

        $filename = $tree->name() . date('-Y-m-d') . '.ged';

        if ($this->filesystem->has($filename)) {
            $this->filesystem->delete($filename);
        }

        $tree->exportGedcom($stream);
        fseek($stream, 0);
        $this->filesystem->writeStream($tree->name() . date('-Y-m-d') . '.ged', $stream);
        fclose($stream);

        return response(view('components/alert-success', [
            'alert' => I18N::translate('The family tree has been exported to %s.', e($filename)),
        ]));
    }
921455
public function treePageUpdate(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $defaults = (bool) $request->get('defaults');

        if ($defaults) {
            $main_blocks = $this->treeBlocks(-1, 'main')->all();
            $side_blocks = $this->treeBlocks(-1, 'side')->all();
        } else {
            $main_blocks = (array) $request->get('main');
            $side_blocks = (array) $request->get('side');
        }

        $this->updateTreeBlocks($tree->id(), $main_blocks, $side_blocks);

        return redirect(route('tree-page', ['ged' => $tree->name()]));
    }
948965
protected function buildTree(array $simpleTree, $tree = [])
    {
        foreach ($simpleTree as $item) {
            if (!isset($this->collection[$item['id']])) {
                continue;
            }

            $content = $this->collection[$item['id']];

            unset($this->collection[$item['id']]); // TODO Fix multi-usage of single item

            if (isset($item['__children']) && count($item['__children'])) {
                $content['__children'] = $this->buildTree($item['__children']);
            } else {
                $content['__children'] = [];
            }

            $tree[] = $content;
        }

        return $tree;
    }
143338
private function findOption(array $pathOption, array $tree)
    {
        $idOption = array_shift($pathOption);
        if (sizeof($pathOption) > 0) {
            $localTree  = $tree[$idOption]['children'];
            $option     = $this->findOption($pathOption, $localTree);
        } else {
            $option     = $tree[$idOption];
        }
        return $option;
    }
1309298
public static function add($route){
      if (is_a($route, 'Route')){

        // Add to tag map
        if ($route->tag) static::$tags[$route->tag] =& $route;

        // Optimize tree
        if (Options::get('core.route.auto_optimize', true)){
          $base =& static::$optimized_tree;
          foreach (explode('/',trim(preg_replace('#^(.+?)\(?:.+$#','$1',$route->URLPattern),'/')) as $segment) {
            $segment = trim($segment,'(');
            if (!isset($base[$segment])) $base[$segment] = [];
            $base =& $base[$segment];
          }
          $base[] =& $route;
        }
      }

      // Add route to active group
      if ( isset(static::$group[0]) ) static::$group[0]->add($route);

      return static::$routes[implode('', static::$prefix)][] = $route;
    }
1223614
private function recursiveSort(&$tree)
    {
        //execute sort
        usort(
            $tree,
            function ($a, $b) {
                if ($a[$this->config['sort_key']] == $b[$this->config['sort_key']]) {
                    return 0;
                }

                return ($a[$this->config['sort_key']] < $b[$this->config['sort_key']]) ? -1 : 1;
            }
        );

        foreach ($tree as &$t) {
            if (array_key_exists($this->config['childs'], $t) && $t[$this->config['childs']] != '') {
                $t[$this->config['childs']] = $this->recursiveSort($t[$this->config['childs']]);
            }
        }

        return $tree;
    }
1113798
func (res *Resource) RouteTree() string {
	var routes string

	for _, route := range res.Routes {
		routes = strings.Join([]string{routes, route}, "\n")
	}

	return routes
}