This addition in RED demonstrates the behaviour:
Output:
usually this performance replace is for non doubling queues, where if a return is 0, you should push the buffer to queue, if a return was 1, replace it but dont push:
ex.
if theres nothing to replace, queue it, this single line prevents duplicates
EDIT, your sketch, the 3rd one actually did work, but you didnt notice it was replaced, with the same exact buffer
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");
[COLOR="#FF0000"]bufme[7] = 99;[/COLOR]
k.replace(bufme, sizeof(bufme), 5, 6, 6); // 2 fields
k.list();
}
void loop() {
// put your main code here, to run repeatedly:
}
Output:
Code:
Queue list:
0) 0 1 2 3 4 5 (6 entries.)
1) 6 19 20 21 88 12 13 [COLOR="#FF0000"]99[/COLOR] 5 (9 entries.)
2) 12 13 14 15 16 17 (6 entries.)
3) 6 19 20 21 88 12 13 4 5 (9 entries.)
usually this performance replace is for non doubling queues, where if a return is 0, you should push the buffer to queue, if a return was 1, replace it but dont push:
ex.
Code:
if ( _outgoing_queue.replace(buffer,4,1,1,1) == 0) _outgoing_queue.push_back(buffer,4);
if theres nothing to replace, queue it, this single line prevents duplicates
EDIT, your sketch, the 3rd one actually did work, but you didnt notice it was replaced, with the same exact buffer
Last edited: