-/* $Id$ */
-
/* a generic and efficient heap */
-/* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
+/* Copyright (c) 2004, 2005, 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
*
* Creates a new heap.
*/
-XBT_INLINE xbt_heap_t xbt_heap_new(int init_size, void_f_pvoid_t const free_func)
+XBT_INLINE xbt_heap_t xbt_heap_new(int init_size,
+ void_f_pvoid_t const free_func)
{
xbt_heap_t H = xbt_new0(struct xbt_heap, 1);
H->size = init_size;
* \param update_callback function to call on each element to update its index when needed.
*/
XBT_INLINE void xbt_heap_set_update_callback(xbt_heap_t H,
- void (*update_callback) (void *, int))
+ void (*update_callback) (void
+ *,
+ int))
{
H->update_callback = update_callback;
}
if (count > size) {
H->size = 2 * size + 1;
H->items =
- (void *) realloc(H->items, (H->size) * sizeof(struct xbt_heapItem));
+ (void *) realloc(H->items,
+ (H->size) * sizeof(struct xbt_heapItem));
}
item = &(H->items[count - 1]);
if (H->count < H->size / 4 && H->size > 16) {
H->size = H->size / 2 + 1;
H->items =
- (void *) realloc(H->items, (H->size) * sizeof(struct xbt_heapItem));
+ (void *) realloc(H->items,
+ (H->size) * sizeof(struct xbt_heapItem));
}
- H->update_callback ? H->update_callback(max, -1) : NULL;
+ if (H->update_callback)
+ H->update_callback(max, -1);
return max;
}
struct xbt_heapItem tmp = H->items[i];
H->items[i] = H->items[greatest];
H->items[greatest] = tmp;
- H->update_callback ? H->update_callback(CONTENT(H, i), i) : NULL;
+ if (H->update_callback)
+ H->update_callback(CONTENT(H, i), i);
i = greatest;
} else {
- H->update_callback ? H->update_callback(CONTENT(H, i), i) : NULL;
+ if (H->update_callback)
+ H->update_callback(CONTENT(H, i), i);
return;
}
}
struct xbt_heapItem tmp = H->items[i];
H->items[i] = H->items[PARENT(i)];
H->items[PARENT(i)] = tmp;
- H->update_callback ? H->update_callback(CONTENT(H, i), i) : NULL;
+ if (H->update_callback)
+ H->update_callback(CONTENT(H, i), i);
i = PARENT(i);
}
- H->update_callback ? H->update_callback(CONTENT(H, i), i) : NULL;
+ if (H->update_callback)
+ H->update_callback(CONTENT(H, i), i);
return;
}
-