diff options
author | Piotr HaĆaczkiewicz <piotr.halaczkiewicz@gmail.com> | 2013-07-22 22:50:45 +0200 |
---|---|---|
committer | Piotr HaĆaczkiewicz <piotr.halaczkiewicz@gmail.com> | 2013-07-22 22:50:45 +0200 |
commit | c0c254f14d0d65a8b7ec50720ed8d98b5a04919a (patch) | |
tree | 0fc26c057880491c12358a6cc9d0f37d15155dc3 /src/common/cbasetypes.h | |
parent | 0b63deefd251a06b50a333facd6ad0e099e942b2 (diff) | |
download | hercules-c0c254f14d0d65a8b7ec50720ed8d98b5a04919a.tar.gz hercules-c0c254f14d0d65a8b7ec50720ed8d98b5a04919a.tar.bz2 hercules-c0c254f14d0d65a8b7ec50720ed8d98b5a04919a.tar.xz hercules-c0c254f14d0d65a8b7ec50720ed8d98b5a04919a.zip |
Binary heap fix & improvement.
Fixed a bug when removing last element of binary heap (its parent would
be removed instead if it had the same value).
Binary heap now allows custom swapper function/macro. Added `swap_ptr`
macro to swap two pointers in place (`swap` is not suitable for
pointers). This allows to store pointers in binary heap.
Diffstat (limited to 'src/common/cbasetypes.h')
-rw-r--r-- | src/common/cbasetypes.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index bfe8bf8f8..82ca9df69 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -300,6 +300,8 @@ typedef char bool; #endif #endif +#define swap_ptr(a,b) if ((a) != (b)) ((a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)), (b) = (void*)((intptr_t)(a) ^ (intptr_t)(b)), (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b))) + #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif |