This works:

private func shiftArray( inout arr: [UInt32], lowerIndex: UInt, upperIndex: 
UInt )
{
        //      move: arr[ lowerIndex ..< upperIndex ] to: arr[ lowerIndex + 1 
... upperIndex ]

        let av = arr[ Int(upperIndex) ]
                                                
        for var i = upperIndex - 1;; i--        
        {
                arr[ Int(i+1) ] = arr[ Int(i) ]
                if i == lowerIndex { break }
        }
                
        arr[ Int(lowerIndex) ] = av     
}

But I thought that maybe memmove might be more efficient:

let dest : UnsafeMutablePointer<Void> =  arr + lowerIndex + 1
let orig : UnsafePointer<Void> =  arr + lowerIndex 
let nbrInts = upperIndex - 1 - lowerIndex
let nbrBytes = nbrInts * UInt( sizeof(UInt32) )
memmove( dest, orig, nbrBytes )

But I can't get my Unsafe Pointers to compile.
Tried everything I could think of. But got only varying (not very helpful) 
error messages.

Is this possible in Swift?

Gerriet.


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to