这是我的场景,我想要一些聪明的解决方案来解决这个问题。
我有 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 元素如何与条目元素保持关联? 我认为,您在这里使用了错误的数据结构。
关于java - 如何更新优先级队列中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29314406/