mDict = array(); $this->mContainer = array(); } public function parase($words,$value) { foreach (mb_str_split($words) as $word) { if(filter::filter($word)) { $this->add($word,$value); } } $this->mContainer[$value] = $words; } protected function add($key,$value) { if(isset($this->mDict[$key])) { $datas = &$this->mDict[$key]; if(algorithm::binary_search($datas,$value) == false) { $pos = algorithm::lower_bonud($datas,$value); algorithm::array_insert($datas,$pos,$value); } } else { $this->mDict[$key] = array($value); } } public function find($key) { if(isset($this->mDict[$key])) { return $this->mDict[$key]; } else { return array(); } } public function name($val) { if(isset($this->mContainer[$val])) { return $this->mContainer[$val]; } else { return false; } } } class one_multi { private $mContainer; public function __construct() { $this->mContainer = array(); } public function add($key,$val) { if(isset($this->mContainer[$key])) { $values = &$this->mContainer[$key]; if(algorithm::binary_search($values,$val) == false) { $pos = algorithm::lower_bonud($values,$val); algorithm::array_insert($values,$pos,$val); } } else { $this->mContainer[$key] = []; $this->mContainer[$key][] = $val; } } public function get($key) { if(isset($this->mContainer[$key])) { return $this->mContainer[$key]; } else { return array(); } } } class one_one { private $mContainer; public function __construct() { $this->mContainer = array(); } public function add($key,$val) { $this->mContainer[$key] = $val; } public function get($key) { if(isset($this->mContainer[$key])) { return $this->mContainer[$key]; } else { return false; } } } class array_tree { private $mTree; public function __construct() { $this->mTree = []; } public function add($id,$pid) { $id = intval($id); $pid = intval($pid); if(isset($this->mTree[$pid]) == false) { $this->mTree[$pid] = []; $this->mTree[$pid]['pid'] = 0; $this->mTree[$pid]['subids'] = []; $this->mTree[$pid]['subids'][] = $id; } else { $sub_ids = &$this->mTree[$pid]['subids']; $this->add_sub($sub_ids,$id); } if(isset($this->mTree[$id]) == false) { $this->mTree[$id] = []; $this->mTree[$id]['pid'] = $pid; $this->mTree[$id]['subids'] = []; } } private function add_sub(&$values,$val) { if(algorithm::binary_search($values,$val) == false) { $pos = algorithm::lower_bonud($values,$val); algorithm::array_insert($values,$pos,$val); } } public function is_parent($hot) { if (isset($this->mTree[$hot]) == false) { return false; } return (count($this->mTree[$hot]['subids']) > 0); } public function subs($hot) { if (isset($this->mTree[$hot]) == false) { return array(); } return $this->mTree[$hot]['subids']; } }