aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-01-09 11:01:24 +0000
committergingerBill <bill@gingerbill.org>2024-01-09 11:01:24 +0000
commit72dfb73c9d375e2ee280398e40cdcc2d3415ee24 (patch)
tree1a0f772b7ae76132b8fc3167dcd9ed8b2c327110
parent67dcd916e8f7b1badef5c6beee621557b069db3c (diff)
parentefb2b050400e7e566d7f4a1e3695c09d75059945 (diff)
Merge branch 'master' of https://github.com/odin-lang/Odin
-rw-r--r--core/container/priority_queue/priority_queue.odin15
-rw-r--r--core/slice/sort.odin2
-rw-r--r--core/strings/strings.odin3
-rw-r--r--tests/core/strings/test_core_strings.odin12
4 files changed, 30 insertions, 2 deletions
diff --git a/core/container/priority_queue/priority_queue.odin b/core/container/priority_queue/priority_queue.odin
index 0c5c4931d..0c43816e1 100644
--- a/core/container/priority_queue/priority_queue.odin
+++ b/core/container/priority_queue/priority_queue.odin
@@ -140,3 +140,18 @@ remove :: proc(pq: ^$Q/Priority_Queue($T), i: int) -> (value: T, ok: bool) {
return
}
+peek_safe :: proc(pq: $Q/Priority_Queue($T), loc := #caller_location) -> (res: T, ok: bool) {
+ if builtin.len(pq.queue) > 0 {
+ return pq.queue[0], true
+ }
+ return
+}
+
+peek :: proc(pq: $Q/Priority_Queue($T), loc := #caller_location) -> (res: T) {
+ assert(condition=builtin.len(pq.queue)>0, loc=loc)
+
+ if builtin.len(pq.queue) > 0 {
+ return pq.queue[0]
+ }
+ return
+} \ No newline at end of file
diff --git a/core/slice/sort.odin b/core/slice/sort.odin
index 515eddcc3..3b4119afa 100644
--- a/core/slice/sort.odin
+++ b/core/slice/sort.odin
@@ -62,7 +62,7 @@ _sort_by_indices :: proc(data, sorted: $T/[]$E, indices: []int) {
sort_by_indices_overwrite :: proc(data: $T/[]$E, indices: []int) {
assert(len(data) == len(indices))
- temp := make([]int, len(data), context.allocator)
+ temp := make([]E, len(data), context.allocator)
defer delete(temp)
for v, i in indices {
temp[i] = data[v]
diff --git a/core/strings/strings.odin b/core/strings/strings.odin
index 539829a1a..5cee25a66 100644
--- a/core/strings/strings.odin
+++ b/core/strings/strings.odin
@@ -1792,7 +1792,8 @@ last_index_any :: proc(s, chars: string) -> (res: int) {
if r >= utf8.RUNE_SELF {
r = utf8.RUNE_ERROR
}
- return index_rune(chars, r)
+ i := index_rune(chars, r)
+ return i if i < 0 else 0
}
if len(s) > 8 {
diff --git a/tests/core/strings/test_core_strings.odin b/tests/core/strings/test_core_strings.odin
index fdaf3af28..3424675b3 100644
--- a/tests/core/strings/test_core_strings.odin
+++ b/tests/core/strings/test_core_strings.odin
@@ -67,6 +67,18 @@ test_index_any_larger_string_found :: proc(t: ^testing.T) {
expect(t, index == 8, "index_any should be 8")
}
+@test
+test_last_index_any_small_string_found :: proc(t: ^testing.T) {
+ index := strings.last_index_any(".", "/:.\"")
+ expect(t, index == 0, "last_index_any should be 0")
+}
+
+@test
+test_last_index_any_small_string_not_found :: proc(t: ^testing.T) {
+ index := strings.last_index_any(".", "/:\"")
+ expect(t, index == -1, "last_index_any should be -1")
+}
+
Cut_Test :: struct {
input: string,
offset: int,