add GetOrSet
This commit is contained in:
@@ -108,6 +108,29 @@ func (arr *Array2) Get(idx int) (interface{}, bool) {
|
||||
return v, v != nil
|
||||
}
|
||||
|
||||
func (arr *Array2) GetOrSet(idx int, DoSetValue func([]interface{}, int)) (result interface{}, isSet bool) {
|
||||
yindex := idx / arr.xsize
|
||||
xindex := idx % arr.xsize
|
||||
|
||||
xdata := arr.data[yindex]
|
||||
if xdata == nil {
|
||||
xdata = make([]interface{}, arr.xsize, arr.xsize)
|
||||
arr.data[yindex] = xdata
|
||||
}
|
||||
|
||||
result = xdata[xindex]
|
||||
if result == nil {
|
||||
DoSetValue(xdata, xindex)
|
||||
result = xdata[xindex]
|
||||
if result == nil {
|
||||
panic("DoSetValue Not Set <nil> Value")
|
||||
}
|
||||
arr.sizes[yindex]++
|
||||
return result, true
|
||||
}
|
||||
return result, false
|
||||
}
|
||||
|
||||
func (arr *Array2) Del(idx int) (interface{}, bool) {
|
||||
yindex := idx / arr.xsize
|
||||
xindex := idx % arr.xsize
|
||||
|
||||
Reference in New Issue
Block a user