Does Go has out of the box priority queue? -
does go has out of box priority queue (the 1 can import module , start using python's priority queue)?
i know priority queues implemented using heap data structure , go has heap package, suggests how use implement queue (in example (priorityqueue) ), can grab , use.
my question recommended way this, or there out of box priority queue package failed find?
quoting wikipedia:
a priority queue abstract data type regular queue or stack data structure, additionally each element has "priority" associated it. [...] while priority queues implemented heaps, conceptually distinct heaps. priority queue abstract concept "a list" or "a map";
go provides basic data structures used in applications leave implementation of more specialized data structures programmer. example, go map can used trivially implement set.
the example link uses slice []*item
represent more abstract type heap.interface
, (even more abstract) type priorityqueue
. go composition , implementing priorityqueue
in terms of heap operations practice.
this gives control programmer. if want thread safety, use composition of priorityqueue
, sync.mutex
make thread safe. if want different implementation heap, make priorityqueue
interface , can implement want.
of course there's trade-off. in case, implementation ~25 lines of code. if implementation hundreds of lines you'd want find package has done already.
Comments
Post a Comment