Gladiator
Explore posts from servers❔ 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?
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
4 replies
❔ Generally, how do you implement a readonly struct?
Hi. Generally, how do you implement a readonly struct? I mean define readonly fields or getter?
What is the difference? What about defensive copy?
Suppose that struct type contains primitive value types like int, float and also other struct types
2 replies
Is there any reason why comparing struct types with null does not result in compile error?
When comparing struct types with null, it is always false. So, why doesn't the compiler throw compilation error?
When and where do we want to compare struct types with null?! never because it is a logical bug
26 replies
❔ Task.WhenAll does not work without Task.Run inside
Inside a task,
_pathFinder.FindPath
is not called.
returnFirstPath
is false (Task.WhenAll)
but if I change list.Add(new Task<PathResult>(action));
to list.Add(Task.Run(action));
, it works.
Another question, I should use Task.Run to be sure it runs in different threads and get results faster?
95 replies
Why are Linq methods incomplete? (MinBy, MaxBy, etc.) [Answered]
There is no method to return object by field which is minimum/maximum. I know I can use Aggregate method but it is weird to me Min/Max linq methods does not return the object itself
15 replies
❔ Separating struct array data
Is it worth separating fields of array data (struct array) into different data structures so that cache hit count increases? Because the struct size reduces and more elements of the array can be cached
When I say separation I mean smart separation (relevant data in a struct)
7 replies
❔ Using concurrent collections to add or remove elements for in-memory collections (server)?
Should we use concurrent collections to add/remove elements to/from in-memory collections in asp.net?
For example adding/removing players in online player list
13 replies