fix some bug and add cap method to array

This commit is contained in:
2019-04-15 01:42:22 +08:00
parent 703dff0813
commit 293e02149f
4 changed files with 41 additions and 3 deletions

View File

@@ -8,6 +8,8 @@ type Array3 struct {
ysize int
xsize int
data [][][]interface{}
cap int
}
func New() *Array3 {
@@ -26,6 +28,8 @@ func NewWithCap(zsize, ysize, xsize int) *Array3 {
arr.xyproduct = arr.ysize * arr.xsize
arr.data = make([][][]interface{}, arr.zsize, arr.zsize)
arr.cap = arr.zsize * arr.xyproduct
return arr
}
@@ -87,8 +91,12 @@ func (arr *Array3) Values() []interface{} {
return result
}
func (arr *Array3) Cap() int {
return arr.cap
}
func (arr *Array3) Grow(size int) {
arr.ysize += size
arr.zsize += size
temp := make([][][]interface{}, arr.zsize, arr.zsize)
copy(temp, arr.data)
arr.data = temp
@@ -100,6 +108,8 @@ func (arr *Array3) Grow(size int) {
tempxsizes := make([][]int, arr.ysize, arr.ysize)
copy(tempxsizes, arr.xsizes)
arr.xsizes = tempxsizes
arr.cap = arr.zsize * arr.xyproduct
}
func (arr *Array3) Set(idx int, value interface{}) {