You are here

function _crumbs_admin_find_ideal_length in Crumbs, the Breadcrumbs suite 7

Same name and namespace in other branches
  1. 6.2 crumbs.admin.inc \_crumbs_admin_find_ideal_length()

This algorithm is copied 1:1 from blockadminlight

1 call to _crumbs_admin_find_ideal_length()
_crumbs_build_default_text in admin/crumbs.admin.inc

File

admin/crumbs.admin.inc, line 173

Code

function _crumbs_admin_find_ideal_length(array $key_lengths, $factor = 30) {
  sort($key_lengths, SORT_NUMERIC);
  $n = count($key_lengths);
  $length = 0;
  $best_length = 0;
  $cost = $n * $factor;
  $best_cost = $cost;
  for ($i = 0; $i < $n; ++$i) {
    $increment = $key_lengths[$i] - $length;
    $length = $key_lengths[$i];
    $cost += $i * $increment;
    $cost -= $factor;
    if ($cost < $best_cost) {
      $best_cost = $cost;
      $best_length = $length;
    }
  }
  return $best_length;
}