Fix: add missing heap_copy
authorJulien Desfossez <jdesfossez@efficios.com>
Tue, 24 Jul 2012 15:54:02 +0000 (11:54 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 24 Jul 2012 15:54:02 +0000 (11:54 -0400)
This function allows the user to copy an existing priority heap.
It is required to fix the seek by position.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/babeltrace/prio_heap.h
lib/prio_heap/prio_heap.c

index b3e2491e519b9be5e86409b54f89a3985397cafb..347a2ced5fa302482878fd75160c0aa61c17c1b4 100644 (file)
@@ -114,4 +114,13 @@ extern void *heap_cherrypick(struct ptr_heap *heap, void *p);
  */
 extern void *heap_replace_max(struct ptr_heap *heap, void *p);
 
+/**
+ * heap_copy - copy a heap
+ * @dst: the destination heap (must be allocated)
+ * @src: the source heap
+ *
+ * Returns -ENOMEM if out of memory.
+ */
+extern int heap_copy(struct ptr_heap *dst, struct ptr_heap *src);
+
 #endif /* _BABELTRACE_PRIO_HEAP_H */
index a37e64c89542d10f017f8da835e01272dab2e2ef..092f0095f874844d58ba5460b16b31eadfddd3ff 100644 (file)
@@ -214,3 +214,21 @@ found:
        heapify(heap, pos);
        return p;
 }
+
+int heap_copy(struct ptr_heap *dst, struct ptr_heap *src)
+{
+       int ret;
+
+       ret = heap_init(dst, src->alloc_len, src->gt);
+       if (ret < 0)
+               goto end;
+
+       ret = heap_set_len(dst, src->len);
+       if (ret < 0)
+               goto end;
+
+       memcpy(dst->ptrs, src->ptrs, src->len * sizeof(void *));
+
+end:
+       return ret;
+}
This page took 0.024916 seconds and 4 git commands to generate.