From 2fa568c628f5a66c5ca2cb8ef79528a1b4287080 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Mon, 26 Nov 2018 21:27:29 +0000 Subject: binds: Add imv_binds_clear_key --- src/binds.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/binds.c') diff --git a/src/binds.c b/src/binds.c index 9e268b4..3408ad9 100644 --- a/src/binds.c +++ b/src/binds.c @@ -130,6 +130,30 @@ void imv_binds_clear(struct imv_binds *binds) init_bind_node(&binds->bind_tree); } +void imv_binds_clear_key(struct imv_binds *binds, const struct list *keys) +{ + struct bind_node *node = &binds->bind_tree; + + for(size_t i = 0; i < keys->len; ++i) { + /* Traverse the trie to find the right node for the input keys */ + int child_index = list_find(node->suffixes, &compare_node_key, keys->items[i]); + if(child_index == -1) { + /* No such node, no more work to do */ + return; + } else { + node = node->suffixes->items[child_index]; + } + } + + /* We've now found the correct node for the input */ + + /* Clear the commands for this node */ + if(node->commands) { + list_deep_free(node->commands); + node->commands = NULL; + } +} + enum lookup_result { LOOKUP_PARTIAL, LOOKUP_INVALID, -- cgit v1.2.3