Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update circular_buffer.h #903

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions exercises/practice/circular-buffer/circular_buffer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
#ifndef CIRCULAR_BUFFER_H
#define CIRCULAR_BUFFER_H

#include <stddef.h>
#include <stdint.h>

typedef int16_t buffer_value_t;
typedef struct circular_buffer_t circular_buffer_t;

// constructs a new buffer
circular_buffer_t *new_circular_buffer(size_t capacity);

// read next value from buffer
int16_t read(circular_buffer_t *buffer, buffer_value_t *value);

// write a value to the buffer
int16_t write(circular_buffer_t *buffer, buffer_value_t value);

// write a value to the buffer
// overwrites the oldest value if the buffer is already full
int16_t overwrite(circular_buffer_t *buffer, buffer_value_t value);

// clear the buffer
void clear_buffer(circular_buffer_t *buffer);

// destroy the entire buffer
// buffer will be a dangling pointer after calling this method on it
void delete_buffer(circular_buffer_t *buffer);

#endif