Commit 7c6203e2 authored by Pekka Pessi's avatar Pekka Pessi

heap.h: using su_smoothsort()

darcs-hash:20070704225134-65a35-c2072c906a0ccac2820862ffb3fb2f3f3cce0dd7.gz
parent ee11b023
......@@ -114,6 +114,7 @@ scope int prefix##free(void *, heaptype *); \
scope int prefix##is_full(heaptype const); \
scope size_t prefix##size(heaptype const); \
scope size_t prefix##used(heaptype const); \
scope void prefix##sort(heaptype); \
scope int prefix##add(heaptype, type); \
scope type prefix##remove(heaptype, size_t); \
scope type prefix##get(heaptype, size_t)
......@@ -126,6 +127,7 @@ scope type prefix##get(heaptype, size_t)
* - prefix ## is_full(heap)
* - prefix ## size(heap)
* - prefix ## used(heap)
* - prefix ## sort(heap)
* - prefix ## add(heap, entry)
* - prefix ## remove(heap, index)
* - prefix ## get(heap, index)
......@@ -307,6 +309,25 @@ size_t prefix##used(heaptype const h) \
struct prefix##priv *_priv = *(void **)&h; \
return _priv ? _priv->_used : 0; \
} \
scope int prefix##_less(void *h, size_t a, size_t b) \
{ \
type *_heap = h; return less(_heap[a], _heap[b]); \
} \
scope void prefix##_swap(void *h, size_t a, size_t b) \
{ \
type *_heap = h; type _swap = _heap[a]; \
set(_heap, a, _heap[b]); set(_heap, b, _swap); \
} \
void su_smoothsort(void *base, size_t r0, size_t N, \
int (*less)(void *base, size_t a, size_t b), \
void (*swap)(void *base, size_t a, size_t b)); \
scope void prefix##sort(heaptype h) \
{ \
struct prefix##priv { size_t _size, _used; type _heap[1];}; \
struct prefix##priv *_priv = *(void **)&h; \
if (_priv) \
su_smoothsort(_priv->_heap - 1, 1, _priv->_used, prefix##_less, prefix##_swap); \
} \
extern int const prefix##dummy_heap
#endif /** !defined(SOFIA_SIP_HEAP_H) */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment