Skip to content

Commit

Permalink
std/slices: rename Find as Index, FindLast as IndexLast
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 25, 2025
1 parent 5682789 commit f17928e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/julec/opt/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ impl scopeOptimizer {
mut lv, ok := (&sema::Var)(l.Model)
mut j := -1
if ok {
j = slices::Find(assign.Decls, lv)
j = slices::Index(assign.Decls, lv)
}
if j != -1 {
if lv.ValueSym == nil {
Expand Down
6 changes: 3 additions & 3 deletions std/slices/slices.jule
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn Equal[S: []E, E: comparable](s1: S, s2: S): bool {
// Returns index of first matched element with specified element,
// returns -1 if not exist any match. Starts searching at left
// of slice to right.
fn Find[S: []E, E: comparable](s: S, e: E): int {
fn Index[S: []E, E: comparable](s: S, e: E): int {
for i, e2 in s {
if e == e2 {
ret i
Expand All @@ -32,7 +32,7 @@ fn Find[S: []E, E: comparable](s: S, e: E): int {
// Returns index of first matched element with specified element,
// returns -1 if not exist any match. Starts searching at right
// of slice to left.
fn FindLast[S: []E, E: comparable](s: S, e: E): int {
fn IndexLast[S: []E, E: comparable](s: S, e: E): int {
mut i := len(s) - 1
for i >= 0; i-- {
if s[i] == e {
Expand All @@ -44,7 +44,7 @@ fn FindLast[S: []E, E: comparable](s: S, e: E): int {

// Reports whether slice includes e.
fn Contains[S: []E, E: comparable](s: S, e: E): bool {
ret Find[S, E](s, e) >= 0
ret Index[S, E](s, e) >= 0
}

// Counts the number of matched elements with e in s.
Expand Down
32 changes: 16 additions & 16 deletions std/slices/slices_test.jule
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ fn testEqual(t: &testing::T) {
}

#test
fn testFind(t: &testing::T) {
fn testIndex(t: &testing::T) {
s := [1, 2, 3, 4, 6, 5, 6]
t.Assert(Find(s, 20) == -1, "Find(s, 20) != -1")
t.Assert(Find(s, 1) == 0, "Find(s, 1) != 0")
t.Assert(Find(s, 2) == 1, "Find(s, 2) != 1")
t.Assert(Find(s, 3) == 2, "Find(s, 3) != 2")
t.Assert(Find(s, 4) == 3, "Find(s, 4) != 3")
t.Assert(Find(s, 5) == 5, "Find(s, 5) != 5")
t.Assert(Find(s, 6) == 4, "Find(s, 6) != 4")
t.Assert(Index(s, 20) == -1, "Index(s, 20) != -1")
t.Assert(Index(s, 1) == 0, "Index(s, 1) != 0")
t.Assert(Index(s, 2) == 1, "Index(s, 2) != 1")
t.Assert(Index(s, 3) == 2, "Index(s, 3) != 2")
t.Assert(Index(s, 4) == 3, "Index(s, 4) != 3")
t.Assert(Index(s, 5) == 5, "Index(s, 5) != 5")
t.Assert(Index(s, 6) == 4, "Index(s, 6) != 4")
}

#test
fn testFindLast(t: &testing::T) {
fn testIndexLast(t: &testing::T) {
s := [1, 2, 3, 4, 6, 5, 6]
t.Assert(FindLast(s, 20) == -1, "FindLast(s, 20) != -1")
t.Assert(FindLast(s, 1) == 0, "FindLast(s, 1) != 0")
t.Assert(FindLast(s, 2) == 1, "FindLast(s, 2) != 1")
t.Assert(FindLast(s, 3) == 2, "FindLast(s, 3) != 2")
t.Assert(FindLast(s, 4) == 3, "FindLast(s, 4) != 3")
t.Assert(FindLast(s, 5) == 5, "FindLast(s, 5) != 5")
t.Assert(FindLast(s, 6) == 6, "FindLast(s, 6) != 6")
t.Assert(IndexLast(s, 20) == -1, "IndexLast(s, 20) != -1")
t.Assert(IndexLast(s, 1) == 0, "IndexLast(s, 1) != 0")
t.Assert(IndexLast(s, 2) == 1, "IndexLast(s, 2) != 1")
t.Assert(IndexLast(s, 3) == 2, "IndexLast(s, 3) != 2")
t.Assert(IndexLast(s, 4) == 3, "IndexLast(s, 4) != 3")
t.Assert(IndexLast(s, 5) == 5, "IndexLast(s, 5) != 5")
t.Assert(IndexLast(s, 6) == 6, "IndexLast(s, 6) != 6")
}

#test
Expand Down

0 comments on commit f17928e

Please sign in to comment.