Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions v1/test/cases/testdata/v0/numbersrange/test-numbersrange-0258.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,20 @@ cases:
- -1
- -2
- -3
- note: numbersrange/descending (cheap optimization)
query: data.generated.p = x
modules:
- |
package generated

p := __local0__ {
numbers.range(5, 2, __local1__)
__local0__ = __local1__
}
data: {}
want_result:
- x:
- 5
- 4
- 3
- 2
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ cases:
- -6
- -8
- -10
- note: numbersrangestep/descending (cheap optimization)
query: data.test.p = x
modules:
- |
package test

p = num {
num := numbers.range_step(10, 3, 2)
}
want_result:
- x:
- 10
- 8
- 6
- 4
- note: numbersrangestep/negative
query: data.test.p = x
modules:
Expand Down
17 changes: 17 additions & 0 deletions v1/test/cases/testdata/v1/numbersrange/test-numbersrange-0258.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,20 @@ cases:
- -1
- -2
- -3
- note: numbersrange/descending (cheap optimization)
query: data.generated.p = x
modules:
- |
package generated

p := __local0__ if {
numbers.range(5, 2, __local1__)
__local0__ = __local1__
}
data: {}
want_result:
- x:
- 5
- 4
- 3
- 2
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ cases:
- -6
- -8
- -10
- note: numbersrangestep/descending (cheap optimization)
query: data.test.p = x
modules:
- |
package test

p = num if {
num := numbers.range_step(10, 3, 2)
}
want_result:
- x:
- 10
- 8
- 6
- 4
- note: numbersrangestep/negative
query: data.test.p = x
modules:
Expand Down
10 changes: 8 additions & 2 deletions v1/topdown/numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,14 @@ func generateCheapRange(operands []*ast.Term, iter func(*ast.Term) error) error

terms := make([]*ast.Term, 0, y+1)

for i := x; i <= y; i += step {
terms = append(terms, ast.InternedIntNumberTerm(i))
if x <= y {
for i := x; i <= y; i += step {
terms = append(terms, ast.InternedIntNumberTerm(i))
}
} else {
for i := x; i >= y; i -= step {
terms = append(terms, ast.InternedIntNumberTerm(i))
}
}

return iter(ast.ArrayTerm(terms...))
Expand Down