Skip to content

Small helper data structure that allows retaining unused data (Mirror)

Notifications You must be signed in to change notification settings

eaon/rotating-buffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Rotating Buffer

… is a small helper data structure that allows a stack-allocated buffer to be reused while keeping data that couldn't be handled immediately.

Example:

use rotating_buffer::*;
let mut buf = RotatingBuffer::<u8, 4>::new();

buf.get_append_only().copy_from_slice(&[1, 2, 3, 4]);
buf.add_len(4);
assert_eq!(&[1, 2, 3, 4], buf.as_slice());

buf.rotate_right_and_resize_at(3);
assert_eq!(&[4], buf.as_slice());

assert_eq!(3, buf.get_append_only().len());
buf.get_append_only().copy_from_slice(&[5, 6, 7]);
buf.add_len(3);
assert_eq!(&[4, 5, 6, 7], buf.as_slice());

buf.rotate_right_and_resize_at(4);
assert_eq!(buf.as_slice().len(), 0);

Inspired by a pairing session at Recurse Center 👩‍💻🐙

About

Small helper data structure that allows retaining unused data (Mirror)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages