ref: d056c1e8904e8c0722331ac2c75f7396fd2dda80
parent: 387ecb6cb48885d4102383064d82fb9554377f66
author: mkf <mkf@cloud9p.org>
date: Wed Jun 5 18:43:50 EDT 2024
util.[ch]: improve quene functions
--- a/util.c
+++ b/util.c
@@ -126,8 +126,6 @@
if(last->next != nil)
return 0;
-
- dprint("lladd(): adding entry\n");
temp = llnew();
@@ -142,20 +140,22 @@
{
List *temp, *last;
- dprint("lladd(%p, %p)\n", first, data);
+ dprint("llappend(%p, %p)\n", first, data);
+
+ for(last = first ; last->next != nil ; last = last->next)
+ ;
+
/* workaround for first entry */
if(first->data == nil)
temp = first;
else
temp = llnew();
- temp->data = data;
- last = first->prev;
+ temp->data = data;
+
if(last != nil)
last->next = temp;
-
- first->prev = temp;
}
List*
@@ -165,8 +165,7 @@
l = (List*)emalloc(sizeof(List));
l->next = nil;
l->data = nil;
- l->prev = nil;
-
+
return l;
}
@@ -189,7 +188,8 @@
qadd(Quene *q, void *data)
{
q->len++;
- llappend(q->l, data);
+ lladd(q->tail, data);
+ q->tail = q->tail->next;
}
void
@@ -201,16 +201,12 @@
q->len--;
- /* note the last node */
- last = q->l->prev;
+ oldfirst = q->head;
+ q->head = q->head->next;
- /* note the first */
- oldfirst = q->l;
-
- /* delete oldfirst */
- q->l = q->l->next;
+ if(q->tail == oldfirst)
+ q->tail = nil;
+
free(oldfirst);
- /* update last */
- last->next = q->l;
}
--- a/util.h
+++ b/util.h
@@ -3,13 +3,13 @@
{
void *data;
List *next;
- List *prev;
};
typedef struct
{
int len;
- List *l;
+ List *head;
+ List *tail;
}Quene;
int isnum(char *s, unsigned int n);