no message

master
zcy 2021-12-22 15:06:57 +08:00
parent 5e4796836c
commit 72e20c74ae
2 changed files with 33 additions and 30 deletions

View File

@ -130,6 +130,7 @@ int RingBuffer<T>::Add(T *data,uint64_t len){
}
if(tmp == m_head) {
(*tail) = data[i];
i++;
break;
}
(*tail) = data[i];
@ -139,6 +140,10 @@ int RingBuffer<T>::Add(T *data,uint64_t len){
return i;
}
/*
*/
template<typename T>
int RingBuffer<T>::TakeBack(T *data,uint64_t len){
if(data == nullptr)
@ -147,34 +152,33 @@ int RingBuffer<T>::TakeBack(T *data,uint64_t len){
if(m_len == 0)
return 0;
if((m_head + m_len) > m_data_end){
std::cout<< 1;
tail = m_head + m_len - m_size;
}else{
tail = m_head + m_len - 1;
}
int i = 0;
for(i = 0;i < len;i++){
T* tmp = tail;
if(tail > m_data) {
tmp--;
}
if(tail == m_data) {
tmp = m_data_end;
}
// next is head stop
if((tmp == m_head) || (m_head == tail)) {
data[len - 1 - i] = (*tail);
for(i = 0;i < len;i++) {
data[len - 1 - i] = (*tail) ;
if((tail == m_head)) {
i++;
break;
}
data[len - 1 - i] = (*tail) ;
tail = tmp;
if(tail > m_data) {
tail--;
}
if(tail == m_data) {
tail = m_data_end;
}
// next is head stop
}
m_len-=i;
return i;
m_len -= i;
return i ;
}
template<typename T>
int TakeFront(T *data,uint64_t len){
int RingBuffer<T>::TakeFront(T *data,uint64_t len){
if(data == nullptr)
return -1;
T *tail = nullptr;
@ -186,23 +190,21 @@ int TakeFront(T *data,uint64_t len){
tail = m_head + m_len - 1;
}
int i = 0;
for(i = 0;i < len;i++){
T* tmp = m_head;
if(m_head < m_data_end) {
tmp++;
}
if(m_head == m_data_end) {
tmp = m_data;
}
// next is head stop
if((tmp == tail) || (m_head == tail)) {
data[i] = (*tail);
for(i = 0;i < len;i++) {
data[i] = (*m_head);
if(m_head == tail) {
std::cout<<"equal"<<std::endl;
i++;
break;
}
data[i] = (*tail) ;
m_head = tmp;
if(m_head < m_data_end) {
m_head++;
}
if(m_head == m_data_end) {
m_head = m_data;
}
}
m_len-=i;
m_len -= i;
return i;
}

View File

@ -18,6 +18,7 @@ void clearBuffer(int *dat,int len){
}
void TestRingBuffer(){
int in[1024];
for(int i = 0;i < 1024;i ++){
in[i] = i;
}