Page 1 of 2
[Implemented] Associative Arrays
Posted: Fri Aug 29, 2003 11:50 pm
by Karbon
Bam. I know it's not a BASIC construct but I think it's the single most useful thing about PHP and other languages that have them as native variable types.
Anyway, just wanted to add that to the stack of feature requests

Posted: Sat Aug 30, 2003 6:41 am
by fsw
What is this
A short explanation would be nice.
Maybe this is something I needed for ages and didn't know about it 8O
Posted: Sat Aug 30, 2003 3:08 pm
by Master C
Data in associative arrays aren't called by an index, but by an keyword:
Normal array:
person(0)="John"
person(1)="Banner"
Associative array:
person("prename")="John"
person("lastname")="Banner"
Posted: Sat Aug 30, 2003 4:44 pm
by Inner
already can;
dim array.s(2)
#NAME=0
#SURNAME=1
array(0)="Inner"
array(1)="Space"
debug(array(#NAME))
debug(array(#SURNAME))
Or am I missing something ?
Posted: Sat Aug 30, 2003 9:20 pm
by Fred
It's so called 'HashMap' array, which has a key (basically a string) and a value. It's to have faster/easier data handling when your key can't be a sequential number
Code: Select all
a$ = "Book"
b$ = "Book2"
a(a$) = "Author1"
a(b$) = "Author2"
It heavily used in JAVA for example. I may introduce this kind of data storage later.
Posted: Sun Aug 31, 2003 2:21 am
by Karbon
Fred, excellent to hear!
Posted: Wed Mar 28, 2007 6:14 pm
by Karbon
Thread resurrection
4 years past (wow!), just checking...
Posted: Wed Mar 28, 2007 6:17 pm
by thefool
Actually i could use this right now :p
Well, i will just have to do my own.
Posted: Wed Mar 28, 2007 6:19 pm
by DarkDragon
Haven't I asked for this a few years ago?

Posted: Wed Mar 28, 2007 6:31 pm
by fsw
Karbon wrote:Thread resurrection
4 years past (wow!), just checking...
You are walking on dangerous ground.
Last time somebody resurrected a thread, Freak got all

Posted: Wed Mar 28, 2007 6:35 pm
by Karbon
My middle name is danger. Mitchell Danger Vincent.. That's me

Posted: Wed Mar 28, 2007 7:09 pm
by Trond
I don't really see the use for this. Of course it's handy, but it will be so much slower than normal arrays.
Posted: Wed Mar 28, 2007 7:15 pm
by Karbon
Speed has nothing to do with it as there is no way you could compare the functionality of a hash table (AKA associative array) with that of a "plain" array. You simple can't do this with an array, fast or slow :
Name.s = TheSettings("name")
(IE, string, or *any* non-integer variable type indexes)
You can get almost the same functionality with the linked lists (especially with the sorting) but there are still plenty of uses for "real" hash tables.
I'm not saying PB is useless or anything but it's a very valuable language construct just the same

Posted: Wed Mar 28, 2007 7:26 pm
by Flype
I agree about the speed,
but speed is not a problem in all case, everytime, everywhere.
9 times on 10 i don't need run-time speed (ok the more it is, the better), but coding-time speed.
Such 'associative array' or also called 'dictionary' (search those keywords on the forum, there are some includes) are very useful, and powerful. Such data-structures are used in many languages (PHP, Python, Java, ...)
Particularly when working with SQL, parsing sort of INI files, parsing arguments of command-lines, but not only...
Posted: Wed Mar 28, 2007 7:46 pm
by Karbon
Indeed, it's a *really* nice way of handling arbitrary length non-numeric "collections" of data.
PHP's array handling functions are about the best of any language I've seen. I realize that is due in large part to PHP's loose typing, something PB doesn't (and shouldn't, IMHO) support.
Anyway, just dropping this note back in the suggestion box
