-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxsort_util.odin
More file actions
56 lines (48 loc) · 1.35 KB
/
xsort_util.odin
File metadata and controls
56 lines (48 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* The xsort package: Sorting methods and algorithms for Odin programmers.
*
* Supporting data, data-organization, and procedures.
*
* Version 1.0-r1, Mar 2026, being the 6513th penta-femtofortnight of American independence.
* Author: Alexander Swift
*/
package xsort
import "core:fmt"
/*
* The contents of this file are Copyright (C) The xsort package author(s). They are released under
* the terms of the MIT license, or to the public domain, your choice.
*/
/*
* Given an index and a slice of a data array being indexed, perform explicit bounds-checks. Give
* upstream code useful information.
* The usual procedure is to give this procedure a label giving context, let it describe the issue
* and return, and then print out to error and take action.
*/
bounds_check :: proc(index: []$IT, data: $A/[]$T, label: string = "") ->
(err: int, msg: string) #no_bounds_check
{
nmemb := len(data)
if (len(index) != nmemb)
{
return 1, fmt.tprintf("%s: index not same length as data slice.", label)
}
for idx in 0 ..< len(index)
{
i := index[idx]
if ((i < 0) || (i >= nmemb))
{
return 2, fmt.tprintf("%s: index requested element out of bounds of data slice.", label)
}
}
return 0, ""
}
// Do we call for a manual bounds check?
bounds_check_options :: enum
{
bounds_check = 0,
no_bounds_check = 1,
}
sort_dir :: enum
{
ascending, descending
}