list hash

Apr. 4th, 2002 01:58 pm
liralen: Finch Painting (Default)
[personal profile] liralen
Okay... so my boss has a hash of lists that includes a hash as one member of that list. That hash is of lists that also include a reference to a list. Now I need to get that last list to actually be made, instead of scalars, of another list of hashes that key to a bunch of lists...

whee...

This is hurting my brain.

Date: 2002-04-04 02:17 pm (UTC)
From: [identity profile] srakkt.livejournal.com
I suppose it's best to simply be happy that it's not recursive...

Date: 2002-04-08 11:27 am (UTC)
From: [identity profile] liralen.livejournal.com
Hee.

Well, actually recursion has made the filling in of the layered structures a much easier piece of code to understand, stand-alone.

It's just the whole wrapping of code that I didn't write around a seven-dimensional problem that's hurting my brain[

Date: 2002-04-04 05:42 pm (UTC)
From: [identity profile] zamiel.livejournal.com
So, we're talking, really, about an associative array that points its indices to lists associated with them. One of the indices is, itself, a list.

I think I see what the core problem is, here: you have a associative index that's a mutable. That's just a straight up design no-no (in part, because you have to rehash on any change of the index list). I'm hoping that I'm misunderstanding the problem, because if Perl lets you do that, my opinion of it will drop even lower than its current "mitachondria of shit-eating dung beetles" level.

Date: 2002-04-04 05:50 pm (UTC)
From: [identity profile] elthar.livejournal.com
No, no, the *index* isn't a list, the target is.

Date: 2002-04-04 06:00 pm (UTC)
From: [identity profile] zamiel.livejournal.com
Oh, then that shouldn't be a problem at all.

OK, in a real language. [smirk]

Seriously, its just an associative array; walking that kind of structure should be a total no brainer as long as you just keep a separate reference to the index and what it points to.

Date: 2002-04-08 08:41 am (UTC)
From: [identity profile] liralen.livejournal.com
Ah. Sorry, my language was imprecise. Keys to the hashes cannot be references, and aren't mutable, and when I actually say that a hash has a list in it, it actually has a key associated to a reference to a list/array...

So it's actually a hash with a string key that associates to a reference to an array. The array (which could just be thought of as an object if my boss had been object oriented instead of perl-oriented) has a reference to another hash that keys off a string that is associated to a reference to an array. That array, presently, is just an array of strings, which is nice, but I'm just having to munge it up by making it an array of references to yet another hash of string keys associated to a reference of arrays.

I actually kind of like the fact that I can use a hash/library/keyed index that is mutable, i.e. I can stuff things into it whenever I want to and query by keys when I need to as I'm having to parse a file to figure out what the new members even might be. I can think in objects when I think of them as objects that happen to have references to other objects, in order to represent what's presently a four dimensional array of possibliites which I have to expand to seven. It's translating what was originally a pretty tough problem into a language I don't know was what was hurting my brain, I think.

Date: 2002-04-08 12:24 pm (UTC)
From: [identity profile] zamiel.livejournal.com
OK, so a hash in your terminology is, essentially, what everyone else calls an associative array, Python calls a dictionary, Erlang refers to an an "ets" (Erlang Term Storage), and Chris Osaki has thirty different fuctional implimentations of. ;) (Yes, this is the danger of knowing too many languages ...)

So, what you have looks vaguely like this:

Image


In most languages I deal with on any regular basis, one ends up conflating the Array and Hash idea; Python Dictionaries are associative arrays that can point off at each other, like so:
X = {'item': 'value'}
Y = {'thing': 'value2}
Y = {1: X, 2: Y}

And then you can access them like so:
print Y[1]['item']
=> value

... if you wanted to refer down the whole chain. Of course, you could use full-bore objects at any step down the chain (which are really represented behind the scenes as a Dictionary, internally, regardless).

Dictionaries and their kin are wonderful, wonderful tools that let you do scary things like count the number of occurances of an item in a file in linear time and other such goodies. I dig 'em. :)

Date: 2002-04-08 02:17 pm (UTC)
From: [identity profile] liralen.livejournal.com
Yay! Yes!!

Exactly. I originally got at dictionaries through SmallTalk and, yes, the hashes are exactly that. I like 'em, yum! It's just getting my brain around someone else's code in an unfamiliar language that's been mildly hairy.

Date: 2002-04-08 04:46 pm (UTC)
From: [identity profile] zamiel.livejournal.com
[chuckles] You get used to it, given enough time. See if your guy'll buy you a copy of Chris Osaki's Fully Functional Data Structures for your next excuse to get presents; its brain-stretching, but well worth the effort.

Fully functional red/black and b-trees, yum ...

March 2025

S M T W T F S
      1
2345678
910 1112131415
16171819202122
23242526272829
3031     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 19th, 2026 05:51 pm
Powered by Dreamwidth Studios