💾 Archived View for gmi.noulin.net › gitRepositories › sort › file › README.md.gmi captured on 2023-01-29 at 10:50:22. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
README.md (2025B)
1 # Sheepy 2 This is a sheepy package for [sheepy](https://spartatek.se/r/sheepy/file/README.md.html) and using [libsheepy](https://spartatek.se/r/libsheepy/file/README.md.html) 3 4 # Sort package 5 6 Sorting algorithms for any type of array: 7 8 - flashsort: sorts numbers (not strings) and uses extra memory 9 10 ## Usage 11 12 Install with spm: `spm install sort` 13 14 Include header file: 15 - `#include "shpPackages/sort/sort.h"` 16 17 Usage examples are on the top of the headers and in `main.c`. 18 19 ## radix sort 20 21 radix sort sorts unsigned ints or strings. 22 23 Example: 24 25 ```c 26 // sorting array with string keys 27 28 typ struct { 29 char *a; 30 int b; 31 } skElemt; 32 33 // define macro or function for access the key given an address to an element in the array 34 #define radixsortAt(ptr) (ptr)->a 35 36 // define a radixsort function with name 'radiS' and 'radiSSafe' sorting arrays with skElemt element type 37 radixyStringThreadDef(,radiS,skElemt,6,4, 40); 38 #undef radixsortAt 39 40 // the radiSSafe check if there are empty strings (NULL or "") in the keys 41 // Empty strings are not allowed. 42 43 // declare array 44 skElemt radS[200]; 45 46 // sort the array 47 radiS(radS, sz); 48 ``` 49 50 ## flashsort 51 52 `flashsort.h` is a type safe flashsort implementation. 53 54 Flashsort is in the classification sort category (no string compare) and sorts numbers (int, uint, float, ...). 55 56 Struct and pointer elements in the input array are supported 57 58 59 The performance depends on how uniform is the distribution, the more uniform the better (high variance). 60 61 Measuring the performance with the random arrays in `main.c`, flashsort is 50% faster than qsort from glibc. 62 63 64 An array of size m * sizeof(size_t) is allocated the heap and then freed. 65 66 67 Example: 68 69 ```c 70 // declare an array 71 typ struct { 72 i32 key; 73 i32 value; 74 } elemt; 75 76 elemt array[1000]; 77 78 // define flashsortGet 79 #define flashsortGet(ptr) (ptr)->key 80 81 // call flashsort 82 flashsort(array, ARRAY_SIZE(array)); 83 84 // or call flashsortM to be able to set the number of classes 85 // flashsortM(array, ARRAY_SIZE(array), 0.43 * ARRAY_SIZE(array)); 86 87 #undef flashsortGet 88 ```