3 Mar 2004 01:15
Re: approve: Dictionary-chooseAssoc
ok
On Mar 1, 2004, at 7:50 PM, James Harkins wrote:
> Another minor enhancement. Sometimes you need the key when choosing
> from a Dictionary too:
>
> + Dictionary {
> chooseAssoc {
> var index, key, val;
> if (this.size <= 0, { ^nil }); // empty dictionary
> while({
> index = (array.size >> 1).rand << 1; // generate an even index.
> (key = array.at(index)).isNil; // key is at even index.
> });
> // return the value for the first non Nil key we find.
> // the value is at the odd index.
> ^Association.new(key, array[index + 1]);
> }
> }
>
> It's the same as the regular choose method except for the output.
> ____________________________________
>
> H. James Harkins /// dewdrop_world
> http://www.duke.edu/~jharkins
>
> "If attacked by a lion, thrust your arm down his throat.
> This takes some practice." -- Cyril Connolly
> _______________________________________________
> sc-dev mailing list
> sc-dev@...
> http://www.create.ucsb.edu/mailman/listinfo/sc-dev
_______________________________________________ sc-dev mailing list sc-dev@... http://www.create.ucsb.edu/mailman/listinfo/sc-dev
RSS Feed