contributed by < Herakleos >
queue.[ch]
, and several files to meet the requirements of the automatic test.
lab-0c
. Compare the efficiency between the source code and yours.shuffle
in qtest
by using Fisher–Yates shuffle to shuffle every nodes in the queue.web
in qtest
to provide functions of web server.
qtest
.qtest
, by using Massif to visualize the memory usage in the "simulation" progress.There are serveral critical problems now, try to solve it and pull request.
q_new
:"Our program needs to use regular malloc/free" is written in qtest.c. Instead of using kmalloc(sizeof(struct list_head), GFP_KERNAL)
or kfree
.
q_free
:The correct way to free the node, is to use q_release_element
in order to release every single element in the node. If you free the node itself may occur "Freed queue, but … blocks are still allocated"
q_insert_head
, q_insert_tail
:The q_insert_tail
is similar to q_insert_head
, without initialize list head and change the function list_add
to list_add_tail
. I also found that,
strncpy
, strscpy
is often used in linux kernal.q_remove_head
, q_remove_tail
:The q_remove_tail
is much like q_remove_head
, in spite of using list_del_init
but list_del
and replace list_first_entry
to list_last_entry
.
q_delete_mid
:There are two ways to find the middle element. The other one is to set a fast and a slow parameter as following, the method is often used when we got a singly linked list. Since we got a doubly linked structure in the function, traversing from the both side is a better approach.
q_delete_dup
:While the for each function goes through every element in the sorted queue, we are able to create a parameter to check the current element is duplicate or not. Delete the current duplicate element and change the status, the rest of the work belongs to the next round.
q_swap
:This function is not a typical swap but attempt to swap every two adjacent nodes. This reminds me list_swap
do list_del
, list_replace
and list_add
at the end. Brillant.
q_reverse
:Reverse can be seen as "switching the first and the last element, the second and the last-1 element… all the way to the middle".
q_sort
:I devide the sorting proccess to 3 parts:
More details: Linked list sort
list_sort
in /lib/list_sort.c.You did it!
Since the original shuffle algorithm spend too much effort to get the target from the remaining number. The modern approach is to exchange the target with the tail element decreasing each round.
console_init
.do_shuffle
.Noticed that linux kernal has it own random number generator, I tried to trace get_random_bytes
in /drivers/char/random.c
Working on…