package hashmap type Table struct { // ysizes []int // xsizes [][]int // xyproduct int size uint growsize uint data [][4][4]*avlTree cap uint } func newTable() *Table { table := &Table{} table.data = make([][4][4]*avlTree, 4, 4) table.countCap() return table } func (t *Table) countCap() { t.cap = uint(len(t.data)) << 4 // * (4 * 4) } // func (t *Table) countNextGrow() { // t.growsize = uint(len(t.data)) << 6 // +4 * (4 * 4) // } // func (arr *Table) debugValues() []interface{} { // var result []interface{} // for _, z := range arr.data { // if z != nil { // for _, y := range z { // if y == nil { // for i := 0; i < arr.xsize; i++ { // result = append(result, nil) // } // } else { // for _, x := range y { // if x == nil { // result = append(result, struct{}{}) // } else { // result = append(result, x) // } // } // } // } // } else { // for i := 0; i < arr.ysize*arr.xsize; i++ { // result = append(result, nil) // } // } // } // return result // } // func (arr *Table) Values() []interface{} { // var result []interface{} // for _, z := range arr.data { // if z != nil { // for _, y := range z { // if y == nil { // for i := 0; i < arr.xsize; i++ { // result = append(result, nil) // } // } else { // for _, x := range y { // if x == nil { // result = append(result, nil) // } else { // result = append(result, x) // } // } // } // } // } else { // for i := 0; i < arr.ysize*arr.xsize; i++ { // result = append(result, nil) // } // } // } // return result // } func (t *Table) Cap() uint { return t.cap } func (t *Table) Grow(size int) { zsize := len(t.data) + size temp := make([][4][4]*avlTree, zsize, zsize) copy(temp, t.data) t.data = temp t.countCap() } func (t *Table) GetWithNilSet(idx int, DoSetValue func([4]*avlTree, int)) *avlTree { zindex := idx / 16 nidx := (idx % 16) yindex := nidx / 4 xindex := nidx % 4 ydata := t.data[zindex] xdata := ydata[yindex] v := xdata[xindex] if v == nil { DoSetValue(xdata, xindex) } return v } // func (arr *Table) Get(idx int) (interface{}, bool) { // zindex := idx / arr.xyproduct // nextsize := (idx % arr.xyproduct) // yindex := nextsize / arr.xsize // xindex := nextsize % arr.xsize // ydata := arr.data[zindex] // if ydata == nil { // return nil, false // } // xdata := ydata[yindex] // if xdata == nil { // return nil, false // } // v := xdata[xindex] // return v, v != nil // } // func (arr *Table) GetOrSet(idx int, DoSetValue func([]interface{}, int)) (result interface{}, isSet bool) { // zindex := idx / arr.xyproduct // nidx := (idx % arr.xyproduct) // yindex := nidx / arr.xsize // xindex := nidx % arr.xsize // ydata := arr.data[zindex] // if ydata == nil { // ydata = make([][]interface{}, arr.ysize, arr.ysize) // arr.data[zindex] = ydata // } // xdata := ydata[yindex] // if xdata == nil { // xdata = make([]interface{}, arr.xsize, arr.xsize) // ydata[yindex] = xdata // arr.ysizes[zindex]++ // } // result = xdata[xindex] // if result == nil { // DoSetValue(xdata, xindex) // result = xdata[xindex] // if result == nil { // panic("DoSetValue Not Set Value") // } // arr.xsizes[zindex][yindex]++ // return result, false // } // return result, true // } // func (arr *Table) Del(idx int) (interface{}, bool) { // zindex := idx / arr.xyproduct // nextsize := (idx % arr.xyproduct) // yindex := nextsize / arr.xsize // xindex := nextsize % arr.xsize // ydata := arr.data[zindex] // if ydata == nil { // return nil, false // } // xdata := ydata[yindex] // if xdata == nil { // return nil, false // } // v := xdata[xindex] // xdata[xindex] = nil // isnotnil := v != nil // if isnotnil { // arr.xsizes[zindex][yindex]-- // if arr.xsizes[zindex][yindex] == 0 { // arr.data[zindex][yindex] = nil // arr.ysizes[zindex]-- // if arr.ysizes[zindex] == 0 { // arr.data[zindex] = nil // } // } // } // return v, isnotnil // }