Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #40553
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Array object sorted on time, how to deal with. |
| Date | 2021-11-23 12:23 +0000 |
| Organization | A little, after lunch |
| Message-ID | <snimfa$7p4$1@dont-email.me> (permalink) |
| References | (3 earlier) <5dccbec9-7025-455d-96ef-5f5bc1fa4fe8n@googlegroups.com> <58bcaa57-860b-472f-9870-73e6551e7a48n@googlegroups.com> <daf4b01a-066d-461f-8291-712fc31ac8d8n@googlegroups.com> <6ee13397-3a3f-4ad5-8d46-8f9eb85debd8n@googlegroups.com> <878rxff75v.fsf@bsb.me.uk> |
On 23/11/2021 11:22, Ben Bacarisse wrote:
> luserdroog <luser.droog@gmail.com> 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?
>
Haven't been following this, but when I want a sorted queue I use a
linked list.
add the new record wherever the allocation scheme puts it, walk te array
until you find the last element that goes before it, change that
elements link to pint at it and the new elements link to point where
that one used to go.
Of all the things I vaguely read up on when studying 'books on compSci'
this is one of the very few techniques I ended up using.
--
Renewable energy: Expensive solutions that don't work to a problem that
doesn't exist instituted by self legalising protection rackets that
don't protect, masquerading as public servants who don't serve the public.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Array object sorted on time, how to deal with. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-10-26 01:44 -0700
Re: Array object sorted on time, how to deal with. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-10-26 01:48 -0700
Re: Array object sorted on time, how to deal with. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-11-05 00:48 -0700
Re: Array object sorted on time, how to deal with. luserdroog <luser.droog@gmail.com> - 2021-11-19 17:59 -0800
Re: Array object sorted on time, how to deal with. luserdroog <luser.droog@gmail.com> - 2021-11-20 20:41 -0800
Re: Array object sorted on time, how to deal with. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-11-21 04:28 -0800
Re: Array object sorted on time, how to deal with. luserdroog <luser.droog@gmail.com> - 2021-11-22 20:36 -0800
Re: Array object sorted on time, how to deal with. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-11-23 11:22 +0000
Re: Array object sorted on time, how to deal with. The Natural Philosopher <tnp@invalid.invalid> - 2021-11-23 12:23 +0000
Re: Array object sorted on time, how to deal with. luserdroog <luser.droog@gmail.com> - 2021-11-25 18:05 -0800
Re: Array object sorted on time, how to deal with. John Harris <niam@jghnorth.org.uk.invalid> - 2021-11-26 18:18 +0000
Re: Array object sorted on time, how to deal with. luserdroog <luser.droog@gmail.com> - 2021-11-26 16:02 -0800
Re: Array object sorted on time, how to deal with. luserdroog <luser.droog@gmail.com> - 2021-11-25 18:17 -0800
Re: Array object sorted on time, how to deal with. Richard Damon <Richard@Damon-Family.org> - 2021-11-25 22:27 -0500
Re: Array object sorted on time, how to deal with. luserdroog <luser.droog@gmail.com> - 2021-11-25 20:14 -0800
Re: Array object sorted on time, how to deal with. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-11-25 21:02 -0800
Re: Array object sorted on time, how to deal with. luserdroog <luser.droog@gmail.com> - 2021-11-26 16:18 -0800
Re: Array object sorted on time, how to deal with. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-11-25 20:41 -0800
Re: Array object sorted on time, how to deal with. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-11-25 21:06 -0800
csiph-web