Move gtree_node_find_version, and g_tree_root_find_version up, so that the navigation...
authorDana Jansens <danakj@orodu.net>
Fri, 30 Oct 2009 21:57:42 +0000 (17:57 -0400)
committerDana Jansens <danakj@orodu.net>
Thu, 12 Nov 2009 21:54:05 +0000 (16:54 -0500)
glib/gtree.c

index 6a8e1ef3fd0082910a07cbe6d16852a2308d1748..072dab516ff5ecb23ecdad7561ce8658e9cd05d5 100644 (file)
@@ -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.