[gnome-builder] egg-heap: Various fixes and cleanups
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] egg-heap: Various fixes and cleanups
- Date: Wed, 13 May 2015 01:45:41 +0000 (UTC)
commit 5b59e9a87f3e5e9c57f56fdbcd3378b44275c277
Author: Garrett Regier <garrettregier gmail com>
Date: Tue May 12 18:45:27 2015 -0700
egg-heap: Various fixes and cleanups
contrib/egg/egg-heap.c | 128 +++++++++++++++++++++++-------------------------
1 files changed, 61 insertions(+), 67 deletions(-)
---
diff --git a/contrib/egg/egg-heap.c b/contrib/egg/egg-heap.c
index 0dde013..027de1c 100644
--- a/contrib/egg/egg-heap.c
+++ b/contrib/egg/egg-heap.c
@@ -236,7 +236,6 @@ egg_heap_extract (EggHeap *heap,
gpointer result)
{
EggHeapReal *real = (EggHeapReal *)heap;
- gboolean ret;
gint ipos;
gint lpos;
gint rpos;
@@ -244,48 +243,46 @@ egg_heap_extract (EggHeap *heap,
g_return_val_if_fail (heap, FALSE);
- ret = (real->len > 0);
+ if (real->len == 0)
+ return FALSE;
- if (ret)
+ if (result)
+ memcpy (result, heap_index (real, 0), real->element_size);
+
+ if (--real->len > 0)
{
- if (result)
- memcpy (result, heap_index (real, 0), real->element_size);
+ memmove (real->data,
+ heap_index (real, real->len),
+ real->element_size);
+
+ ipos = 0;
- if (real->len && --real->len)
+ while (TRUE)
{
- memmove (real->data,
- heap_index (real, real->len),
- real->element_size);
+ lpos = heap_left (ipos);
+ rpos = heap_right (ipos);
- ipos = 0;
+ if ((lpos < real->len) && (heap_compare (real, lpos, ipos) > 0))
+ mpos = lpos;
+ else
+ mpos = ipos;
- while (TRUE)
- {
- lpos = heap_left (ipos);
- rpos = heap_right (ipos);
+ if ((rpos < real->len) && (heap_compare (real, rpos, mpos) > 0))
+ mpos = rpos;
- if ((lpos < real->len) && (heap_compare (real, lpos, ipos) > 0))
- mpos = lpos;
- else
- mpos = ipos;
+ if (mpos == ipos)
+ break;
- if ((rpos < real->len) && (heap_compare (real, rpos, mpos) > 0))
- mpos = rpos;
-
- if (mpos == ipos)
- break;
-
- heap_swap (real, mpos, ipos);
+ heap_swap (real, mpos, ipos);
- ipos = mpos;
- }
+ ipos = mpos;
}
}
- if ((real->len >= MIN_HEAP_SIZE) && (real->allocated_len / 2) >= real->len)
+ if ((real->len > MIN_HEAP_SIZE) && (real->allocated_len / 2) >= real->len)
egg_heap_real_shrink (real);
- return ret;
+ return TRUE;
}
gboolean
@@ -294,7 +291,6 @@ egg_heap_extract_index (EggHeap *heap,
gpointer result)
{
EggHeapReal *real = (EggHeapReal *)heap;
- gboolean ret;
gint ipos;
gint lpos;
gint mpos;
@@ -303,59 +299,57 @@ egg_heap_extract_index (EggHeap *heap,
g_return_val_if_fail (heap, FALSE);
- ret = (real->len > 0);
+ if (real->len == 0)
+ return FALSE;
- if (real->len)
- {
- if (result)
- memcpy (result, heap_index (real, 0), real->element_size);
+ if (result)
+ memcpy (result, heap_index (real, index_), real->element_size);
- real->len--;
+ real->len--;
- if (real->len && index_ != real->len)
- {
- memcpy (heap_index (real, index_),
- heap_index (real, real->len),
- real->element_size);
+ if (real->len && index_ != real->len)
+ {
+ memcpy (heap_index (real, index_),
+ heap_index (real, real->len),
+ real->element_size);
- ipos = index_;
- ppos = heap_parent (ipos);
+ ipos = index_;
+ ppos = heap_parent (ipos);
- while (heap_compare (real, ipos, ppos) > 0)
- {
- heap_swap (real, ipos, ppos);
- ipos = ppos;
- ppos = heap_parent (ppos);
- }
+ while (heap_compare (real, ipos, ppos) > 0)
+ {
+ heap_swap (real, ipos, ppos);
+ ipos = ppos;
+ ppos = heap_parent (ppos);
+ }
- if (ipos == index_)
+ if (ipos == index_)
+ {
+ while (TRUE)
{
- while (TRUE)
- {
- lpos = heap_left (ipos);
- rpos = heap_right (ipos);
+ lpos = heap_left (ipos);
+ rpos = heap_right (ipos);
- if ((lpos < real->len) && (heap_compare (real, lpos, ipos) > 0))
- mpos = lpos;
- else
- mpos = ipos;
+ if ((lpos < real->len) && (heap_compare (real, lpos, ipos) > 0))
+ mpos = lpos;
+ else
+ mpos = ipos;
- if ((rpos < real->len) && (heap_compare (real, rpos, mpos) > 0))
- mpos = rpos;
+ if ((rpos < real->len) && (heap_compare (real, rpos, mpos) > 0))
+ mpos = rpos;
- if (mpos == ipos)
- break;
+ if (mpos == ipos)
+ break;
- heap_swap (real, mpos, ipos);
+ heap_swap (real, mpos, ipos);
- ipos = mpos;
- }
+ ipos = mpos;
}
}
}
- if ((real->len >= MIN_HEAP_SIZE) && (real->allocated_len / 2) >= real->len)
+ if ((real->len > MIN_HEAP_SIZE) && (real->allocated_len / 2) >= real->len)
egg_heap_real_shrink (real);
- return ret;
+ return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]