[Swift-devel] array function in standard library

Tim Armstrong tim.g.armstrong at gmail.com
Tue Mar 10 09:51:20 CDT 2015


I agree.

There seems to be a set of array operations that are typically used on
dense arrays that depend on knowing where the start of the keyspace is and
where the gaps in the keyspace are (knowing whether the array is dense is a
special case of that).  I can't think of a way to implement them in a way
that works for sparse arrays and is intuitive.

It would be an option to have part of the contract be that the input array
must be dense - we'd just fail if some were missing.  That seems like
something that almost should be part of the type system rather than a
runtime pseudo-type error.

In some cases it could degrade more gracefully, e.g just leaving gaps in
the output array, but that's not generally viable.

I wonder if there are a set of analogous primitives for sparse arrays. e.g.
maybe slice(T a[], T begin, T end) just copies any existing keys such that
begin <= key <= end to the new array, and leaves any gaps.

Anyway, those were some unstructured thoughts - definitely agree that it
needs more thought.

- Tim

On 9 March 2015 at 13:05, Mihael Hategan <hategan at mcs.anl.gov> wrote:

> Hi,
>
> I became suspicious that the proposed array functions aren't very well
> thought of. So I believe that we should not attempt to implement them
> without further thought.
>
> Specifically:
>
> 1. T[K] slice(T[K] a, int start, int end)
>
> What do start and end signify? If there is some ordering on K, then they
> could make sense as indices in the ordered set of keys once the array is
> closed. Unfortunately this requires one to wait for the array to be
> closed.
>
> 2. T[int][K] split(T[K], int n)
>
> Same issue. If the splitting is to be deterministic, one needs to wait
> for the array to be closed.
>
> 3. T[int] join(T[K1][K2] a)
>
> Same.
>
> To some extent, these could be implemented nicely if they worked on
> "compacted" arrays (i.e. T[int] arrays for which the indices are known
> to be consecutive).
>
> Mihael
>
> _______________________________________________
> Swift-devel mailing list
> Swift-devel at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-devel/attachments/20150310/3c8939e7/attachment.html>


More information about the Swift-devel mailing list