You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
odin version dev-2024-03
Odin: dev-2024-03
OS: Arch Linux, Linux 6.7.8-arch1-1
CPU: Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz
RAM: 15943 MiB
Expected Behavior
The slice returned from unique should be of length 1 for a slice of consecutive values.
Current Behavior
import"core:fmt"import"core:slice"
main :: proc() {
s := []int{2,2,2}
res := slice.unique(s)
fmt.println(res) // output: [2, 2, 2]
}
Suspicious code
// 'unique' replaces consecutive runs of equal elements with a single copy.// The procedures modifies the slice in-place and returns the modified slice.@(require_results)
unique :: proc(s: $S/[]$T) -> S where intrinsics.type_is_comparable(T) #no_bounds_check {
iflen(s) < 2 {
return s
}
i := 1for j in1..<len(s) {
if s[j] != s[j-1] && i != j {
s[i] = s[j]
}
i += 1
}
return s[:i]
}
i is always going to be len(s) since i is incremented every iteration of the loop, and the loop always runs len(s)-1 times.
The text was updated successfully, but these errors were encountered:
Context
odin version dev-2024-03
Odin: dev-2024-03
OS: Arch Linux, Linux 6.7.8-arch1-1
CPU: Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz
RAM: 15943 MiB
Expected Behavior
The slice returned from
unique
should be of length 1 for a slice of consecutive values.Current Behavior
Suspicious code
i
is always going to belen(s)
sincei
is incremented every iteration of the loop, and the loop always runslen(s)-1
times.The text was updated successfully, but these errors were encountered: