Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Array object sorted on time, how to deal with. Date: Tue, 23 Nov 2021 11:22:36 +0000 Organization: A noiseless patient Spider Lines: 31 Message-ID: <878rxff75v.fsf@bsb.me.uk> References: <571380ac-a926-4bf2-88b2-a8a49b77a1bdn@googlegroups.com> <5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com> <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="8eb52a1cb63455e5c0003813e8c7219d"; logging-data="15959"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TibK1r1kVxOYTmaCBCO36Vo4B6z5hsKQ=" Cancel-Lock: sha1:O7cbYzHovbF/SENsH4Slbt3UsXY= sha1:J2uPf2WxknWEncQNLzQPZO2yaZo= X-BSB-Auth: 1.55eca9fb9167b6301ec2.20211123112236GMT.878rxff75v.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:40552 luserdroog writes: > With a priority queue, at least the ones I looked at, when you create the > queue you pass an ordering function to the constructor. It uses that function > to figure out how to keep your data in order without knowing anything else > about your data. So you can fill it with records and it'll keep everything in > a sorted order, you just have to tell it how to sort 2 of your things. For an abstract priority queue (in the strictest sense) you don't need to keep the queue sorted. I went on the write "In fact, one common implementation uses a heap, as in heap sort" but then I looked at your link and that uses a heap! I would not say that the data in a heap are in sorted order, though it's almost a philosophical point. However, if you need this: > //then when you click play, you can get an array of everything > //in order and run through converting each note to midi events. > > function getNotesArray(){ > return notesQueue.toArray() > } Then it might pay (depending on how the notes are generated) to maintain a sorted array. But why is a sorted array needed? Can't whatever uses this queue simply pull the notes off one at a time? -- Ben.