reimplement ringbuffer

The new implementation use the mirroring method to distinguish full
buffer and the empty buffer. It also support buffers of arbitrary size.
ringbuffer: format the code to a more symmetric structure
Merge pull request #84 from grissiom/ringbuffer

Ringbuffer