-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) 2023 Xu Shaohua <[email protected]>. All rights reserved. | ||
// Use of this source is governed by GNU General Public License | ||
// that can be found in the LICENSE file. | ||
|
||
#ifndef CII_RING_H_ | ||
#define CII_RING_H_ | ||
|
||
#include <stddef.h> | ||
|
||
typedef struct ring_s ring_t; | ||
|
||
/** | ||
* Creates and returns an empty ring. | ||
* | ||
* @return | ||
*/ | ||
extern ring_t* ring_new(void); | ||
|
||
/** | ||
* Creates and returns a ring whose values are initialized to its non-null pointer | ||
* arguments. | ||
* | ||
* @param x | ||
* @return | ||
*/ | ||
extern ring_t* ring_ring(void* x, ...); | ||
|
||
/** | ||
* Deallocates and clear a ring. | ||
* @param ring | ||
*/ | ||
extern void ring_free(ring_t** ring); | ||
|
||
/** | ||
* Returns the number of values in a ring. | ||
* | ||
* @param ring | ||
* @return | ||
*/ | ||
extern size_t ring_length(ring_t* ring); | ||
|
||
/** | ||
* Get the value at |index| in a ring. | ||
* | ||
* It is a checked runtime error if index is out of range. | ||
* | ||
* @param ring | ||
* @param index | ||
* @return | ||
*/ | ||
extern void* ring_get(ring_t* ring, size_t index); | ||
|
||
/** | ||
* Put a new value at |index| and returns old value. | ||
* | ||
* @param ring | ||
* @param index | ||
* @param value | ||
* @return | ||
*/ | ||
extern void* ring_put(ring_t* ring, size_t index, void* value); | ||
|
||
/** | ||
* Add |value| at anywhere in a ring and returns |value|. | ||
* | ||
* @param ring | ||
* @param pos | ||
* @param value | ||
* @return | ||
*/ | ||
extern void* ring_add(ring_t* ring, int pos, void* value); | ||
|
||
/** | ||
* Add a value to lower end of ring. | ||
* | ||
* @param ring | ||
* @param value | ||
* @return | ||
*/ | ||
extern void* ring_add_low(ring_t* ring, void* value); | ||
|
||
/** | ||
* Add a value to higher end of ring. | ||
* @param ring | ||
* @param value | ||
* @return | ||
*/ | ||
extern void* ring_add_high(ring_t* ring, void* value); | ||
|
||
/** | ||
* Remove value at |index| and returns that value. | ||
* | ||
* @param ring | ||
* @param index | ||
* @return | ||
*/ | ||
extern void* ring_remove(ring_t* ring, size_t index); | ||
|
||
extern void* ring_remove_low(ring_t* ring); | ||
|
||
extern void* ring_remove_high(ring_t* ring); | ||
|
||
#endif // CII_RING_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) 2023 Xu Shaohua <[email protected]>. All rights reserved. | ||
// Use of this source is governed by GNU General Public License | ||
// that can be found in the LICENSE file. | ||
|
||
#include "cii/ring.h" |