Now using 2 spaces instead of tabs. Fix copyright years. Improve documentation
[cgds.git] / src / Heap.h
index c17cb73..e360829 100644 (file)
  * @brief Generic d-ary heap.
  */
 typedef struct Heap {
-       size_t dataSize; ///< Size of a heap item in bytes.
-       OrderType hType; ///< Type of heap: max first (MAX_T) or min first (MIN_T).
-       UInt arity; ///< Arity of the underlying tree.
-       Vector* array; ///< Vector of ItemValue* (internal representation).
+  size_t dataSize; ///< Size of a heap item in bytes.
+  OrderType hType; ///< Type of heap: max first (MAX_T) or min first (MIN_T).
+  UInt arity; ///< Arity of the underlying tree.
+  Vector* array; ///< Vector of ItemValue* (internal representation).
 } Heap;
 
 /**
  * @brief Return an allocated and initialized heap.
  */
 Heap* _heap_new(
-       size_t dataSize, ///< Size in bytes of a heap element.
-       OrderType hType, ///< Type of heap: max first (MAX_T) or min first (MIN_T).
-       UInt arity ///< Arity of the underlying tree.
+  size_t dataSize, ///< Size in bytes of a heap element.
+  OrderType hType, ///< Type of heap: max first (MAX_T) or min first (MIN_T).
+  UInt arity ///< Arity of the underlying tree.
 );
 
 /**
@@ -40,27 +40,29 @@ Heap* _heap_new(
  * Usage: Heap* heap_new(<Type> type, OrderType hType, UInt arity)
  */
 #define heap_new(type, hType, arity) \
-       _heap_new(sizeof(type), hType, arity)
+{ \
+  _heap_new(sizeof(type), hType, arity); \
+}
 
 /**
  * @brief Copy constructor (shallow copy, ok for basic types).
  */
 Heap* heap_copy(
-       Heap* heap ///< "this" pointer.
+  Heap* heap ///< "this" pointer.
 );
 
 /**
  * @brief Check if the heap is empty.
  */
 bool heap_empty(
-       Heap* heap ///< "this" pointer.
+  Heap* heap ///< "this" pointer.
 );
 
 /**
  * @brief Return the size of current heap.
  */
 UInt heap_size(
-       Heap* heap ///< "this" pointer.
+  Heap* heap ///< "this" pointer.
 );
 
 /**
@@ -68,8 +70,8 @@ UInt heap_size(
  * in O(log(n)) operations.
  */
 void _heap_bubble_up(
-       Heap* heap, ///< "this" pointer.
-       UInt startIndex ///< Index to bubble up.
+  Heap* heap, ///< "this" pointer.
+  UInt startIndex ///< Index to bubble up.
 );
 
 /**
@@ -77,17 +79,17 @@ void _heap_bubble_up(
  * in O(log(n)) operations.
  */
 void _heap_bubble_down(
-       Heap* heap, ///< "this" pointer.
-       UInt startIndex ///< Index to bubble down.
+  Heap* heap, ///< "this" pointer.
+  UInt startIndex ///< Index to bubble down.
 );
 
 /**
  * @brief Insert a pair (item,value) inside the heap.
  */
 void _heap_insert(
-       Heap* heap, ///< "this" pointer.
-       void* item, ///< Pointer to an item of type as defined in the constructor.
-       Real value ///< Value associated with the item.
+  Heap* heap, ///< "this" pointer.
+  void* item, ///< Pointer to an item of type as defined in the constructor.
+  Real value ///< Value associated with the item.
 );
 
 /**
@@ -100,17 +102,17 @@ void _heap_insert(
  */
 #define heap_insert(heap, item, value) \
 { \
-       typeof((item)) tmp = item; \
-       _heap_insert(heap, &tmp, value); \
+  typeof((item)) tmp = item; \
+  _heap_insert(heap, &tmp, value); \
 }
 
 /**
  * @brief Change the value of an item at a given index.
  */
 void _heap_modify(
-       Heap* heap, ///< "this" pointer.
-       UInt index, ///< Index of the item to modify.
-       Real newValue ///< New value for the item.
+  Heap* heap, ///< "this" pointer.
+  UInt index, ///< Index of the item to modify.
+  Real newValue ///< New value for the item.
 );
 
 /**
@@ -121,26 +123,27 @@ void _heap_modify(
  * @note If several similar items are present, only the first is affected.
  *
  * Usage: void heap_modify(Heap* heap, void item_, Real newValue)
+ *
  * WARNING: does not work if items are not basic type nor pointers.
  */
 #define heap_modify(heap, item_, newValue) \
 { \
-    UInt index = 0; \
-       typeof((item_)) item__ = item_; \
-    for (; index<heap->array->size; index++) \
-       { \
-               void* pItem = ((ItemValue*)(heap->array->datas[index]))->item; \
-        if (*((typeof(&item__))pItem) == item__) break; \
-    } \
-       _heap_modify(heap, index, newValue); \
+  UInt index = 0; \
+  typeof((item_)) item__ = item_; \
+  for (; index<heap->array->size; index++) \
+  { \
+    void* pItem = ((ItemValue*)(heap->array->datas[index]))->item; \
+    if (*((typeof(&item__))pItem) == item__) break; \
+  } \
+  _heap_modify(heap, index, newValue); \
 }
 
 /**
  * @brief Remove an item-value at a given index.
  */
 void _heap_remove(
-       Heap* heap, ///< "this" pointer.
-       UInt index  ///< Index of the item to remove.
+  Heap* heap, ///< "this" pointer.
+  UInt index  ///< Index of the item to remove.
 );
 
 /**
@@ -150,25 +153,26 @@ void _heap_remove(
  * @note If several similar items are present, only the first is deleted.
  *
  * Usage: void heap_remove(Heap* heap, void item_)
+ *
  * WARNING: does not work if items are not basic type nor pointers.
  */
 #define heap_remove(heap, item_) \
 { \
-    UInt index = 0; \
-       typeof((item_)) item__ = item_; \
-    for (; index<heap->array->size; index++) \
-       { \
-               void* pItem = ((ItemValue*)(heap->array->datas[index]))->item; \
-        if (*((typeof(&item__))pItem) == item__) break; \
-    } \
-       _heap_remove(heap, index); \
+  UInt index = 0; \
+  typeof((item_)) item__ = item_; \
+  for (; index<heap->array->size; index++) \
+  { \
+    void* pItem = ((ItemValue*)(heap->array->datas[index]))->item; \
+    if (*((typeof(&item__))pItem) == item__) break; \
+  } \
+  _heap_remove(heap, index); \
 }
 
 /**
  * @brief Return what is at the beginning of the heap.
  */
 ItemValue* heap_top_raw(
-       Heap* heap ///< "this" pointer.
+  Heap* heap ///< "this" pointer.
 );
 
 /**
@@ -180,29 +184,29 @@ ItemValue* heap_top_raw(
  */
 #define heap_top(heap, item_) \
 { \
-       void* pItem = heap_top_raw(heap)->item; \
-       item_ = *((typeof(&item_))pItem); \
+  void* pItem = heap_top_raw(heap)->item; \
+  item_ = *((typeof(&item_))pItem); \
 }
 
 /**
  * @brief Remove the top of the heap.
  */
 void heap_pop(
-       Heap* heap ///< "this" pointer.
+  Heap* heap ///< "this" pointer.
 );
 
 /**
  * @brief Clear the entire heap.
  */
 void heap_clear(
-       Heap* heap ///< "this" pointer.
+  Heap* heap ///< "this" pointer.
 );
 
 /**
  * @brief Destroy the heap: clear it, and free 'heap' pointer.
  */
 void heap_destroy(
-       Heap* heap ///< "this" pointer.
+  Heap* heap ///< "this" pointer.
 );
 
 #endif