aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-01-06 15:51:48 -0800
committerChristian Cunningham <cc@localhost>2022-01-06 15:51:48 -0800
commita61201b8047ebe278cfb281723a4bf6c82556472 (patch)
treef3b2d5b4a9e537fa8f370b00d0c4d4b637223303 /src/lib
parenta826a645a67c2be3c7acb097c436c810da728ed7 (diff)
Scheduling
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ll.c27
-rw-r--r--src/lib/q.c14
2 files changed, 40 insertions, 1 deletions
diff --git a/src/lib/ll.c b/src/lib/ll.c
index 4eaa291..4918194 100644
--- a/src/lib/ll.c
+++ b/src/lib/ll.c
@@ -13,13 +13,24 @@ struct LL* new_ll(void* val)
void push_ll(struct LL* l, void* val)
{
struct LL* ll = (struct LL*)malloc(sizeof(struct LL));
+ l->prev->next = ll;
ll->prev = l->prev;
ll->next = l;
- ll->prev->next = ll;
l->prev = ll;
ll->data = val;
}
+void pop_ll(struct LL* l)
+{
+ if ((l->prev == l->next) && (l->prev == l))
+ l->data = 0;
+ else {
+ l->prev->next = l->next;
+ l->next->prev = l->prev;
+ free(l);
+ }
+}
+
void remove_ll(struct LL* l, unsigned long idx)
{
struct LL* t = l;
@@ -30,3 +41,17 @@ void remove_ll(struct LL* l, unsigned long idx)
t->next->prev = t->prev;
free(t);
}
+
+unsigned long length_ll(struct LL* l)
+{
+ struct LL* t = l;
+ unsigned long len = 0;
+ while (1) {
+ if (t->next == l) {
+ return len;
+ }
+ len++;
+ t = t->next;
+ }
+ return len;
+}
diff --git a/src/lib/q.c b/src/lib/q.c
index ebae2b9..2ade143 100644
--- a/src/lib/q.c
+++ b/src/lib/q.c
@@ -38,3 +38,17 @@ void pop_q(struct Q_base* qb)
free(t->data);
free(t);
}
+
+unsigned long length_q(struct Q_base* qb)
+{
+ unsigned long length = 0;
+ if(qb->next == 0)
+ return length;
+ length++;
+ struct Q* q = qb->next;
+ while (q != qb->last) {
+ length++;
+ q = q->next;
+ }
+ return length;
+}