Log in

View Full Version : Hashes of Arrays, who'd have 'em


2mths
13-08-08, 03:26 PM
I just can't get my head round it :-(

Hashes of Arrays, Arrays of Arrays, references bah - bugger 'em all.

SoulKiss
13-08-08, 03:27 PM
*Sits back, gets some Popcorn and watches 2mths head explode"

Luckypants
13-08-08, 03:27 PM
Hash tables - ace! :D

Baph
13-08-08, 03:28 PM
Pish easy really. :)

Personal preference is to use the hash of an element as it's location ident, but still...

EDIT: Wait until you get a 3D array of pointers...

2mths
13-08-08, 03:29 PM
*******s the lot of you

Baph
13-08-08, 03:30 PM
*******s the lot of you
I didn't finish my edit, as each of the pointers could actually point to another array.

SK, can I have some popcorn please? :D

SoulKiss
13-08-08, 03:32 PM
*******s the lot of you

WoW - I would have thought only 4 stars would have been needed :)

Luckypants
13-08-08, 03:32 PM
*******s the lot of you

Boom! :D

EDIT: Now PMSL at SK's comment!

Grinch
13-08-08, 03:34 PM
Wait until you get a 3D array of pointers...

On the course I did this is the point my brain stopped working.

Baph
13-08-08, 03:35 PM
WoW - I would have thought only 4 stars would have been needed :)
It's a reference to the 4 letter word...

SoulKiss
13-08-08, 03:39 PM
It's a reference to the 4 letter word...

Of course, silly me - you want sweet, salt, natural or cheese popcorn ?

Baph
13-08-08, 03:45 PM
Of course, silly me - you want sweet, salt, natural or cheese popcorn ?

for (i=0; i<boxes.length; i++) if (boxes[i] == sweet) System.out.println("I'll take that one...");


Sorry 2mths, couldn't resist.

2mths
13-08-08, 04:20 PM
Hmm not entirely sure I understand what you're getting with that last Baph

For me it'd have been something like...

perl -e while (@boxes ) { if ($_ =~ /sw/) { print "$_ for me please!" } }

Or some such (there being a _lot_ of different ways you could approach that)

As for too many asterisk, I didn't but asterisks there and there were just enough to disguise something similar to bar stewards.

The 'thing' (graphing module) I'm trying to use requires that the plot data be fed to it as an array of arrays (I think). Said data is coming from a db query. So I'm trying to populate the different arrays on the fly. That took me long enough to work out. Then I realised that I needed another array containing my x-axis values. In trying that a) I broke what I had got working and b) my brain fell over so I swore at you lot and went home.

I could do what I need to do by writing a very namby pampy script which runs several queries and processes the output of each to prepare my data. But I'm trying to develop my scripting and write something a little more mature that does it in one go (trivial to some I'm sure).

Anyway I'm home now and about to kill some sprites in CoD4 till I feel better.

Baph
13-08-08, 04:23 PM
Hmm not entirely sure I understand what you're getting with that last Baph

For me it'd have been something like...

for ($i=0, $i<$totalSweets, $i++) {
Linguistic difference.

However, why bother looping around totalSweets? If you've named the variable properly, surely that's an array containing all boxes of sweet popcorn? Why not just treat it as a FIFO structure instead of looping?

Grinch
13-08-08, 04:26 PM
Pardon?

Filipe M.
13-08-08, 04:29 PM
Pardon?

Nothing to do with cake, don't worry.

2mths
13-08-08, 04:35 PM
Linguistic difference.

However, why bother looping around totalSweets? If you've named the variable properly, surely that's an array containing all boxes of sweet popcorn? Why not just treat it as a FIFO structure instead of looping?

I didn't mean to post what you saw - that was my first error. The second was misunderstanding what you were getting at, I subsequently worked out more of what you'd done by reading the quote of SK for some context.

No idea what about FIFO structures (I can work out what it stands for but that's not helping) so looping is all I've got.

timwilky
13-08-08, 04:38 PM
What is the problem, I cut my teeth coding assembly language on VAX computers many years ago. so multiple levels of indirection with offset etc. piece of ****.

You then get to c type pointer arrays, so effectively create multi dimensional arrays and multi size etc.

You them move into things like java collections and arrays etc. But now you no longer have those nice pointers that allowed you to do fancy tricks, like stepping through arrays etc using pointer arithmetic.

So explain what is doing your head in, and we will try to help.

but first read the manual young man, then read it again. there is nothing worse than getting somebody to show you how, because you will just not remember.

timwilky
13-08-08, 04:40 PM
BTW FIFO = first in first out, as opposed to last in first out etc.

Luckypants
13-08-08, 04:42 PM
BTW FIFO = first in first out, as opposed to last in first out etc.
AKA a queue to us oldies.

Baph
13-08-08, 04:44 PM
No idea what about FIFO structures (I can work out what it stands for but that's not helping) so looping is all I've got.
As you've worked out, FIFO == First In First Out. Basically, pick one end of the array to add things to, and only remove things from the other end of the array. Doesn't matter if this is the "bottom" of the array, but it's usually easier that way.


You them move into things like java collections and arrays etc. But now you no longer have those nice pointers that allowed you to do fancy tricks, like stepping through arrays etc using pointer arithmetic.


Java actually does support pointer arithmetic (as of Java 1.5). The only thing you can't do is uninitialise an object (though you can finalize() which is tantamount to the same thing really), and you can't deallocate memory.

Baph
13-08-08, 04:45 PM
Data set returned along line of...

Day Production Line Qty
2

So you have an array of arrays, the the outer being columns, the inner being specific row data?

2mths
13-08-08, 04:51 PM
Nah I posted again without meaning to (bloody annoying - not sure what I'm doing)

Basically at one point I wanted an Array of Arrays (for one type of graph), then changed my mind and went back to wanting a Hash of Arrays to produce separate graphs (by looping round the keys and using making a simple array of (2) arrays on each loop).

I've done a ****e job of explaining it, not helped my mis-posting twice. I'll look at it tomorrow.

Basically my problem is syntax and in there I'm not helped by not understanding things like references.

Baph
13-08-08, 05:09 PM
AKA a queue to us oldies.
Ah, but a specific queue. ;)

For example, Pringles are arranged into a "queue" - in that you have to get one (or a group) out first, but those you pull out were among the last in the container. ;)

timwilky
13-08-08, 06:47 PM
queues are nice things to work with when you start to add functionality to insert into queues, delete from queue, service the first member, last member etc.

You end up with structures that contain pointers to the previous member, next member of the queue, plus either a pointer to the data item or if a privative type that data item. In that way, you can end up coding a whole structure to implement stacks (simple push/pop) for a LIFO implementation. or your FIFO. You then need to build a good enumerator round it to efficiently walk the queue.

Mike, I think of a queue (from above), as more than a FIFO as there is a lot more you can do with it. my best analogy of a FIFO is in a pipe implementation, there is only two methods involved to insert something to the tail end of a pipe and extract something from the head end of the pipe.

Baph
Thanks for the heads up re pointer functionality of 1.5. I must admit I have not read the spec, and tend to still think 1.2/1.3 with some added extra class implementations