fix some bug and add cap method to array
This commit is contained in:
@@ -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{}) {
|
||||
|
||||
Reference in New Issue
Block a user