mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 13:00:28 +00:00
Fix slice.unique wrong result
When you try to make this array unique `[]int{1, 2, 4, 4, 5}` you get
`[]int{1, 4, 5}` instead of `[]int{1, 2, 4, 5}`.
Our index `i` should be increased even with both indices `i` and `j`
have the same value
This commit is contained in:
@@ -495,8 +495,10 @@ unique :: proc(s: $S/[]$T) -> S where intrinsics.type_is_comparable(T) #no_bound
|
||||
}
|
||||
i := 1
|
||||
for j in 1..<len(s) {
|
||||
if s[j] != s[j-1] && i != j {
|
||||
s[i] = s[j]
|
||||
if s[j] != s[j-1] {
|
||||
if i != j {
|
||||
s[i] = s[j]
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
@@ -513,8 +515,10 @@ unique_proc :: proc(s: $S/[]$T, eq: proc(T, T) -> bool) -> S #no_bounds_check {
|
||||
}
|
||||
i := 1
|
||||
for j in 1..<len(s) {
|
||||
if !eq(s[j], s[j-1]) && i != j {
|
||||
s[i] = s[j]
|
||||
if !eq(s[j], s[j-1]) {
|
||||
if i != j {
|
||||
s[i] = s[j]
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user