/** * Clips trie branches at the first null node in a walk. This method is used to * determine the cache levels to invalidate during delete operations. * * BEFORE: A --> B -> C AFTER: A --> B -> C * |-> * -> E |-> D * |-> D -> * * * @version 1.0 * @since 1.0 * * @param array $trie | Trie structure * * @param array $columns | Array of column names * * @param array $ctrl | Control args * => VAL @param string $null_token | String to use as null token * * @return array | Exception on failure. Clipped trie structure on success. */ public static function clipAssocTrie($trie, $columns, $ctrl = null) { $ctrl_default = array('null_token' => '*'); $ctrl = FOX_sUtil::parseArgs($ctrl, $ctrl_default); try { $cls = new FOX_trie_clip($trie, $columns, $ctrl); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 1, 'text' => "Error creating iterator object", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => $child)); } try { $result = $cls->render(); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 2, 'text' => "Error rendering to array", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => $child)); } return $result; }
function test_trie_clip_06() { $columns = array("C1", "C2", "C3", "C4", "C5"); $trie = array('*' => true, 'K' => array('X' => array('V' => array('K' => array('K' => true, 'W' => true), '*' => array('T' => true)), '*' => array('Z' => array('*' => true))), 'Y' => array('K' => array('*' => array('K' => true, 'W' => true), 'T' => array('*' => true)), 'Z' => array('Z' => array('Z' => true))))); try { $cls = new FOX_trie_clip($trie, $columns, $ctrl = null); } catch (FOX_exception $child) { $this->fail($child->dumpString(1)); } try { $result = $cls->render(); } catch (FOX_exception $child) { $this->fail($child->dumpString(1)); } // Reduces to the universal set $check = array(); $this->assertEquals($check, $result); }