Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #34847

Re: Rosetta Code: Top rank per group

Newsgroups comp.lang.forth
Date 2014-12-08 16:43 -0800
References <77e31dd1-7692-4ef6-83b7-8f2fe3cb7957@googlegroups.com>
Message-ID <f7ed596e-a72d-4e9f-bcc7-82fc6037498f@googlegroups.com> (permalink)
Subject Re: Rosetta Code: Top rank per group
From hughaguilar96@gmail.com

Show all headers | View raw


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.

Note that I have SPLIT that converts comma-deliminated strings into lists of fields. This works for any deliminator, so it can first break up the comma-deliminated strings into a list, and then break up the name field into a sublist of first-name and last-name. Also, it allows text to be in quotes, so everything in the quotes will be considered a field even if it contains the delimiter.

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.

Actually, implementing a basic binary tree with insert and delete is a lot of work too, if it has to be done from scratch for every program. 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!"

Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: Rosetta Code: Top rank per group hughaguilar96@gmail.com - 2014-12-08 16:43 -0800
  Re: Rosetta Code: Top rank per group Melzzzzz <mel@zzzzz.com> - 2014-12-09 05:08 +0100
    Re: Rosetta Code: Top rank per group hughaguilar96@gmail.com - 2014-12-09 21:43 -0800
      Re: Rosetta Code: Top rank per group hughaguilar96@gmail.com - 2014-12-09 21:55 -0800
        Re: Rosetta Code: Top rank per group november.nihal@gmail.com - 2014-12-10 03:40 -0800
          Re: Rosetta Code: Top rank per group hughaguilar96@gmail.com - 2014-12-11 19:15 -0800
            Re: Rosetta Code: Top rank per group hughaguilar96@gmail.com - 2014-12-13 09:11 -0800
              Re: Rosetta Code: Top rank per group "WJ" <w_a_x_man@yahoo.com> - 2014-12-15 06:08 +0000
              Re: Rosetta Code: Top rank per group "WJ" <w_a_x_man@yahoo.com> - 2014-12-17 02:50 +0000
                Re: Rosetta Code: Top rank per group hughaguilar96@gmail.com - 2014-12-18 22:06 -0800
                Re: Rosetta Code: Top rank per group hughaguilar96@gmail.com - 2014-12-21 17:14 -0800
                Re: Rosetta Code: Top rank per group Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-12-22 10:27 +0000
                Re: Rosetta Code: Top rank per group hughaguilar96@gmail.com - 2014-12-22 22:03 -0800
                Re: Rosetta Code: Top rank per group hughaguilar96@gmail.com - 2015-01-08 17:17 -0800
                Re: Rosetta Code: Top rank per group Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2015-01-09 09:56 +0000
                Re: Rosetta Code: Top rank per group hughaguilar96@gmail.com - 2015-03-16 19:11 -0700
                Re: Rosetta Code: Top rank per group "WJ" <w_a_x_man@yahoo.com> - 2014-12-24 05:25 +0000
  Re: Rosetta Code: Top rank per group mix <mix@test.net> - 2014-12-14 11:55 +0000
    Re: Rosetta Code: Top rank per group empty-buffers <empty.buffersYOU-DONT-WANT-THIS@gmail.NEITHER-THIS.com> - 2014-12-14 13:52 +0000
  Re: Rosetta Code: Top rank per group mix <mix@test.net> - 2014-12-14 11:58 +0000

csiph-web