heap: heap size and obj-by-index helpers
authorMarko Kreen <markokr@gmail.com>
Mon, 22 Nov 2010 22:33:00 +0000 (00:33 +0200)
committerMarko Kreen <markokr@gmail.com>
Mon, 22 Nov 2010 22:37:59 +0000 (00:37 +0200)
usual/heap.c
usual/heap.h

index c84679adae049e78563c7731f3aa3a3e858f2098..bf047df87bcbe109c2f3f2b72dd9b05509f08997 100644 (file)
@@ -198,3 +198,15 @@ void *heap_pop(struct Heap *h)
        return heap_remove(h, 0);
 }
 
+unsigned heap_size(struct Heap *h)
+{
+       return h->used;
+}
+
+void *heap_get_obj(struct Heap *h, unsigned pos)
+{
+       if (pos < h->used)
+               return h->data[pos];
+       return NULL;
+}
+
index 44a3ceb2f9b0c896499355076ab6f930fbea8829..03ee265a48e5587b9ac5cc5aed28a2ca1262d4bf 100644 (file)
@@ -92,5 +92,12 @@ void *heap_remove(struct Heap *h, unsigned pos);
  */
 bool heap_reserve(struct Heap *h, unsigned extra);
 
+
+/** Return number of objects in heap */
+unsigned heap_size(struct Heap *h);
+
+/* Return object by index, for testing */
+void *heap_get_obj(struct Heap *h, unsigned pos);
+
 #endif