[Swift-devel] Appendable data structures in Swift/K and Swift/T

Tim Armstrong tim.g.armstrong at gmail.com
Wed Sep 4 16:17:25 CDT 2013


Ok, I see, thanks, that makes a lot of sense.

So essentially each append() call creates a new opaque key value that is
guaranteed to be unique and the same across runs, then the rest follows
from that.

- Tim


On Wed, Sep 4, 2013 at 4:07 PM, Mihael Hategan <hategan at mcs.anl.gov> wrote:

> On Wed, 2013-09-04 at 15:23 -0500, Tim Armstrong wrote:
> > Awesome, thanks, that clears things up.  For some reason I was thinking
> > that [auto] was something like an auto-incremented integer.
>
> I think we quickly dismissed that because of the problems you alluded to
> in the previous email.
>
> There is also the issue of re-starts, which requires that the index
> allocation be deterministic (actually identical) between different runs
> of the same script.
>
> >
> > Does that mean that "b[k] = x"  and append(b, x) are semantically
> identical
> > in these two code fragments?
> >
> > ==============
> > foreach v, k in a {
> >    b[k] = a[k] * 2;
> > }
> > ---------------------------
> > foreach v in a {
> >    append(b, a[k] * 2);
> > }
> > ==============
>
> Nope. The first guarantees that both arrays have the same number of
> elements AND the same keys.
>
> The second one only guarantees that the arrays have the same number of
> elements.
>
> The distinction is obvious if you add another loop:
>
> foreach v, k in a {
>    int s = a[k] + b[k];
> }
>
> That subsequent foreach is only guaranteed to work in the first case you
> have above.
>
> >
> > Also, I was wondering how this interacts with mappers?  E.g. if a have an
> > [auto] array mapped with simple_mapper, then what filenames would be
> > produced for something like this?
> > file outfile[] <simple_mapper;prefix="baz",suffix=".txt">;
> >
> > append(outfile , ...);
> >
> > append(outfile , ...);
>
> Like a [int] array. The string keys get SHA-1ed.
>
> Which might be  a reasonable solution to getting rid of the string keys.
> Thanks!
>
> Mihael
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-devel/attachments/20130904/ceeaaba6/attachment.html>


More information about the Swift-devel mailing list