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 +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -1017,6 +1017,7 @@ bot.Command = function ( cmd ) {
1017
1017
cmd . del = function ( ) {
1018
1018
bot . info . forgotten += 1 ;
1019
1019
delete bot . commands [ cmd . name ] ;
1020
+ bot . commandDictionary . trie . del ( cmd . name ) ;
1020
1021
} ;
1021
1022
1022
1023
return cmd ;
@@ -1539,6 +1540,24 @@ TrieNode.prototype.add = function( word ) {
1539
1540
node . word = word ;
1540
1541
} ;
1541
1542
1543
+ TrieNode . prototype . del = function ( word , i ) {
1544
+ i = i || 0 ;
1545
+ var node = this ;
1546
+ var char = word [ i ++ ] ;
1547
+
1548
+ // recursively delete all trie nodes that are left empty after removing the command from the leaf
1549
+ if ( node . children [ char ] ) {
1550
+ node . children [ char ] . del ( word , i ) ;
1551
+ if ( Object . keys ( node . children [ char ] . children ) . length === 0 && node . children [ char ] . word === null ) {
1552
+ delete node . children [ char ] ;
1553
+ }
1554
+ }
1555
+
1556
+ if ( node . word === word ) {
1557
+ node . word = null ;
1558
+ }
1559
+ }
1560
+
1542
1561
//Having a small maxCost will increase performance greatly, experiment with
1543
1562
//values of 1-3
1544
1563
function SuggestionDictionary ( maxCost ) {
You can’t perform that action at this time.
0 commit comments