2020-05-18 12:30:44 +00:00
|
|
|
/*
|
|
|
|
Package iterator provides functions to work with Neo iterators.
|
|
|
|
*/
|
2018-08-31 08:23:57 +00:00
|
|
|
package iterator
|
|
|
|
|
2020-05-18 12:30:44 +00:00
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop/enumerator"
|
2018-08-31 08:23:57 +00:00
|
|
|
|
2020-05-18 12:30:44 +00:00
|
|
|
// Iterator represents a Neo iterator, it's an opaque data structure that can
|
|
|
|
// be properly created by Create or storage.Find. Unlike enumerators, iterators
|
|
|
|
// range over key-value pairs, so it's convenient to use them for maps. This
|
|
|
|
// structure is similar in function to Neo .net framework's Iterator.
|
2018-08-31 08:23:57 +00:00
|
|
|
type Iterator struct{}
|
|
|
|
|
2020-05-18 12:30:44 +00:00
|
|
|
// Create creates an iterator from the given items (array, struct or map). A new
|
|
|
|
// iterator is set to point at element -1, so to access its first element you
|
2020-06-10 08:49:39 +00:00
|
|
|
// need to call Next first. This function uses `System.Iterator.Create` syscall.
|
2018-08-31 08:23:57 +00:00
|
|
|
func Create(items []interface{}) Iterator {
|
|
|
|
return Iterator{}
|
|
|
|
}
|
|
|
|
|
2020-05-18 12:38:11 +00:00
|
|
|
// Concat concatenates two given iterators returning one that will range on
|
|
|
|
// a first and then continue with b. Iterator positions are not reset for a
|
|
|
|
// and b, so if any of them was already advanced by Next the resulting
|
|
|
|
// Iterator will point at this new position and never go back to previous
|
|
|
|
// key-value pairs. Concatenated iterators also remain completely independent
|
|
|
|
// in results they return, so if both contain the same key you'll receive this
|
2020-06-10 08:49:39 +00:00
|
|
|
// key twice when iterating. This function uses `System.Iterator.Concat` syscall.
|
2020-05-18 12:38:11 +00:00
|
|
|
func Concat(a, b Iterator) Iterator {
|
|
|
|
return Iterator{}
|
|
|
|
}
|
|
|
|
|
2020-05-18 12:30:44 +00:00
|
|
|
// Key returns iterator's key at current position. It's only valid to call after
|
2020-06-10 08:49:39 +00:00
|
|
|
// successful Next call. This function uses `System.Iterator.Key` syscall.
|
2018-08-31 08:23:57 +00:00
|
|
|
func Key(it Iterator) interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-18 12:30:44 +00:00
|
|
|
// Keys returns Enumerator ranging over keys or the given Iterator. Note that
|
|
|
|
// this Enumerator is actually directly tied to the underlying Iterator, so that
|
|
|
|
// advancing it with Next will actually advance the Iterator too. This function
|
2020-06-10 08:49:39 +00:00
|
|
|
// uses `System.Iterator.Keys` syscall.
|
2020-05-18 12:30:44 +00:00
|
|
|
func Keys(it Iterator) enumerator.Enumerator {
|
|
|
|
return enumerator.Enumerator{}
|
2018-08-31 08:23:57 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 12:30:44 +00:00
|
|
|
// Next advances the iterator returning true if it is was successful (and you
|
|
|
|
// can use Key or Value) and false otherwise (and there are no more elements in
|
2020-06-10 08:49:39 +00:00
|
|
|
// this Iterator). This function uses `System.Enumerator.Next` syscall.
|
2020-03-26 13:34:54 +00:00
|
|
|
func Next(it Iterator) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-05-18 12:30:44 +00:00
|
|
|
// Value returns iterator's current value. It's only valid to call after
|
2020-06-10 08:49:39 +00:00
|
|
|
// successful Next call. This function uses `System.Enumerator.Value` syscall.
|
2020-03-26 13:34:54 +00:00
|
|
|
func Value(it Iterator) interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-18 12:30:44 +00:00
|
|
|
// Values returns Enumerator ranging over values or the given Iterator. Note that
|
|
|
|
// this Enumerator is actually directly tied to the underlying Iterator, so that
|
|
|
|
// advancing it with Next will actually advance the Iterator too. This function
|
2020-06-10 08:49:39 +00:00
|
|
|
// uses `System.Iterator.Values` syscall.
|
2020-05-18 12:30:44 +00:00
|
|
|
func Values(it Iterator) enumerator.Enumerator {
|
|
|
|
return enumerator.Enumerator{}
|
2018-08-31 08:23:57 +00:00
|
|
|
}
|