Compare commits

...

4 Commits

Author SHA1 Message Date
gbrochar 3bbb476505 strcmp 2024-10-20 20:55:07 +02:00
gbrochar 32760601af feat: use rb_tree to have faster results 2024-10-20 20:10:21 +02:00
gbrochar 6b31743c38 chore(libft): rb tree 2024-10-20 20:09:55 +02:00
gbrochar d1e1384dce chore(libft): update 2024-10-15 16:26:28 +02:00
3 changed files with 26 additions and 23 deletions

View File

@ -22,7 +22,7 @@ OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILES))
CC = gcc
CFLAGS = -Wall -Werror -Wextra -g2
CFLAGS = -Wall -Werror -Wextra -g3
LIB_NAME = libft

2
libft

@ -1 +1 @@
Subproject commit 1cab2379213f62f814312dc2cc7b0f3aa65268fc
Subproject commit e846b98fcda5878a1d4d9de8f422dec09b97456c

View File

@ -139,24 +139,32 @@ char *get_sym_char(Elf64_Sym sym, Elf64_Shdr sec) {
return ("n");
}
int strcmp_nm(t_list *a, t_list *b) {
int strcmp_nm(void *a, void *b) {
t_entry *aa = (t_entry *)a;
t_entry *bb = (t_entry *)b;
char *s1 = aa->symbol;
char *s2 = bb->symbol;
return ft_strcmp(s1, s2);
}
int reverse(void *a, void *b) {
return strcmp_nm(b, a);
}
int nosort(void *a, void *b) {
(void)a;
(void)b;
return 1;
}
int reverse(t_list *a, t_list *b) {
return strcmp_nm(b, a);
}
int nosort(t_list *a, t_list *b) {
(void)a;
(void)b;
return -1;
void put_entry(void *data) {
t_node *node = (t_node *)data;
t_entry *entry = (t_entry *)node->data;
ft_putstr(entry->string);
}
int nm64(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_ordering ordering) {
t_list *list = NULL;
t_root *tree = NULL;
t_entry *entry = (t_entry *)malloc(sizeof(t_entry));
if (!entry)
return FT_NM_FAILURE;
@ -251,13 +259,13 @@ int nm64(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_orderin
// ensuite un switch ordering avec un ft_lstinsert (pointeur sur fonction serait plus opti mais osef)
switch (ordering) {
case NOSORT:
ft_lstinsert(&list, ft_lstnew((void *)entry, sizeof(t_entry)), &nosort);
ft_rbt_insert(&tree, ft_rbt_new((void *)entry, sizeof(t_entry)), &nosort);
break;
case REVERSE:
ft_lstinsert(&list, ft_lstnew((void *)entry, sizeof(t_entry)), &reverse);
ft_rbt_insert(&tree, ft_rbt_new((void *)entry, sizeof(t_entry)), &reverse);
break;
case DEFAULT_ORDERING:
ft_lstinsert(&list, ft_lstnew((void *)entry, sizeof(t_entry)), &strcmp_nm);
ft_rbt_insert(&tree, ft_rbt_new((void *)entry, sizeof(t_entry)), &strcmp_nm);
break;
}
// pas de bst oops :D
@ -269,14 +277,9 @@ int nm64(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_orderin
free(str);
}
// ici on affiche tout ou no symbols en cas de list vide
if (list) {
while (list) {
t_entry *my_entry = (t_entry *)list->content;
ft_putstr(my_entry->string);
list = list->next;
}
}
else {
if (tree) {
ft_putrbt(tree, &put_entry);
} else {
ft_printf("sss", "nm: ", path, ": no symbols\n");
}
return FT_NM_SUCCESS;