Closed erjiaqing closed 6 years ago
Hey. is it meld similar to merge? because if it is then we the tricky part is to make it work with all implementations. For example:
So we have different signatures unless we have a generic node type we can use.
How to merge two heaps is quite tricky, and different heaps use different node structure.
I have read some articles, the meld operation seems to be similar to merge. It seems that after c = meld(a, b), and we should not use the old heap a and b anymore.
So I think the a.Meld(b) operation should do the following things:
In this case, we do not have to use a generic node type.
Heap a = old heap a + old heap b after merge. and Heap b = empty heap after merge.
Sounds good
Meld is added with this commit https://github.com/theodesp/go-heaps/commit/d25b436491812d3dcc2e672ba4336ddc7075149d
Many heaps supports the meld operation in O(log n) or even O(1) time complexity, and some heaps are designed for fast meld operation.