[ruby-core:124507] [Ruby Feature#21821] Add Stack and SizedStack classes
Issue #21821 has been updated by Eregon (Benoit Daloze). ko1 (Koichi Sasada) wrote in #note-4:
* If we assume the implementation of `Queue` is based on `Dequeu`, adding `pop_back()` (LIFO operation) seems reasonalbe, and easy to introduce than introducing new classes, and good aligned to Ruby's large-class philosophy. I want to ask Matz again.
This would make the implementation of Queue (based on Deque or not) far more complicated and less efficient, as I said in the last paragraph of https://bugs.ruby-lang.org/issues/21721#note-2. I think we should either: * Add nothing because this is not a common need and there are 2 reasonable alternatives: https://bugs.ruby-lang.org/issues/21721#note-2 and https://bugs.ruby-lang.org/issues/21721#note-18 * Add Thread::Stack & Thread::SizedStack. I think it's not good to alias them in `Object` because they should not be used if the stack is used by a single Thread, Array should be used instead.
I'm afraid that expanding the similar idea like `Thread::Heap`, `Thread::PriorityQueue` and so on, atomic containers for each data structure.
Yes, it starts to feel like Java. I think there are not enough use cases for concurrent stacks to deserve to be core. It could be in concurrent-ruby perhaps, or maybe the 2 alternatives linked above are good enough. ---------------------------------------- Feature #21821: Add Stack and SizedStack classes https://bugs.ruby-lang.org/issues/21821#change-116067 * Author: byroot (Jean Boussier) * Status: Open * Target version: 4.1 ---------------------------------------- ### Context `Queue` and `SizedQueue` are very useful and performant constructs, however they only allow for FIFO queues. Some use cases do call for LIFO queues AKA stacks. For instance, in the case of connection pool, it's often preferable to use a stack. ### Feature I'd like to introduce `Stack` and `SizedStack` classes, to mirror `Queue` and `SizedQueue`. They'd have exactly the same method and behavior at the exception of dequeuing order. ### Thread namespace? Currently `Queue` and `SizedQueue` are technically defined under `Thread` and aliased in `Object`. I wonder if that's something we should do for `Stack` too, or just some historical thing we shouldn't perpetuate. -- https://bugs.ruby-lang.org/
participants (1)
-
Eregon (Benoit Daloze)