Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!.POSTED!not-for-mail From: Melzzzzz Newsgroups: comp.lang.forth Subject: Re: Rosetta Code: Top rank per group Date: Tue, 9 Dec 2014 05:08:42 +0100 Organization: albasani.net Lines: 75 Message-ID: <20141209050842.1695200d@maxa-pc> References: <77e31dd1-7692-4ef6-83b7-8f2fe3cb7957@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net ka22ed4hmWq60IZP5ImeoQme7DGq9iTFvRN2aBYeoUMa+gx6l2JazFKiGqXntQtNVsyRDaHON290zsIxrSGBFQ== NNTP-Posting-Date: Tue, 9 Dec 2014 04:08:42 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="kjxNj/eeifFqZQeldCUlLKBrrEryWdh/62mRk2yjaSaulAXpiMXPPzNYmpBTxG5P+BnHrEKAx7oJr7y6GRD4zshd24JyjAZEJ9qvLwyjB+GCtmREEltvVOW55kHXHg7K"; mail-complaints-to="abuse@albasani.net" X-Newsreader: Claws Mail 3.11.0 (GTK+ 2.24.25; x86_64-unknown-linux-gnu) Cancel-Lock: sha1:oFtXgnYFVxRRtYCZK0J3JrF+GnE= Xref: csiph.com comp.lang.forth:34851 On Mon, 8 Dec 2014 16:43:22 -0800 (PST) hughaguilar96@gmail.com wrote: > On Wednesday, February 12, 2014 6:37:15 PM UTC-7, Julian Fondren > wrote: > > 1. brute-force the answer with high-level data structures: walk the > > table, adding departments as keys to a hash table, the values of > > which are lists of salaries. Once you've exhausted the table, sort > > the keys of the hash (for nice output) and then print them and > > their top N of the sorted lists of salaries. > > > > (If you've never used a Perl oneliner that you wrote in a minute to > > chew on multiple repquota streams and spit out the top > > diskspace-using users, then that I call this a 'good solution' may > > puzzle you.) > > A program like this is trivial using my ASSOCIATION.4TH in the novice > package: http://www.forth.org/novice.html > It uses an LLRB tree internally, and it allows associations (or > subsets of associations) to be traversed in order. I would just build > one association sorted by department, then for each department I > would build an association sorted by salary, then just dump out the > leftmost N nodes. For a real program that has a lot of data and has > to be robust, it would make more sense to build an association sorted > by name, and then build associations sorted by department, salary, > etc. in which the record is a pointer to a node in the main > association --- like a relational-database, this saves memory by not > replicating data. Hm, sounds complicated. SQL/Database is best for such tasks... You just have to send SQL command and that's all. Not worth a fuss... > > I don't think Rosetta Stone allows the use of libraries however --- > so it favors languages such as Perl that have data-structures built > in --- if the programmer has to implement all of these > data-structures from scratch as Elizabeth Rather demands her cult > members to do, the program is going to be huge and complicated. It > will also likely use an inefficient data-structure such as a basic > binary-tree rather than an LLRB tree, because implementing an LLRB > tree for a single program is way too much work. What's so good about LLRB tree? I think that classical RB tree performs better. Only advantage of LLRB is like AA tree ease of implementation, I guess... > > Actually, implementing a basic binary tree with insert and delete is > a lot of work too, Nope, not much of a code. It requires some thinking but nothing one cannot finish in couple of days. if it has to be done from scratch for every > program. One can write it once and use it in every other program. It is not necessary to write everytime one starts new program. Problem is that like C (which also doesn;t have standard container library) Forth is low level language and people can't agree on interface. This is why ANS-Forth is never used in commercial > programming --- implementing everything from scratch is just too much > work --- the boss expects a trivial program like this to be done in > an hour or two, and he will fire a programmer who spends a week on it > and then says: "Well, um, I'm bogged down in figuring out how LLRB > trees work, as they are quite complicated!" There is internet, but then again, there are programmers that make memory leaks in Java :p