Quick question
Closed this issue · 1 comments
As a data structure that might need to support a huge amount of popping, why is the priority queue a struct
? I'm asking since--to my knowledge--the mutating functions will create a new priority queue every time they're called. Or is it optimized away?
I originally wrote it as a class. @dapenggao did a really nice refactor that included making it a struct. He rightly pointed out that most Swift data structures are value types (aka structs) including Array and Dictionary. I do not believe a mutating function will create a new struct every time it is called. If that were the case, Array and Dictionary would be very non-performant. That said, I would be interested in seeing performance tests of SwiftPriorityQueue as both a class and a struct. You could either look at an earlier version (while it was still a class) on GitHub or the changes to go from struct to class in it are actually very small.