-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2955085
commit 854cb2e
Showing
2 changed files
with
44 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package syntax | ||
|
||
import ( | ||
"github.com/arr-ai/arrai/rel" | ||
) | ||
|
||
// ContainsArray check if array a contains array b. | ||
func ContainsArray(a rel.Array, b rel.Array) rel.Value { | ||
// Get index of b[0] in a | ||
bOffset := 0 | ||
bVals := b.Values() | ||
arrayEnum, _ := a.ArrayEnumerator() | ||
for arrayEnum.MoveNext() { | ||
if bOffset < len(bVals) && arrayEnum.Current().Equal(bVals[bOffset]) { | ||
bOffset++ | ||
} else { | ||
if bOffset > 0 && bOffset < len(bVals) { | ||
return rel.NewBool(false) | ||
} | ||
} | ||
} | ||
|
||
if bOffset == len(bVals) { | ||
return rel.NewBool(true) | ||
} | ||
|
||
return rel.NewBool(false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters