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>
*/
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 */
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;
+}