add: ft_list_push_front
This commit is contained in:
parent
b1a86b85fe
commit
eadf7cde62
@ -13,3 +13,4 @@ char *ft_strdup(const char *s);
|
||||
ssize_t ft_read(int fildes, void *buf, size_t nbyte);
|
||||
|
||||
int ft_list_size(t_list *begin_list);
|
||||
void ft_list_push_front(t_list **begin_list, void *data);
|
27
src/ft_list_push_front.asm
Normal file
27
src/ft_list_push_front.asm
Normal file
@ -0,0 +1,27 @@
|
||||
extern malloc
|
||||
|
||||
section .text
|
||||
global ft_list_push_front
|
||||
ft_list_push_front:
|
||||
|
||||
push rdi
|
||||
push rsi
|
||||
|
||||
mov rdi, 16
|
||||
|
||||
call malloc wrt ..plt
|
||||
|
||||
cmp rax, 0
|
||||
je out
|
||||
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
||||
mov rdx, [rdi]
|
||||
mov [rax + 0], rsi ; .data = arg#1
|
||||
mov [rax + 8], rdx ; .next = *arg#0
|
||||
|
||||
mov [rdi], rax
|
||||
|
||||
out:
|
||||
ret
|
32
test/test.c
32
test/test.c
@ -103,6 +103,7 @@ t_list *create_list(size_t len)
|
||||
for (size_t i = 0; i < len; i++)
|
||||
{
|
||||
current->next = malloc(sizeof(t_list));
|
||||
current->data = (void *) i;
|
||||
if (current->next == NULL)
|
||||
{
|
||||
destroy_list(current, NULL);
|
||||
@ -120,7 +121,7 @@ t_list *create_list(size_t len)
|
||||
void multiple_test_list_size()
|
||||
{
|
||||
size_t len;
|
||||
t_list **root;
|
||||
t_list *root;
|
||||
size_t specific_size[nb_specific_test] = {0};
|
||||
|
||||
srand(time(NULL));
|
||||
@ -137,6 +138,31 @@ void multiple_test_list_size()
|
||||
}
|
||||
}
|
||||
|
||||
void multiple_test_push_front()
|
||||
{
|
||||
size_t len;
|
||||
t_list *root;
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for (size_t i = 0; i < nb_random_test; i++)
|
||||
{
|
||||
len = rand() % 100;
|
||||
|
||||
root = create_list(len);
|
||||
if (root == NULL)
|
||||
return;
|
||||
ft_list_push_front(&root, (void *) 101);
|
||||
printf("data: ");
|
||||
test_size_t((size_t) root->data, 101);
|
||||
printf(" data-next: ");
|
||||
test_size_t((size_t) root->next->data, 0);
|
||||
printf(" list-size: ");
|
||||
test_int(len + 1, ft_list_size(root));
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("STRLEN\n");
|
||||
@ -165,4 +191,8 @@ int main()
|
||||
printf("FT_LIST_SIZE\n");
|
||||
multiple_test_list_size();
|
||||
printf("\n");
|
||||
|
||||
printf("FT_LIST_PUSH_FRONT\n");
|
||||
multiple_test_push_front();
|
||||
printf("\n");
|
||||
}
|
Loading…
Reference in New Issue
Block a user