Ringbuffer

reimplement ringbuffer according to http://en.wikipedia.org/wiki/Circular_buffer#Mirroring