iterator interface chenged index and count members from int to tint 64
This commit is contained in:
+16
-16
@@ -14,36 +14,36 @@ import (
|
||||
|
||||
type ListIterator struct {
|
||||
a *kern.ListType
|
||||
count int
|
||||
index int
|
||||
start int
|
||||
stop int
|
||||
step int
|
||||
count int64
|
||||
index int64
|
||||
start int64
|
||||
stop int64
|
||||
step int64
|
||||
}
|
||||
|
||||
func NewListIterator(list *kern.ListType, args []any) (it *ListIterator) {
|
||||
var argc int = 0
|
||||
listLen := len(([]any)(*list))
|
||||
listLen := int64(len(([]any)(*list)))
|
||||
if args != nil {
|
||||
argc = len(args)
|
||||
}
|
||||
it = &ListIterator{a: list, count: 0, index: -1, start: 0, stop: listLen - 1, step: 1}
|
||||
if argc >= 1 {
|
||||
if i, err := kern.ToGoInt(args[0], "start index"); err == nil {
|
||||
if i, err := kern.ToGoInt64(args[0], "start index"); err == nil {
|
||||
if i < 0 {
|
||||
i = listLen + i
|
||||
}
|
||||
it.start = i
|
||||
}
|
||||
if argc >= 2 {
|
||||
if i, err := kern.ToGoInt(args[1], "stop index"); err == nil {
|
||||
if i, err := kern.ToGoInt64(args[1], "stop index"); err == nil {
|
||||
if i < 0 {
|
||||
i = listLen + i
|
||||
}
|
||||
it.stop = i
|
||||
}
|
||||
if argc >= 3 {
|
||||
if i, err := kern.ToGoInt(args[2], "step"); err == nil {
|
||||
if i, err := kern.ToGoInt64(args[2], "step"); err == nil {
|
||||
if i < 0 {
|
||||
i = -i
|
||||
}
|
||||
@@ -61,14 +61,14 @@ func NewListIterator(list *kern.ListType, args []any) (it *ListIterator) {
|
||||
}
|
||||
|
||||
func NewArrayIterator(array []any) (it *ListIterator) {
|
||||
it = &ListIterator{a: (*kern.ListType)(&array), count: 0, index: -1, start: 0, stop: len(array) - 1, step: 1}
|
||||
it = &ListIterator{a: (*kern.ListType)(&array), count: 0, index: -1, start: 0, stop: int64(len(array)) - 1, step: 1}
|
||||
return
|
||||
}
|
||||
|
||||
func (it *ListIterator) String() string {
|
||||
var l = 0
|
||||
var l = int64(0)
|
||||
if it.a != nil {
|
||||
l = len(*it.a)
|
||||
l = int64(len(*it.a))
|
||||
}
|
||||
return fmt.Sprintf("$([#%d])", l)
|
||||
}
|
||||
@@ -106,13 +106,13 @@ func (it *ListIterator) CallOperation(name string, args map[string]any) (v any,
|
||||
func (it *ListIterator) Current() (item any, err error) {
|
||||
a := *(it.a)
|
||||
if it.start <= it.stop {
|
||||
if it.stop < len(a) && it.index >= it.start && it.index <= it.stop {
|
||||
if it.stop < int64(len(a)) && it.index >= it.start && it.index <= it.stop {
|
||||
item = a[it.index]
|
||||
} else {
|
||||
err = io.EOF
|
||||
}
|
||||
} else {
|
||||
if it.start < len(a) && it.index >= it.stop && it.index <= it.start {
|
||||
if it.start < int64(len(a)) && it.index >= it.stop && it.index <= it.start {
|
||||
item = a[it.index]
|
||||
} else {
|
||||
err = io.EOF
|
||||
@@ -130,11 +130,11 @@ func (it *ListIterator) Next() (item any, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (it *ListIterator) Index() int {
|
||||
func (it *ListIterator) Index() int64 {
|
||||
return it.index
|
||||
}
|
||||
|
||||
func (it *ListIterator) Count() int {
|
||||
func (it *ListIterator) Count() int64 {
|
||||
return it.count
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user