From 7e4aa92f67707b2978302c181bda294b103d1f15 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 30 Oct 2009 17:57:42 -0400 Subject: [PATCH] Move gtree_node_find_version, and g_tree_root_find_version up, so that the navigation functions can use them soon. --- glib/gtree.c | 110 +++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/glib/gtree.c b/glib/gtree.c index 6a8e1ef3..072dab51 100644 --- a/glib/gtree.c +++ b/glib/gtree.c @@ -253,6 +253,61 @@ g_tree_new_full (GCompareDataFunc key_compare_func, return tree; } +/* finds the largest version in the array, that is <= the query version */ +static inline GTreeRootVersion * +g_tree_root_find_version (GTree *tree, + guint version) +{ + GTreeRootVersion *const v = tree->roots; + const guint nv = tree->nroots; + GTreeRootVersion *l, *r; + + /* note: we never search for a version smaller than the smallest + version in the array */ + + if (v[0].version <= version) + return v; + + l = v+1; + r = v+(nv-1); + while (l <= r) /* binary search */ + { + GTreeRootVersion *const m = l + (r - l) / 2; + if (version == m->version) + return m; + else if (version < m->version) + r = m-1; + else + l = m+1; + } + g_assert (r->version < version); + g_assert (l->version > version); + return r; +} + +static inline GTreeNodeVersion * +g_tree_node_find_version(GTreeNode *node, + guint version) +{ + GTreeNodeVersion *const v = node->v; + const guint nv = node->nv; + GTreeNodeVersion *n; + + /* note: we never search for a version smaller than the smallest + version in the array */ + + if (v[0].version <= version) + return v; + + /* there are at most MAX_IN_DEGREE+1 things to look through, which is small, + so just scan through them from largest version to smallest */ + for (n = v+(nv-1); n != v; --n) + if (n->version <= version) + break; + g_assert (n != v); + return n; +} + static inline GTreeNode * g_tree_first_node (GTree *tree) { @@ -525,61 +580,6 @@ g_tree_node_next_version (GTree *tree, } } -/* finds the largest version in the array, that is <= the query version */ -static inline GTreeRootVersion * -g_tree_root_find_version (GTree *tree, - guint version) -{ - GTreeRootVersion *const v = tree->roots; - const guint nv = tree->nroots; - GTreeRootVersion *l, *r; - - /* note: we never search for a version smaller than the smallest - version in the array */ - - if (v[0].version <= version) - return v; - - l = v+1; - r = v+(nv-1); - while (l <= r) /* binary search */ - { - GTreeRootVersion *const m = l + (r - l) / 2; - if (version == m->version) - return m; - else if (version < m->version) - r = m-1; - else - l = m+1; - } - g_assert (r->version < version); - g_assert (l->version > version); - return r; -} - -static inline GTreeNodeVersion * -g_tree_node_find_version(GTreeNode *node, - guint version) -{ - GTreeNodeVersion *const v = node->v; - const guint nv = node->nv; - GTreeNodeVersion *n; - - /* note: we never search for a version smaller than the smallest - version in the array */ - - if (v[0].version <= version) - return v; - - /* there are at most MAX_IN_DEGREE+1 things to look through, which is small, - so just scan through them from largest version to smallest */ - for (n = v+(nv-1); n != v; --n) - if (n->version <= version) - break; - g_assert (n != v); - return n; -} - /** * g_tree_insert: * @tree: a #GTree. -- 2.34.1