2019-02-27 20:55:48 +00:00
|
|
|
package stack
|
|
|
|
|
2019-04-02 20:38:41 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2019-02-27 20:55:48 +00:00
|
|
|
// Array represents an Array of stackItems on the stack
|
|
|
|
type Array struct {
|
|
|
|
*abstractItem
|
|
|
|
val []Item
|
|
|
|
}
|
|
|
|
|
|
|
|
// Array overrides the default implementation
|
|
|
|
// by the abstractItem, returning an Array struct
|
|
|
|
func (a *Array) Array() (*Array, error) {
|
|
|
|
return a, nil
|
|
|
|
}
|
2019-04-02 20:38:41 +00:00
|
|
|
|
|
|
|
//Value returns the underlying Array's value
|
|
|
|
func (a *Array) Value() []Item {
|
|
|
|
return a.val
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewArray returns a new Array.
|
|
|
|
func NewArray(val []Item) *Array {
|
|
|
|
return &Array{
|
|
|
|
&abstractItem{},
|
|
|
|
val,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hash overrides the default abstract hash method.
|
|
|
|
func (a *Array) Hash() (string, error) {
|
|
|
|
data := fmt.Sprintf("%T %v", a, a.Value())
|
|
|
|
return KeyGenerator([]byte(data))
|
|
|
|
}
|