[swift-users] [swift-evolution] Low efficiency multidimensional array problem

Jaden Geller jaden.geller at gmail.com
Wed Apr 19 04:55:07 CDT 2017


Hi Hbucius,

You can define your own `Array2D` type that uses a 1-dimensional array as backing (for fast performance) but exposes a high-level 2-dimensional array API.

Here’s a really primitive starting point I found on GitHub:
https://github.com/raywenderlich/swift-algorithm-club/blob/master/Array2D/Array2D.swift <https://github.com/raywenderlich/swift-algorithm-club/blob/master/Array2D/Array2D.swift>

Cheers,
Jaden Geller

> On Apr 18, 2017, at 11:39 PM, Saagar Jha via swift-evolution <swift-evolution at swift.org> wrote:
> 
> It might be helpful if you showed a bit more of the code you’re working on, so that we can better see what you’re trying to do. Is there any operation in particular that is slow?
> 
> Also, CC’ing swift-users since I think it belongs there.
> 
> Saagar Jha
> 
>> On Apr 18, 2017, at 22:57, Hbucius Smith via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Hello Swift community,
>> 
>> 
>>     When I used multidimensional array in swift, I found it is very low efficiency.
>> 
>>   
>>     I used in the following way : 
>> 
>>    
>>     var array = Array.init(repeating: Array.init(repeating: 0, count: 5), count: 5)
>>    
>>     array[0][0] = 0
>> 
>>    
>>   I have read some posts in stack overflow. It suggests using one dimension to fake multidimensional array. I think it is too ugly. DO we have better choice for this ?
>> 
>>     
>>     
>> 
>> 
>> 
>> best wishes for you 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170419/5e4c7636/attachment.html>


More information about the swift-users mailing list