laminas-stdlib icon indicating copy to clipboard operation
laminas-stdlib copied to clipboard

`PriorityQueue::toArray` does not return items in prioritized order

Open boesing opened this issue 4 years ago • 3 comments

Feature Request

Q A
New Feature yes
RFC no
BC Break yes

Summary

I've recently used the PriorityQueue and realized, that PriorityQueue::toArray does not return items in prioritized order. Is that intended and if so, why? I switched to iterator_to_array instead but I wonder for what PriorityQueue::toArray is for.

Feedback welcome.

boesing avatar Mar 03 '21 09:03 boesing

@weierophinney

Can you shed any light on this?

I'm currently trying to get through #102 for a future v4 so it'd be a good time to change this behaviour if it no longer makes sense.

gsteel avatar Sep 13 '23 22:09 gsteel

@gsteel The docblock specifically notes that it's not returned in priority order:

     * By default, returns only the item data, and in the order registered (not
     * sorted). You may provide one of the EXTR_* flags as an argument, allowing
     * the ability to return priorities or both data and priority.

I honestly do not recall why I wrote it like that; I mean, it was 13 years ago! But based on the implementation, I think the main idea around the method was primarily to allow serialization of the data, optionally with priorities. But it does seem that the data should be in priority order, regardless of the flags provided, as deserialization should return the data in the order it is meant to be iterated. I'd totally support that change.

weierophinney avatar Sep 14 '23 14:09 weierophinney

Yah I would expect the correct order as well. I mean, thats why we even add priorities in the first place 😬

boesing avatar Sep 14 '23 14:09 boesing