From 276079b32eeeaacc154f22c545da8386cd3dbc52 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 24 Sep 2017 17:52:05 -0400 Subject: mq_tab_seek(): New function --- (limited to 'src/tab.c') diff --git a/src/tab.c b/src/tab.c index 458b56d..1fdd2ee 100644 --- a/src/tab.c +++ b/src/tab.c @@ -375,3 +375,25 @@ mq_tab_update_position(MqTab *tab, guint position) tab->position = position; update_tab_label(tab); } + +MqTab * +mq_tab_seek(MqTab *node, guint position) +{ + /* Skip forward to the containing subtree. */ + while (node && node->position + node->tree_size <= position) { + node->next; + } + + /* Check whether we've gone past the end of the tree. */ + if (!node) { + return NULL; + } + + /* Check whether the sibling we've reached is the node we want. */ + if (node->position == position) { + return node; + } + + /* Recurse down the subtree. */ + return mq_tab_seek(node->first_child, position); +} -- cgit v0.9.1