Static Constructors
BCS
ao at pathlink.com
Sat Oct 4 13:45:37 PDT 2008
Reply to Saaa,
>> uint at = 0;
>>
>> if(extra <= at) data.length = (at+1)*2;
>>
> extra=data.length; ?
>
Yes, Oops, (darn remnants :-)
>> data[at] = t;
>> at++;
>> //when done adding
>> data.length = at;
> Initially I'd be adding a lot, but after that only sparsely.
>
>> another option would be to use an AA if order isn't relevant.
>>
>> T[int] data;
>>
> Is this code? I mean should there be an int or 'int'?
>
It's a variables declaration (with T being the type that is needed).
>> void reg(T b)
>> {
>> static int a = 0;
>> data[a++] = b;
> How does this work when it's no dynamic array?
>
http://www.digitalmars.com/d/1.0/arrays.html#associative
It's a hash table, the key is "a". It's incremented so that you get a unique
value for each insertion. ("data[rand()] = b;" might work also)
you can also flip it the other way
int[T] data;
...
data[b] = 0;
to access the data: data.keys.
>> }
>>
More information about the Digitalmars-d-learn
mailing list