Code:
#include "circular_buffer.h"
void setup() {
Serial.begin(115200);
delay(3000);
Serial.println("----------------------");
Circular_Buffer<uint8_t, 64, 10> k;
Serial.print("Initial Q Size: "); Serial.println(k.capacity());
uint8_t bufc[] = { 0, 1, 2, 3, 4, 5 };
uint8_t bufc1[] = { 6, 7, 8, 9, 10, 11 };
uint8_t bufc2[] = { 12, 13, 14, 15, 16, 17 };
uint8_t bufc3[] = { 18, 19, 20, 21, 88, 23 };
k.push_back(bufc, sizeof(bufc));
k.push_back(bufc1, sizeof(bufc1));
k.push_back(bufc2, sizeof(bufc2));
k.push_back(bufc3, sizeof(bufc3));
Serial.print("After Init, Q Size: "); Serial.println(k.size());
uint8_t bufme[] = { 6, 19, 20, 21, 88, 12, 13, 4, 5 };
k.list();
Serial.println("Example of replace with 3 indicies");
k.replace(bufme, sizeof(bufme), 1, 2, 3);
k.list();
//replace is comparing values 19,20,21 between queue and buffer,
//the order is not imporant, if you call:
//k.replace(bufme, sizeof(bufme), 3, 1, 2);
//it's the same search pattern, if those indexes match,
//the buffer will replace that queue content
//There is a minimum of replace indicies need for replace,
//however, it is possible to use only 1 or two indicies
Serial.println("Example to replace based on 1 field");
k.replace(bufme, sizeof(bufme), 0, 0, 0); // 1 field
k.list();
Serial.println("Example to replace based on 2 fields");
k.replace(bufme, sizeof(bufme), 5, 6, 6); // 2 fields
k.list();
}
void loop() {
// put your main code here, to run repeatedly:
}
Output:
Code:
----------------------
Initial Q Size: 64
After Init, Q Size: 4
Queue Size: 4, Index order: 0 1 2 3
First Entry: 0 1 2 3 4 5 (6 entries.)
Last Entry: 18 19 20 21 88 23 (6 entries.)
Queue list:
0) 0 1 2 3 4 5 (6 entries.)
1) 6 7 8 9 10 11 (6 entries.)
2) 12 13 14 15 16 17 (6 entries.)
3) 18 19 20 21 88 23 (6 entries.)
Example of replace with 3 indicies
Queue Size: 4, Index order: 0 1 2 3
First Entry: 0 1 2 3 4 5 (6 entries.)
Last Entry: 6 19 20 21 88 12 13 4 5 (9 entries.)
Queue list:
0) 0 1 2 3 4 5 (6 entries.)
1) 6 7 8 9 10 11 (6 entries.)
2) 12 13 14 15 16 17 (6 entries.)
3) 6 19 20 21 88 12 13 4 5 (9 entries.)
Example to replace based on 1 field
Queue Size: 4, Index order: 0 1 2 3
First Entry: 0 1 2 3 4 5 (6 entries.)
Last Entry: 6 19 20 21 88 12 13 4 5 (9 entries.)
Queue list:
0) 0 1 2 3 4 5 (6 entries.)
1) 6 19 20 21 88 12 13 4 5 (9 entries.)
2) 12 13 14 15 16 17 (6 entries.)
3) 6 19 20 21 88 12 13 4 5 (9 entries.)
Example to replace based on 2 fields
Queue Size: 4, Index order: 0 1 2 3
First Entry: 0 1 2 3 4 5 (6 entries.)
Last Entry: 6 19 20 21 88 12 13 4 5 (9 entries.)
Queue list:
0) 0 1 2 3 4 5 (6 entries.)
1) 6 19 20 21 88 12 13 4 5 (9 entries.)
2) 12 13 14 15 16 17 (6 entries.)
3) 6 19 20 21 88 12 13 4 5 (9 entries.)