C
C#2y ago
Gladiator

❔ Exists a node in priority queue or not (O(1)) with value type nodes

In reference types, it is OK. There is an array of a struct type(Element) and I would like to swap some elements in it. Each element keeps its index as well. Outside, an element of that array has been stored in a variable for example. Because it is value type, when swapping elements of the array and update index field, it does not reflect it, what is your idea?
public struct Element{
//...
public int Index;
}
public struct Element{
//...
public int Index;
}
var el = elements[10];
var el = elements[10];
swap element(10) with element(5) and update index field inside. Now, index in el is not updated because it is value type My original situation is priority queue implemented for value types. I keep index of nodes inside nodes. When the positions of those nodes change (heapify up/down), indices change. Now, suppose I have kept a node of the priority queue in a variable. So, the index is wrong and obsolete I want to know if a node exists in a priority queue or not (O(1)) but with value type nodes not ref types and then update the priority value for that node
3 Replies
sibber
sibber2y ago
Because it is value type, when swapping elements of the array and update index field, it does not reflect it, what is your idea?
wdym by this
realivanjxツ
realivanjxツ2y ago
what is your idea?
modify the Index before swapping the elements
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server