Skip to content

Commit 02ae0d0

Browse files
committed
add deltree feature.
1 parent 6133869 commit 02ae0d0

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
- 支持在树梢增加自定义数组 [替换内容]
99
- 性能提升10倍
1010
- v3.0
11-
- 增加删除特性
11+
- 增加删除特性
12+
- 删除整棵关键词树
1213
- 解决命中不全BUG
1314

1415
## 示例
@@ -37,8 +38,8 @@ var_dump($res);
3738

3839
//删除
3940
$res = $tree->delete("张三");
40-
$res = $tree->search("张三");
41-
var_dump($res);
41+
//删除整棵树 连带“张三”和张三下的“张三四”一并删除
42+
$tree->delete("张三",true);
4243
```
4344

4445
## 使用场景

src/TrieTree.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct() {
2929
* 从树种摘除一个文本
3030
* @param $str
3131
*/
32-
public function delete($str) {
32+
public function delete($str,$deltree=false) {
3333
$str = trim($str);
3434
$delstr_arr = $this->_convertStrToH($str);
3535
$len = count($delstr_arr);
@@ -57,6 +57,11 @@ public function delete($str) {
5757
}
5858
}
5959
$idx = $len - 1;
60+
//删除整棵树
61+
if($deltree){
62+
//清空子集
63+
$del_index[$idx]['index']['child']=array();
64+
}
6065
//只有一个字 直接删除
6166
if ($idx == 0) {
6267
if (count($del_index[$idx]['index']['child']) == 0) {

0 commit comments

Comments
 (0)