wp_find_hierarchy_loop_tortoise_hare


wp_find_hierarchy_loop_tortoise_hare ( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false )

Access:
  • private
Parameters:
  • (callable) $callback Function that accepts ( ID, callback_arg, ... ) and outputs parent_ID.
  • (int) $start The ID to start the loop check at.
  • (array) $override Optional. An array of ( ID => parent_ID, ... ) to use instead of $callback. Default empty array.
  • (array) $callback_args Optional. Additional arguments to send to $callback. Default empty array.
  • (bool) $_return_loop Optional. Return loop members or just detect presence of loop? Only set to true if you already know the given $start is part of a loop (otherwise the returned array might include branches). Default false.
Returns:
  • (mixed) Scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if $_return_loop
Defined at:

Description

Use the "The Tortoise and the Hare" algorithm to detect loops.

For every step of the algorithm, the hare takes two steps and the tortoise one. If the hare ever laps the tortoise, there must be a loop.

Related Functions

wp_find_hierarchy_loop, wp_check_term_hierarchy_for_loops, wp_check_post_hierarchy_for_loops, _wp_ajax_add_hierarchical_term, wp_privacy_exports_url

Top Google Results

User discussions

wpseek mobile