如何更新优先级队列中的位置

how to update locations in priority queue

本文关键字:队列 位置 优先级 何更新 更新      更新时间:2023-10-16

这是我的场景,我想要一些智能的解决方案来解决这个问题。

我有1024个位置,每个位置都与一个条目相关联。现在,我在已经存在的1024个位置的基础上添加了1024个位置。现在,我必须更新与旧1024个位置相关联的现有条目的位置。有没有什么聪明的方法可以在不遍历所有1024个条目的情况下做到这一点。

下面是场景。

location 0 associated to ==> entry 0
location 1 associated to ==> entry 1
location 2 associated to ==> entry 2
location 3 associated to ==> entry 3
.
.
.
.
location 1023 associated to ==> entry 1023

now i have added new 1024 locations on top. so i have to update the locations of entries as follow
location 0 new location
location 1 new location
location 2 new location
location 3 new location
location 4 new location
.
.
.
.
location 1024 associated to ==> entry 0
location 1025 associated to ==> entry 1
location 1026 associated to ==> entry 2
location 1027 associated to ==> entry 3
location 1028 associated to ==> entry 4
.
.
.
location 2047 associated to ==> entry 1023

要做到这一点,有没有任何方法可以做到这一步,而不需要一个接一个地循环所有条目并更新位置?

PriorityQueue元素如何与入口元素保持关联?我认为,您在这里使用了错误的数据结构。