[Swift-devel] Associative array in Swift [GSoC]

Yadu Nand yadudoc1729 at gmail.com
Sat Jun 18 12:21:56 CDT 2011


>> where ! means "some appropriate unique index" (I think the restart code
>> did/does do that foreach loops to label variables in nested scope in a way
>> that could be used here).
>>
>> So then Yadu's: a[0] = 100; a[0] = 200; example might turn into:
>>
>>  int a[][]; a[0][!] = 100; a[0][!] = 200;

I've got this almost working. When I specify
int a[ ] [ ] ; a["hi"]["!"] = 100 ; a["hi"]["!"] = 200 ;
foreach value, index in a["hi"] {
       trace ( value );
}

I get this :

Swift svn swift-r4525 (swift modified locally) cog-r3116

RunID: 20110618-2237-u7avzkd2
Progress:  time: Sat, 18 Jun 2011 22:37:11 +0530
SwiftScript trace: a.[hi][2034564079]:int = 30.0 - Closed
SwiftScript trace: a.[hi][1072406687]:int = 10.0 - Closed
SwiftScript trace: a.[hi][598210806]:int = 20.0 - Closed

A diff at this stage is attached.

As you might have guessed from the output, whenever I see
a "!" string as a subscript I used a random function to generate a random key.
This might be bad as there is no guarantee that there will be no collision.
I'm trying to replace this with a UUID so that no-collisions can be guaranteed.

-- 
Thanks and Regards,
Yadu Nand B
-------------- next part --------------
A non-text attachment was scrubbed...
Name: second.patch
Type: text/x-patch
Size: 4467 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/swift-devel/attachments/20110618/3ba82bf3/attachment.bin>


More information about the Swift-devel mailing list