aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-15 20:03:12 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-15 20:03:45 +0100
commit827a21b55ad5085765788728f0048f257cb35ccd (patch)
tree032c5319b09ef496eeaa8833056de855f7163aef
parentRemove repeat information in invocation of FOR macro. (diff)
downloadcalp-827a21b55ad5085765788728f0048f257cb35ccd.tar.gz
calp-827a21b55ad5085765788728f0048f257cb35ccd.tar.xz
LinkedList O(1) length.
-rw-r--r--linked_list.inc.h9
1 files changed, 2 insertions, 7 deletions
diff --git a/linked_list.inc.h b/linked_list.inc.h
index cdb0ac1a..cb6df29c 100644
--- a/linked_list.inc.h
+++ b/linked_list.inc.h
@@ -86,6 +86,7 @@ TYPE* POP(LLIST(TYPE)) ( LLIST(TYPE)* lst) {
UNLINK(LINK(TYPE))(frst);
TYPE* retval = frst->value;
+ --lst->length;
free (frst);
return retval;
}
@@ -128,13 +129,7 @@ int APPEND(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* new ) {
}
int SIZE(LLIST(TYPE)) ( LLIST(TYPE)* llist ) {
- int size = 0;
- LINK(TYPE)* l = FIRST(llist);
- while (l->after != NULL) {
- ++size;
- l = l->after;
- }
- return size;
+ return llist->length;
}
int EMPTY(LLIST(TYPE)) ( LLIST(TYPE)* llist ) {