Up to Main Index Up to Journal for August, 2012
JOURNAL FOR THURSDAY 25TH AUGUST, 2012
______________________________________________________________________________
SUBJECT: Reversing a slice
DATE: Sat Aug 25 16:31:16 BST 2012
While busy working on WolfMUD and writing tests I found myself needing to
reverse the elements in a slice. Go's multiple assignments made this very easy
but I'm left wondering if there is a better - faster - way to do this:
l := len(things)-1
for x := (int)(l / 2); x >= 0; x-- {
things[x], things[l-x] = things[l-x], things[x]
}
Short, simple and all done in place without extra allocations.
--
Diddymus
Up to Main Index Up to Journal for August, 2012