~ubuntu-branches/ubuntu/maverick/transmission/maverick

« back to all changes in this revision

Viewing changes to third-party/libevent/min_heap.h

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Klimonda
  • Date: 2009-05-22 21:57:30 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (2.1.18 sid) (1.3.8 upstream)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20090522215730-ly5kgv5aw9ig2u82
Tags: upstream-1.61
ImportĀ upstreamĀ versionĀ 1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
{
87
87
    if(((unsigned int)-1) != e->min_heap_idx)
88
88
    {
89
 
        min_heap_shift_down_(s, e->min_heap_idx, s->p[--s->n]);
 
89
        struct event *last = s->p[--s->n];
 
90
        unsigned parent = (e->min_heap_idx - 1) / 2;
 
91
        /* we replace e with the last element in the heap.  We might need to
 
92
           shift it upward if it is less than its parent, or downward if it is
 
93
           greater than one or both its children. Since the children are known
 
94
           to be less than the parent, it can't need to shift both up and
 
95
           down. */
 
96
        if (e->min_heap_idx > 0 && min_heap_elem_greater(s->p[parent], last))
 
97
             min_heap_shift_up_(s, e->min_heap_idx, last);
 
98
        else
 
99
             min_heap_shift_down_(s, e->min_heap_idx, last);
90
100
        e->min_heap_idx = -1;
91
101
        return 0;
92
102
    }