# Maintain min-Heap together with another vector

**URL:** https://discourse.julialang.org/t/maintain-min-heap-together-with-another-vector/59604
**Category:** General Usage
**Created:** [April 19, 2021, 6:46pm UTC](https://discourse.julialang.org/t/maintain-min-heap-together-with-another-vector/59604 "2021-04-19T18:46:37Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Rouzaire](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rouzaire](https://discourse.julialang.org/u/Rouzaire)
#### Post date: [April 19, 2021, 6:46pm UTC](https://discourse.julialang.org/t/maintain-min-heap-together-with-another-vector/59604/1 "2021-04-19T18:46:37Z")

</div>

Hello everyone,

I have a 2D matrix of 2 rows and n columns.  
The first row represents a distance (type : Float \> 0).  
The second row represents an ID (type : Integer \> 0) corresponding to the distance above.

First question : it is possible to maintain a min-heap from DataStructures.jl with the first row (distances), while sorting the bottom row accordingly ; I basically need a sortperm function for min-Heaps. Does it exist ? I haven’t found it in the doc [Heaps · DataStructures.jl](https://juliacollections.github.io/DataStructures.jl/latest/heaps/).

Second question : I also need to be able to delete an entry in my heap based on the ID, while of course keeping the min-heap property. Any idea on how to do so ?

Example :  
Initially, we could have such a matrix (distance in top row, ID in bottom row)  
5 | 1 | 3  
1 | 2 | 3

Sorting with respect to row1 could lead to :  
1 | 5 | 3  
2 | 1 | 3

Then deleting the entry with ID “2” would lead to : (note how min-heap property is eventually satisfied)  
3 | 5  
3 | 1

Hope this is clear !  
Does anyone have any suggestions ? maybe I’m thinking the wrong way, there might be a workaround  
Thank you very much in advance.
