contributed by < tfliao
>
Implement queue using singly linked-list, each queue element stores a C string, support new, free, two different push (FIFO and LIFO), pop, size, and reverse. All operations except free and reverse must in constant time O(1).
To achieve Constant push() and size(), we need to add two extra variables in queue_t
, a pointer to last element and size_t store number of element in queue.
Two extra functions to manage list_ele_t
.
list_ele_t
allocation can reduce maintenance efforts.About maintaining the pointer to first and last element, we need explicitly handle the case of empty queue when pushing element, or poping last element in queue.
According to Makefile, make test
will build qtest and run driver.py under scripts folder.
In driver.py, it will run ./qtest -v <verbLevel> -f <testscript>
on each testscript under tests/
In queue.c
, it include harness.h
, without INTERNAL defined, it will replace malloc
, free
, strdup
to another version for deep inspection.
noallocate_mode
noallocate_mode
queue_init
, qtest
setup signal handler for SIGSEGV
and SIGALRM
.SIGSEGV
will be triggerred when invalid memeory segment is accessed.SIGALRM
will be triggerred by alarm(2)
, which trigger SIGALRM
after given timeout.harness.c
, exception_setup
set time limit using alarm(2)
, if next operation doesn't complete before timeout, SIGALRM
will be triggerred. besides, a jump tag is set here using sigsetjmp(3)
.SIGSEGV
or SIGALRM
triggerred, our custom signal handler pass error message through trigger_exception()
, use long jump to the jump tag we set in exception_setup()
.