hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 1896ad99d6120ad8e3e954b1cfa2a17676c76ad3
parent f1f94af1cd8414babbbfb615037ea3cd6b5cf87c
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sat,  2 Apr 2022 00:05:21 -0400

sort: const `in` param and return value for search

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mfnmatch/fnmatch.ha | 4++--
Msort/+test.ha | 2+-
Msort/search.ha | 4++--
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fnmatch/fnmatch.ha b/fnmatch/fnmatch.ha @@ -346,8 +346,8 @@ fn ctype_name_to_func(name: str) nullable *fn(c: rune) bool = { match (sort::search(map, size(funcmap), &name, &cmp)) { case null => return null: nullable *fn(c: rune) bool; - case let p: *void => - return (p: *funcmap).1; + case let p: *const void => + return (p: *const funcmap).1; }; }; diff --git a/sort/+test.ha b/sort/+test.ha @@ -11,7 +11,7 @@ fn ncmp(a: const *void, b: const *void) int = { const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; for (let i = 0z; i < len(nums); i += 1) { const key = nums[i]; - let p = search(nums[..], size(int), &key, &ncmp) as *int; + const p = search(nums, size(int), &key, &ncmp) as *const int; assert(p == &nums[i] && *p == nums[i]); }; const key = 1337; diff --git a/sort/search.ha b/sort/search.ha @@ -7,11 +7,11 @@ // less than, equal to, or greater than zero if the key is, respectively, less // than, equal to, or greater than the array member. export fn search( - in: []void, + in: []const void, sz: size, key: const *void, cmp: *fn(a: const *void, b: const *void) int, -) nullable *void = { +) nullable *const void = { let ba = in: *[*]u8; for (let nmemb = len(in); nmemb > 0) { let v = &ba[nmemb / 2 * sz];