fix some bug and add cap method to array
This commit is contained in:
@@ -5,6 +5,8 @@ type Array2 struct {
|
||||
ysize int
|
||||
xsize int
|
||||
data [][]interface{}
|
||||
|
||||
cap int
|
||||
}
|
||||
|
||||
func New() *Array2 {
|
||||
@@ -15,6 +17,8 @@ func NewWithCap(ysize, xsize int) *Array2 {
|
||||
arr := &Array2{ysize: ysize, xsize: xsize}
|
||||
arr.sizes = make([]int, arr.ysize, arr.ysize)
|
||||
arr.data = make([][]interface{}, arr.ysize, arr.ysize)
|
||||
|
||||
arr.cap = arr.ysize * arr.xsize
|
||||
return arr
|
||||
}
|
||||
|
||||
@@ -58,6 +62,10 @@ func (arr *Array2) Values() []interface{} {
|
||||
return result
|
||||
}
|
||||
|
||||
func (arr *Array2) Cap() int {
|
||||
return arr.cap
|
||||
}
|
||||
|
||||
func (arr *Array2) Grow(size int) {
|
||||
arr.ysize += size
|
||||
temp := make([][]interface{}, arr.ysize, arr.ysize)
|
||||
@@ -67,6 +75,8 @@ func (arr *Array2) Grow(size int) {
|
||||
tempsizes := make([]int, arr.ysize, arr.ysize)
|
||||
copy(tempsizes, arr.sizes)
|
||||
arr.sizes = tempsizes
|
||||
|
||||
arr.cap = arr.ysize * arr.xsize
|
||||
}
|
||||
|
||||
func (arr *Array2) Set(idx int, value interface{}) {
|
||||
|
||||
Reference in New Issue
Block a user