2020-02-16 00:26:51 +00:00
|
|
|
U0 LinkedListDel(U8 **_list)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Free entire linked-list.
|
2020-02-20 23:40:10 +00:00
|
|
|
U8 **tmpl;
|
|
|
|
while (_list) {
|
|
|
|
tmpl=*_list;
|
|
|
|
Free(_list);
|
|
|
|
_list=tmpl;
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 00:26:51 +00:00
|
|
|
U8 *LinkedListCopy(U8 **_list,CTask *mem_task=NULL)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//MAlloc ident copy of entire linked-list.
|
2020-02-20 23:40:10 +00:00
|
|
|
U8 *res=NULL,**tmpl=&res;
|
|
|
|
while (_list) {
|
|
|
|
tmpl=*tmpl=MAllocIdent(_list,mem_task);
|
|
|
|
_list=*_list;
|
|
|
|
}
|
|
|
|
return res;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 00:26:51 +00:00
|
|
|
I64 LinkedListCount(U8 **_list)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Count of nodes in linked-list.
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 res=0;
|
|
|
|
while (_list) {
|
|
|
|
res++;
|
|
|
|
_list=*_list;
|
|
|
|
}
|
|
|
|
return res;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 00:26:51 +00:00
|
|
|
I64 LinkedListSize(U8 **_list)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Mem size of all nodes in linked-list.
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 res=0;
|
|
|
|
while (_list) {
|
|
|
|
res+=MSize2(_list);
|
|
|
|
_list=*_list;
|
|
|
|
}
|
|
|
|
return res;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 22:53:02 +00:00
|
|
|
U0 QueueDel(CQueue *head,Bool querem=FALSE)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Free entries in queue, not head.
|
2020-02-20 23:40:10 +00:00
|
|
|
CQueue *tmpq=head->next,*tmpq1;
|
|
|
|
while (tmpq!=head) {
|
|
|
|
tmpq1=tmpq->next;
|
|
|
|
if (querem)
|
|
|
|
QueueRemove(tmpq);
|
|
|
|
Free(tmpq);
|
|
|
|
tmpq=tmpq1;
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 22:53:02 +00:00
|
|
|
CQueue *QueueCopy(CQueue *head,CTask *mem_task=NULL)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//MAlloc ident copy of entire queue and head.
|
2020-02-20 23:40:10 +00:00
|
|
|
CQueue *res=MAllocIdent(head,mem_task),*tmpq=head->next,*tmpq1;
|
|
|
|
QueueInit(res);
|
|
|
|
while (tmpq!=head) {
|
|
|
|
tmpq1=MAllocIdent(tmpq,mem_task);
|
|
|
|
QueueInsert(tmpq1,res->last);
|
|
|
|
tmpq=tmpq->next;
|
|
|
|
}
|
|
|
|
return res;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 00:20:04 +00:00
|
|
|
I64 QueueCount(CQueue *head)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Count of nodes in queue, not head.
|
2020-02-20 23:40:10 +00:00
|
|
|
CQueue *tmpq=head->next;
|
|
|
|
I64 res=0;
|
|
|
|
while (tmpq!=head) {
|
|
|
|
res++;
|
|
|
|
tmpq=tmpq->next;
|
|
|
|
}
|
|
|
|
return res;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 22:53:02 +00:00
|
|
|
I64 QueueSize(CQueue *head)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Mem size of all nodes in queue, not head.
|
2020-02-20 23:40:10 +00:00
|
|
|
CQueue *tmpq=head->next;
|
|
|
|
I64 res=0;
|
|
|
|
while (tmpq!=head) {
|
|
|
|
res+=MSize2(tmpq);
|
|
|
|
tmpq=tmpq->next;
|
|
|
|
}
|
|
|
|
return res;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 22:53:02 +00:00
|
|
|
CQueueVectU8 *QueueVectU8New(I64 min_idx=0)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Create new queue vecter.
|
2020-02-20 23:40:10 +00:00
|
|
|
CQueueVectU8 *res=MAlloc(sizeof(CQueueVectU8));
|
|
|
|
QueueInit(res);
|
|
|
|
res->total_count=res->node_count=0;
|
|
|
|
res->min_idx=min_idx;
|
|
|
|
return res;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 22:53:02 +00:00
|
|
|
U0 QueueVectU8Put(CQueueVectU8 *v,I64 idx,U8 ch)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Put U8 at idx i.
|
2020-02-20 23:40:10 +00:00
|
|
|
CQueueVectU8 *tmpv;
|
|
|
|
idx-=v->min_idx;
|
|
|
|
if (idx<0) return;
|
|
|
|
if (idx<v->total_count) {
|
|
|
|
tmpv=v;
|
|
|
|
do {
|
|
|
|
idx-=tmpv->node_count;
|
|
|
|
if (idx<0) {
|
|
|
|
tmpv->body[idx+tmpv->node_count]=ch;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tmpv=tmpv->next;
|
|
|
|
} while (tmpv!=v);
|
|
|
|
} else
|
|
|
|
idx-=v->total_count;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
while (TRUE) {
|
|
|
|
tmpv=v->last;
|
|
|
|
if (tmpv->node_count>=QUE_VECT_U8_COUNT) {
|
|
|
|
tmpv=MAlloc(sizeof(CQueueVectU8));
|
|
|
|
tmpv->node_count=0;
|
|
|
|
QueueInsert(tmpv,v->last);
|
|
|
|
}
|
|
|
|
if (idx--) {
|
|
|
|
tmpv->body[tmpv->node_count++]=0;
|
|
|
|
v->total_count++;
|
|
|
|
} else {
|
|
|
|
tmpv->body[tmpv->node_count++]=ch;
|
|
|
|
v->total_count++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 22:53:02 +00:00
|
|
|
U0 QueueVectU8Del(CQueueVectU8 *v)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Free entire queue vector.
|
2020-02-20 23:40:10 +00:00
|
|
|
if (v) {
|
|
|
|
QueueDel(v);
|
|
|
|
Free(v);
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 22:53:02 +00:00
|
|
|
I64 QueueVectU8Get(CQueueVectU8 *v,I64 idx)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Get U8 at idx i.
|
2020-02-20 23:40:10 +00:00
|
|
|
CQueueVectU8 *tmpv;
|
|
|
|
idx-=v->min_idx;
|
|
|
|
if (!(0<=idx<v->total_count)) return 0;
|
|
|
|
tmpv=v;
|
|
|
|
do {
|
|
|
|
idx-=tmpv->node_count;
|
|
|
|
if (idx<0)
|
|
|
|
return tmpv->body[idx+tmpv->node_count];
|
|
|
|
tmpv=tmpv->next;
|
|
|
|
} while (tmpv!=v);
|
|
|
|
return 0;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CFifoU8 *FifoU8New(I64 size,CTask *mem_task=NULL)
|
|
|
|
{//Create new fifo.
|
2020-02-20 23:40:10 +00:00
|
|
|
CFifoU8 *f;
|
|
|
|
if (!mem_task) mem_task=Fs;
|
|
|
|
f=MAlloc(sizeof(CFifoU8),mem_task);
|
|
|
|
f->buf=MAlloc(size,mem_task);
|
|
|
|
f->mask=size-1;
|
|
|
|
f->in_ptr=0;
|
|
|
|
f->out_ptr=0;
|
|
|
|
return f;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 FifoU8Del(CFifoU8 *f)
|
|
|
|
{//Free fifo.
|
2020-02-20 23:40:10 +00:00
|
|
|
Free(f->buf);
|
|
|
|
Free(f);
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Bool FifoU8Ins(CFifoU8 *f,U8 b)
|
|
|
|
{//Insert U8 into fifo.
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 new_in_ptr;
|
|
|
|
PUSHFD
|
|
|
|
CLI
|
|
|
|
new_in_ptr=(f->in_ptr+1)&f->mask;
|
|
|
|
if (new_in_ptr==f->out_ptr) {
|
|
|
|
POPFD
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
f->buf[f->in_ptr]=b;
|
|
|
|
f->in_ptr=new_in_ptr;
|
|
|
|
POPFD
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 23:13:27 +00:00
|
|
|
Bool FifoU8Remove(CFifoU8 *f,U8 *_b)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Remove U8 from fifo.
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSHFD
|
|
|
|
CLI
|
|
|
|
if (f->in_ptr==f->out_ptr) {
|
|
|
|
POPFD
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
*_b=f->buf[f->out_ptr];
|
|
|
|
f->out_ptr=(f->out_ptr+1)&f->mask;
|
|
|
|
POPFD
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Bool FifoU8Peek(CFifoU8 *f,U8 *_b)
|
|
|
|
{//Peek at front of fifo and don't remove.
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSHFD
|
|
|
|
CLI
|
|
|
|
if (f->in_ptr==f->out_ptr) {
|
|
|
|
POPFD
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
*_b=f->buf[f->out_ptr];
|
|
|
|
POPFD
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 FifoU8Flush(CFifoU8 *f)
|
|
|
|
{//Flush fifo getting rid of all U8's.
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSHFD
|
|
|
|
CLI
|
|
|
|
f->out_ptr=f->in_ptr;
|
|
|
|
POPFD
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 00:20:04 +00:00
|
|
|
I64 FifoU8Count(CFifoU8 *f)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Count of U8's in fifo.
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 res;
|
|
|
|
PUSHFD
|
|
|
|
CLI
|
|
|
|
if (f->out_ptr>f->in_ptr)
|
|
|
|
res=f->mask+1-(f->out_ptr-f->in_ptr);
|
|
|
|
else
|
|
|
|
res=f->in_ptr-f->out_ptr;
|
|
|
|
POPFD
|
|
|
|
return res;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CFifoI64 *FifoI64New(I64 size,CTask *mem_task=NULL)
|
|
|
|
{//Create new fifo.
|
2020-02-20 23:40:10 +00:00
|
|
|
CFifoI64 *f;
|
|
|
|
if (!mem_task) mem_task=Fs;
|
|
|
|
f=MAlloc(sizeof(CFifoI64),mem_task);
|
|
|
|
f->buf=MAlloc(size*sizeof(I64),mem_task);
|
|
|
|
f->mask=size-1;
|
|
|
|
f->in_ptr=0;
|
|
|
|
f->out_ptr=0;
|
|
|
|
return f;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 FifoI64Del(CFifoI64 *f)
|
|
|
|
{//Free fifo.
|
2020-02-20 23:40:10 +00:00
|
|
|
Free(f->buf);
|
|
|
|
Free(f);
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Bool FifoI64Ins(CFifoI64 *f,I64 q)
|
|
|
|
{//Insert I64 into fifo.
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 new_in_ptr;
|
|
|
|
PUSHFD
|
|
|
|
CLI
|
|
|
|
new_in_ptr=(f->in_ptr+1)&f->mask;
|
|
|
|
if (new_in_ptr==f->out_ptr) {
|
|
|
|
POPFD
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
f->buf[f->in_ptr]=q;
|
|
|
|
f->in_ptr=new_in_ptr;
|
|
|
|
POPFD
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 23:13:27 +00:00
|
|
|
Bool FifoI64Remove(CFifoI64 *f,I64 *_q)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Remove I64 from fifo.
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSHFD
|
|
|
|
CLI
|
|
|
|
if (f->in_ptr==f->out_ptr) {
|
|
|
|
POPFD
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
*_q=f->buf[f->out_ptr];
|
|
|
|
f->out_ptr=(f->out_ptr+1)&f->mask;
|
|
|
|
POPFD
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Bool FifoI64Peek(CFifoI64 *f,I64 *_q)
|
|
|
|
{//Peek at front of fifo and don't remove.
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSHFD
|
|
|
|
CLI
|
|
|
|
if (f->in_ptr==f->out_ptr) {
|
|
|
|
POPFD
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
*_q=f->buf[f->out_ptr];
|
|
|
|
POPFD
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 FifoI64Flush(CFifoI64 *f)
|
|
|
|
{//Flush fifo getting rid of all I64's.
|
2020-02-20 23:40:10 +00:00
|
|
|
PUSHFD
|
|
|
|
CLI
|
|
|
|
f->out_ptr=f->in_ptr;
|
|
|
|
POPFD
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 00:20:04 +00:00
|
|
|
I64 FifoI64Count(CFifoI64 *f)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Count of I64's in fifo.
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 res;
|
|
|
|
PUSHFD
|
|
|
|
CLI
|
|
|
|
if (f->out_ptr>f->in_ptr)
|
|
|
|
res=f->mask+1-(f->out_ptr-f->in_ptr);
|
|
|
|
else
|
|
|
|
res=f->in_ptr-f->out_ptr;
|
|
|
|
POPFD
|
|
|
|
return res;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|