function panels_extra_layouts_adaptive_hash in Panels Extra Layouts 7.2
Same name and namespace in other branches
- 6 panels_extra_layouts.module \panels_extra_layouts_adaptive_hash()
- 7 panels_extra_layouts.module \panels_extra_layouts_adaptive_hash()
Adaptive hash function.
The hashing function is quite simple, hence imperfect. There are some exceptions that are handled below to make the way the grid is filled consistent.
h(i) = \sum_{i}_{j = 1,n} get_digit(c(i,j))
where i is the row number, j is the column number, c(i,j) is the content of entry (i,j) of the content matrix and get_digit is a function that returns m given a number nm, e.g., 41, returns 1.
Parameters
array $indexes: The indexes of a given row of the content array.
int $columns: The number of columns in the current 'submatrix'.
string $mapper_f: The mapper function name.
Return value
int The hash of a given row.
2 calls to panels_extra_layouts_adaptive_hash()
- four-three-adaptive.tpl.php in plugins/
layouts/ four_three_adaptive/ four-three-adaptive.tpl.php - four-three-adaptive.tpl.php @author António P. P. Almeida <appa@perusio.net> @date Tue Dec 18 09:29:00 2012
- three-four-adaptive.tpl.php in plugins/
layouts/ three_four_adaptive/ three-four-adaptive.tpl.php - three-four-adaptive.tpl.php @author António P. P. Almeida <appa@perusio.net> @date Tue Dec 18 09:29:00 2012
File
- ./
panels_extra_layouts.module, line 65 - panels_extra_layouts.module @author António P. P. Almeida <appa@perusio.net> @date Wed Aug 3 04:36:20 2011
Code
function panels_extra_layouts_adaptive_hash($indexes = array(), $columns = 3, $mapper_f) {
// Bail out if there are no elements.
if (empty($indexes)) {
return 0;
}
// Count the number of elements in the given row.
$n = count($indexes);
// Compute the hash.
$h = $n == 1 ? 1 : array_sum(array_map($mapper_f, $indexes));
// For 4 columns there are a couple of special cases where the hash is
// ambiguous.
if ($h != 0 && $columns == 4) {
// If we are in a special situation correct it. The hashing function is
// quite naive. It's the sum of the column indexes in each row.
// Some cases we get an incorrect value that needs to be corrected.
if ($n == 2 && $h == 6) {
return 4;
}
if ($n == 2 && ($h == 7 || $h == 5 && panels_extra_layouts_adaptive_get_digit($indexes[1]) == 3)) {
return 3;
}
}
// panels_extra_layouts_adaptive_hash.
return $h;
}