💾 Archived View for gmi.noulin.net › markdown › sort_README.md captured on 2024-08-25 at 06:55:56.

View Raw

More Information

⬅️ Previous capture (2023-07-10)

-=-=-=-=-=-=-

# Sheepy
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)

# Sort package

Sorting algorithms for any type of array:

- flashsort: sorts numbers (not strings) and uses extra memory

## Usage

Install with spm: `spm install sort`

Include header file:
- `#include "shpPackages/sort/sort.h"`

Usage examples are on the top of the headers and in `main.c`.

## radix sort

radix sort sorts unsigned ints or strings.

Example:

// sorting array with string keys

typ struct {

char *a;

int b;

} skElemt;

// define macro or function for access the key given an address to an element in the array

define radixsortAt(ptr) (ptr)->a

// define a radixsort function with name 'radiS' and 'radiSSafe' sorting arrays with skElemt element type

radixyStringThreadDef(,radiS,skElemt,6,4, 40);

undef radixsortAt

// the radiSSafe check if there are empty strings (NULL or "") in the keys

// Empty strings are not allowed.

// declare array

skElemt radS[200];

// sort the array

radiS(radS, sz);


## flashsort

`flashsort.h`  is a type safe flashsort implementation.

Flashsort is in the classification sort category (no string compare) and sorts numbers (int, uint, float, ...).

Struct and pointer elements in the input array are supported


The performance depends on how uniform is the distribution, the more uniform the better (high variance).

Measuring the performance with the random arrays in `main.c`, flashsort is 50% faster than qsort from glibc.


An array of size m * sizeof(size_t) is allocated the heap and then freed.


Example:

// declare an array

typ struct {

i32 key;

i32 value;

} elemt;

elemt array[1000];

// define flashsortGet

define flashsortGet(ptr) (ptr)->key

// call flashsort

flashsort(array, ARRAY_SIZE(array));

// or call flashsortM to be able to set the number of classes

// flashsortM(array, ARRAY_SIZE(array), 0.43 * ARRAY_SIZE(array));

undef flashsortGet