This repository was archived by the owner on Jul 17, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -357,6 +357,7 @@ bot.Command = function ( cmd ) {
357
357
cmd . del = function ( ) {
358
358
bot . info . forgotten += 1 ;
359
359
delete bot . commands [ cmd . name ] ;
360
+ bot . commandDictionary . trie . del ( cmd . name ) ;
360
361
} ;
361
362
362
363
return cmd ;
Original file line number Diff line number Diff line change @@ -22,6 +22,24 @@ TrieNode.prototype.add = function( word ) {
22
22
node . word = word ;
23
23
} ;
24
24
25
+ TrieNode . prototype . del = function ( word , i ) {
26
+ i = i || 0 ;
27
+ var node = this ;
28
+ var char = word [ i ++ ] ;
29
+
30
+ // recursively delete all trie nodes that are left empty after removing the command from the leaf
31
+ if ( node . children [ char ] ) {
32
+ node . children [ char ] . del ( word , i ) ;
33
+ if ( Object . keys ( node . children [ char ] . children ) . length === 0 && node . children [ char ] . word === null ) {
34
+ delete node . children [ char ] ;
35
+ }
36
+ }
37
+
38
+ if ( node . word === word ) {
39
+ node . word = null ;
40
+ }
41
+ }
42
+
25
43
//Having a small maxCost will increase performance greatly, experiment with
26
44
//values of 1-3
27
45
function SuggestionDictionary ( maxCost ) {
You can’t perform that action at this time.
0 commit comments