1
0
mirror of https://gittea.dev/nova/th.git synced 2025-10-22 02:40:15 -04:00

improvenments to random sort

This commit is contained in:
nova
2025-08-29 22:42:46 +02:00
parent 9f3042ccac
commit 5afabfb412
3 changed files with 22 additions and 49 deletions

View File

@@ -1,11 +1,13 @@
#include <curses.h>
#include <dirent.h>
#include <strings.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <pthread.h>
#include "defines.h"
extern time_t seed;
extern unsigned int settings;
extern unsigned int file_modifiers;
@@ -97,55 +99,22 @@ int sort_alpha(const void *file0, const void *file1){
char *file_name1 = ((file*)file1)->file_name;
return strcmp(file_name0, file_name1);
}
int sort_random(const void *file0, const void *file1){
unsigned char file_type0 = ((file*)file0)->file_type;
unsigned char file_type1 = ((file*)file1)->file_type;
static int seed = 0;
static int random = 0;
if (seed == 0) {
seed = rand();
}
if (random == 0) {
random = seed;
}
char weight = 0;
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
weight |= 1;
}
if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
weight |= 2;
}
if (weight == 0 || weight == 3) {
random = random > 1;
if ((random & 2) == 2) {
int sort_random(const void *file0_, const void *file1_){
file *file0 = (file*)file0_;
file *file1 = (file*)file1_;
if (file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR) && !(file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR))) {
return -1;
} else {
if (random & 1){
return 1;
} else {
return 0;
}
}
} else {
if (file_type0 > file_type1) {
}
if (!(file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
return 1;
} else if (file_type0 < file_type1) {
return -1;
} else {
random = random > 1;
if ((random & 2) == 2) {
return -1;
} else {
if (random & 1){
return 1;
} else {
return 0;
}
}
}
}
return 0;
int random = rand();
if (random & 1) {
return 1;
} else {
return -1;
}
}
int sort_type(const void *file0, const void *file1){
unsigned char file_type0 = ((file*)file0)->file_type;