2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2019-01-30 21:27:03 +08:00
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2019-01-30 21:27:03 +08:00
|
|
|
|
|
|
|
|
package garray
|
|
|
|
|
|
|
|
|
|
import (
|
2019-12-18 19:37:07 +08:00
|
|
|
"fmt"
|
2019-06-22 11:03:50 +08:00
|
|
|
"sort"
|
2025-11-19 18:11:04 +08:00
|
|
|
"sync"
|
2019-06-22 11:03:50 +08:00
|
|
|
|
2021-10-11 21:41:56 +08:00
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
2019-01-30 21:27:03 +08:00
|
|
|
)
|
|
|
|
|
|
2020-03-30 20:56:00 +08:00
|
|
|
// IntArray is a golang int array with rich features.
|
2020-05-22 12:04:58 +08:00
|
|
|
// It contains a concurrent-safe/unsafe switch, which should be set
|
|
|
|
|
// when its initialization and cannot be changed then.
|
2019-01-30 21:27:03 +08:00
|
|
|
type IntArray struct {
|
2025-11-19 18:11:04 +08:00
|
|
|
*TArray[int]
|
|
|
|
|
once sync.Once
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// NewIntArray creates and returns an empty array.
|
2021-06-02 09:42:27 +08:00
|
|
|
// The parameter `safe` is used to specify whether using array in concurrent-safety,
|
2019-04-24 22:23:32 +08:00
|
|
|
// which is false in default.
|
2019-07-23 23:20:27 +08:00
|
|
|
func NewIntArray(safe ...bool) *IntArray {
|
|
|
|
|
return NewIntArraySize(0, 0, safe...)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// NewIntArraySize create and returns an array with given size and cap.
|
2021-06-02 09:42:27 +08:00
|
|
|
// The parameter `safe` is used to specify whether using array in concurrent-safety,
|
2019-04-24 22:23:32 +08:00
|
|
|
// which is false in default.
|
2019-07-23 23:20:27 +08:00
|
|
|
func NewIntArraySize(size int, cap int, safe ...bool) *IntArray {
|
2019-06-19 09:06:52 +08:00
|
|
|
return &IntArray{
|
2025-11-19 18:11:04 +08:00
|
|
|
TArray: NewTArraySize[int](size, cap, safe...),
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2019-02-01 17:30:23 +08:00
|
|
|
}
|
|
|
|
|
|
2022-11-07 17:55:49 +08:00
|
|
|
// NewIntArrayRange creates and returns an array by a range from `start` to `end`
|
2021-06-02 09:42:27 +08:00
|
|
|
// with step value `step`.
|
2019-12-18 19:37:07 +08:00
|
|
|
func NewIntArrayRange(start, end, step int, safe ...bool) *IntArray {
|
|
|
|
|
if step == 0 {
|
|
|
|
|
panic(fmt.Sprintf(`invalid step value: %d`, step))
|
|
|
|
|
}
|
2022-12-26 19:28:01 +08:00
|
|
|
slice := make([]int, 0)
|
2019-12-18 19:37:07 +08:00
|
|
|
index := 0
|
|
|
|
|
for i := start; i <= end; i += step {
|
2022-12-26 19:28:01 +08:00
|
|
|
slice = append(slice, i)
|
2019-12-18 19:37:07 +08:00
|
|
|
index++
|
|
|
|
|
}
|
|
|
|
|
return NewIntArrayFrom(slice, safe...)
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// NewIntArrayFrom creates and returns an array with given slice `array`.
|
|
|
|
|
// The parameter `safe` is used to specify whether using array in concurrent-safety,
|
2019-04-24 22:23:32 +08:00
|
|
|
// which is false in default.
|
2019-07-23 23:20:27 +08:00
|
|
|
func NewIntArrayFrom(array []int, safe ...bool) *IntArray {
|
2019-01-30 21:27:03 +08:00
|
|
|
return &IntArray{
|
2025-11-19 18:11:04 +08:00
|
|
|
TArray: NewTArrayFrom(array, safe...),
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// NewIntArrayFromCopy creates and returns an array from a copy of given slice `array`.
|
|
|
|
|
// The parameter `safe` is used to specify whether using array in concurrent-safety,
|
2019-04-24 22:23:32 +08:00
|
|
|
// which is false in default.
|
2019-07-23 23:20:27 +08:00
|
|
|
func NewIntArrayFromCopy(array []int, safe ...bool) *IntArray {
|
2019-06-19 09:06:52 +08:00
|
|
|
newArray := make([]int, len(array))
|
|
|
|
|
copy(newArray, array)
|
2025-11-19 18:11:04 +08:00
|
|
|
return NewIntArrayFrom(newArray, safe...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// lazyInit lazily initializes the array.
|
|
|
|
|
func (a *IntArray) lazyInit() {
|
|
|
|
|
a.once.Do(func() {
|
|
|
|
|
if a.TArray == nil {
|
|
|
|
|
a.TArray = NewTArray[int](false)
|
|
|
|
|
}
|
|
|
|
|
})
|
2019-02-20 19:06:08 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// At returns the value by the specified index.
|
|
|
|
|
// If the given `index` is out of range of the array, it returns `0`.
|
|
|
|
|
func (a *IntArray) At(index int) (value int) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.At(index)
|
2021-06-02 09:42:27 +08:00
|
|
|
}
|
|
|
|
|
|
2020-03-30 20:31:47 +08:00
|
|
|
// Get returns the value by the specified index.
|
2021-06-02 09:42:27 +08:00
|
|
|
// If the given `index` is out of range of the array, the `found` is false.
|
2020-03-30 20:31:47 +08:00
|
|
|
func (a *IntArray) Get(index int) (value int, found bool) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Get(index)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Set sets value to specified index.
|
2020-03-30 20:31:47 +08:00
|
|
|
func (a *IntArray) Set(index int, value int) error {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Set(index, value)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// SetArray sets the underlying slice array with the given `array`.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) SetArray(array []int) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.SetArray(array)
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// Replace replaces the array items by given `array` from the beginning of array.
|
2019-02-01 17:30:23 +08:00
|
|
|
func (a *IntArray) Replace(array []int) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.Replace(array)
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-02-01 17:30:23 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Sum returns the sum of values in an array.
|
2019-02-01 17:30:23 +08:00
|
|
|
func (a *IntArray) Sum() (sum int) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Sum()
|
2019-02-01 17:30:23 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Sort sorts the array in increasing order.
|
2021-06-02 09:42:27 +08:00
|
|
|
// The parameter `reverse` controls whether sort in increasing order(default) or decreasing order.
|
2019-06-19 09:06:52 +08:00
|
|
|
func (a *IntArray) Sort(reverse ...bool) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
|
2019-06-19 09:06:52 +08:00
|
|
|
a.mu.Lock()
|
|
|
|
|
defer a.mu.Unlock()
|
2025-11-19 18:11:04 +08:00
|
|
|
|
2019-06-19 09:06:52 +08:00
|
|
|
if len(reverse) > 0 && reverse[0] {
|
|
|
|
|
sort.Slice(a.array, func(i, j int) bool {
|
2021-08-01 15:19:48 +08:00
|
|
|
return a.array[i] >= a.array[j]
|
2019-06-19 09:06:52 +08:00
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
sort.Ints(a.array)
|
|
|
|
|
}
|
|
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// SortFunc sorts the array by custom function `less`.
|
2019-02-01 18:33:53 +08:00
|
|
|
func (a *IntArray) SortFunc(less func(v1, v2 int) bool) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.SortFunc(less)
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-02-01 18:33:53 +08:00
|
|
|
}
|
|
|
|
|
|
2023-02-08 19:08:10 +08:00
|
|
|
// InsertBefore inserts the `values` to the front of `index`.
|
|
|
|
|
func (a *IntArray) InsertBefore(index int, values ...int) error {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.InsertBefore(index, values...)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// InsertAfter inserts the `value` to the back of `index`.
|
2023-02-08 19:08:10 +08:00
|
|
|
func (a *IntArray) InsertAfter(index int, values ...int) error {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.InsertAfter(index, values...)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Remove removes an item by index.
|
2021-06-02 09:42:27 +08:00
|
|
|
// If the given `index` is out of range of the array, the `found` is false.
|
2020-03-30 20:31:47 +08:00
|
|
|
func (a *IntArray) Remove(index int) (value int, found bool) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Remove(index)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2020-01-17 19:48:50 +08:00
|
|
|
// RemoveValue removes an item by value.
|
|
|
|
|
// It returns true if value is found in the array, or else false if not found.
|
|
|
|
|
func (a *IntArray) RemoveValue(value int) bool {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.RemoveValue(value)
|
2020-01-17 19:48:50 +08:00
|
|
|
}
|
|
|
|
|
|
2023-04-12 10:12:28 +08:00
|
|
|
// RemoveValues removes multiple items by `values`.
|
|
|
|
|
func (a *IntArray) RemoveValues(values ...int) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.RemoveValues(values...)
|
2023-04-12 10:12:28 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// PushLeft pushes one or multiple items to the beginning of array.
|
2019-06-19 09:06:52 +08:00
|
|
|
func (a *IntArray) PushLeft(value ...int) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.PushLeft(value...)
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// PushRight pushes one or multiple items to the end of array.
|
|
|
|
|
// It equals to Append.
|
2019-06-19 09:06:52 +08:00
|
|
|
func (a *IntArray) PushRight(value ...int) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.PushRight(value...)
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// PopLeft pops and returns an item from the beginning of array.
|
2021-06-02 09:42:27 +08:00
|
|
|
// Note that if the array is empty, the `found` is false.
|
2020-03-30 20:31:47 +08:00
|
|
|
func (a *IntArray) PopLeft() (value int, found bool) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.PopLeft()
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// PopRight pops and returns an item from the end of array.
|
2021-06-02 09:42:27 +08:00
|
|
|
// Note that if the array is empty, the `found` is false.
|
2020-03-30 20:31:47 +08:00
|
|
|
func (a *IntArray) PopRight() (value int, found bool) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.PopRight()
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// PopRand randomly pops and return an item out of array.
|
2021-06-02 09:42:27 +08:00
|
|
|
// Note that if the array is empty, the `found` is false.
|
2020-03-30 20:31:47 +08:00
|
|
|
func (a *IntArray) PopRand() (value int, found bool) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.PopRand()
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// PopRands randomly pops and returns `size` items out of array.
|
|
|
|
|
// If the given `size` is greater than size of the array, it returns all elements of the array.
|
|
|
|
|
// Note that if given `size` <= 0 or the array is empty, it returns nil.
|
2019-02-20 19:06:08 +08:00
|
|
|
func (a *IntArray) PopRands(size int) []int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.PopRands(size)
|
2019-02-20 19:06:08 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// PopLefts pops and returns `size` items from the beginning of array.
|
|
|
|
|
// If the given `size` is greater than size of the array, it returns all elements of the array.
|
|
|
|
|
// Note that if given `size` <= 0 or the array is empty, it returns nil.
|
2019-02-02 14:22:32 +08:00
|
|
|
func (a *IntArray) PopLefts(size int) []int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.PopLefts(size)
|
2019-02-02 14:22:32 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// PopRights pops and returns `size` items from the end of array.
|
|
|
|
|
// If the given `size` is greater than size of the array, it returns all elements of the array.
|
|
|
|
|
// Note that if given `size` <= 0 or the array is empty, it returns nil.
|
2019-02-02 14:22:32 +08:00
|
|
|
func (a *IntArray) PopRights(size int) []int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.PopRights(size)
|
2019-02-02 14:22:32 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Range picks and returns items by range, like array[start:end].
|
|
|
|
|
// Notice, if in concurrent-safe usage, it returns a copy of slice;
|
2019-02-02 14:22:32 +08:00
|
|
|
// else a pointer to the underlying data.
|
2019-06-22 11:03:50 +08:00
|
|
|
//
|
2021-06-02 09:42:27 +08:00
|
|
|
// If `end` is negative, then the offset will start from the end of array.
|
|
|
|
|
// If `end` is omitted, then the sequence will have everything from start up
|
2019-06-22 11:03:50 +08:00
|
|
|
// until the end of the array.
|
|
|
|
|
func (a *IntArray) Range(start int, end ...int) []int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Range(start, end...)
|
2019-02-02 14:22:32 +08:00
|
|
|
}
|
|
|
|
|
|
2019-06-22 11:03:50 +08:00
|
|
|
// SubSlice returns a slice of elements from the array as specified
|
2021-06-02 09:42:27 +08:00
|
|
|
// by the `offset` and `size` parameters.
|
2019-06-22 11:03:50 +08:00
|
|
|
// If in concurrent safe usage, it returns a copy of the slice; else a pointer.
|
|
|
|
|
//
|
|
|
|
|
// If offset is non-negative, the sequence will start at that offset in the array.
|
|
|
|
|
// If offset is negative, the sequence will start that far from the end of the array.
|
|
|
|
|
//
|
|
|
|
|
// If length is given and is positive, then the sequence will have up to that many elements in it.
|
|
|
|
|
// If the array is shorter than the length, then only the available array elements will be present.
|
|
|
|
|
// If length is given and is negative then the sequence will stop that many elements from the end of the array.
|
|
|
|
|
// If it is omitted, then the sequence will have everything from offset up until the end of the array.
|
|
|
|
|
//
|
|
|
|
|
// Any possibility crossing the left border of array, it will fail.
|
|
|
|
|
func (a *IntArray) SubSlice(offset int, length ...int) []int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.SubSlice(offset, length...)
|
2019-06-22 11:03:50 +08:00
|
|
|
}
|
|
|
|
|
|
2021-08-04 23:35:29 +08:00
|
|
|
// Append is alias of PushRight,please See PushRight.
|
2019-06-19 09:06:52 +08:00
|
|
|
func (a *IntArray) Append(value ...int) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.Append(value...)
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Len returns the length of array.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) Len() int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Len()
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Slice returns the underlying data of array.
|
2019-09-29 14:27:09 +08:00
|
|
|
// Note that, if it's in concurrent-safe usage, it returns a copy of underlying data,
|
|
|
|
|
// or else a pointer to the underlying data.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) Slice() []int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Slice()
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
refactor: interface{} to any and reflect.Ptr to reflect.Pointer (#4395)
This pull request standardizes the use of the Go 1.18+ `any` type alias
instead of `interface{}` throughout the codebase. The change improves
code readability and aligns with modern Go best practices. The update
touches many files, including core data structures, code generation
templates, logging utilities, and test data, ensuring consistency across
all usages.
**Type alias migration to `any`:**
* Replaced all instances of `interface{}` with `any` in core data
structures such as `garray` and in generated model structs (e.g.,
`TableUser`, `User1`, `User2`) to modernize type usage.
[[1]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L31-R31)
[[2]](diffhunk://#diff-6c19859cb32c7516ea95ddc8f8235460818eb2f24d2204308e0d9e1b19e7d90fL15-R19)
[[3]](diffhunk://#diff-a15ba2f5e830b4833c47b902515a4f9e5a4f83a3707698f3229b307ec3776b41L15-R18)
[[4]](diffhunk://#diff-52e0837e84d49221d1b810d88fdf78221f36cffcd664fb42f8aba49a79b974dcL15-R19)
[[5]](diffhunk://#diff-11c3457d1a23a4ca6ecd00d6b856289774936b6a708384cf03aff164044e7546L15-R19)
[[6]](diffhunk://#diff-2cff9cf8e6a0cc34087326d8c8149c3bbaf74c76fdbdf5a73daed13cc04249e1L15-R19)
* Updated function signatures, method parameters, and return types from
`interface{}` to `any` in various parts of the codebase, including code
generation, service logic, and logging utilities (e.g., `mlog`).
[[1]](diffhunk://#diff-175edfeea54490b8fe4e18ffcbea5835efaf8f0b8acf623359073987cae7eb76L48-R55)
[[2]](diffhunk://#diff-2b1953fb78cf3593d8c2c7d911e95b65fd0b847c30ed0b4d167d16fe6d781235L54-R74)
[[3]](diffhunk://#diff-e001b7a4b63603b9b14f00de78a4d570bb76c5f57d856a24643f071032e12356L66-R73)
[[4]](diffhunk://#diff-5582954e8a9983988dc8854ad82067fb2ac6269b988e07357ad8db1dfec5f1a0L39-R41)
[[5]](diffhunk://#diff-c5d51d56f487779a2b6207c7ad26c7a20bbadcc846ce094fe60ab4cabff58c51L107-R107)
[[6]](diffhunk://#diff-f96e6a9fdb416eb1804ceaba1fe0ac637bff22c43837f8bb849c2366ce72d4a1L116-R121)
[[7]](diffhunk://#diff-f94c83a1b08ae060d9346f4a6031fc4a7b9a0b894e02d9afaa09018b6598eac0L112-R112)
[[8]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L36-R36)
[[9]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L74-R74)
[[10]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L96-R96)
**Generated code and templates:**
* Adjusted generated files and code generation templates to output `any`
instead of `interface{}` for relevant struct fields and function
signatures, ensuring that new code generation aligns with the updated
convention.
[[1]](diffhunk://#diff-6c19859cb32c7516ea95ddc8f8235460818eb2f24d2204308e0d9e1b19e7d90fL15-R19)
[[2]](diffhunk://#diff-a15ba2f5e830b4833c47b902515a4f9e5a4f83a3707698f3229b307ec3776b41L15-R18)
[[3]](diffhunk://#diff-52e0837e84d49221d1b810d88fdf78221f36cffcd664fb42f8aba49a79b974dcL15-R19)
[[4]](diffhunk://#diff-11c3457d1a23a4ca6ecd00d6b856289774936b6a708384cf03aff164044e7546L15-R19)
[[5]](diffhunk://#diff-2cff9cf8e6a0cc34087326d8c8149c3bbaf74c76fdbdf5a73daed13cc04249e1L15-R19)
[[6]](diffhunk://#diff-175edfeea54490b8fe4e18ffcbea5835efaf8f0b8acf623359073987cae7eb76L48-R55)
[[7]](diffhunk://#diff-e001b7a4b63603b9b14f00de78a4d570bb76c5f57d856a24643f071032e12356L66-R73)
[[8]](diffhunk://#diff-5582954e8a9983988dc8854ad82067fb2ac6269b988e07357ad8db1dfec5f1a0L39-R41)
**Container and utility updates:**
* Refactored the `garray` container implementation and related
constructors/methods to use `[]any` instead of `[]interface{}`, along
with corresponding function signatures.
[[1]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L31-R31)
[[2]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L52-R52)
[[3]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L62-R62)
[[4]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L73-R86)
[[5]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L96-R97)
[[6]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L107-R114)
[[7]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L124-R124)
[[8]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L135-R143)
[[9]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L167-R167)
These changes collectively modernize the codebase and prepare it for
future Go developments by using the idiomatic `any` type.
2025-08-28 16:53:19 +08:00
|
|
|
// Interfaces returns current array as []any.
|
|
|
|
|
func (a *IntArray) Interfaces() []any {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Interfaces()
|
2019-10-21 19:13:25 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Clone returns a new array, which is a copy of current array.
|
2019-02-01 22:00:58 +08:00
|
|
|
func (a *IntArray) Clone() (newArray *IntArray) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return &IntArray{
|
|
|
|
|
TArray: a.TArray.Clone(),
|
|
|
|
|
}
|
2019-02-01 22:00:58 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Clear deletes all items of current array.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) Clear() *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.Clear()
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Contains checks whether a value exists in the array.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) Contains(value int) bool {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Contains(value)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// Search searches array by `value`, returns the index of `value`,
|
2019-04-24 22:23:32 +08:00
|
|
|
// or returns -1 if not exists.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) Search(value int) int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Search(value)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Unique uniques the array, clear repeated items.
|
2020-05-08 17:12:37 +08:00
|
|
|
// Example: [1,1,2,3,2] -> [1,2,3]
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) Unique() *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.Unique()
|
2019-01-30 21:27:03 +08:00
|
|
|
return a
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// LockFunc locks writing by callback function `f`.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) LockFunc(f func(array []int)) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.LockFunc(f)
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// RLockFunc locks reading by callback function `f`.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) RLockFunc(f func(array []int)) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.RLockFunc(f)
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// Merge merges `array` into current array.
|
|
|
|
|
// The parameter `array` can be any garray or slice type.
|
2019-02-22 09:08:46 +08:00
|
|
|
// The difference between Merge and Append is Append supports only specified slice type,
|
2019-04-24 22:23:32 +08:00
|
|
|
// but Merge supports more parameter types.
|
refactor: interface{} to any and reflect.Ptr to reflect.Pointer (#4395)
This pull request standardizes the use of the Go 1.18+ `any` type alias
instead of `interface{}` throughout the codebase. The change improves
code readability and aligns with modern Go best practices. The update
touches many files, including core data structures, code generation
templates, logging utilities, and test data, ensuring consistency across
all usages.
**Type alias migration to `any`:**
* Replaced all instances of `interface{}` with `any` in core data
structures such as `garray` and in generated model structs (e.g.,
`TableUser`, `User1`, `User2`) to modernize type usage.
[[1]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L31-R31)
[[2]](diffhunk://#diff-6c19859cb32c7516ea95ddc8f8235460818eb2f24d2204308e0d9e1b19e7d90fL15-R19)
[[3]](diffhunk://#diff-a15ba2f5e830b4833c47b902515a4f9e5a4f83a3707698f3229b307ec3776b41L15-R18)
[[4]](diffhunk://#diff-52e0837e84d49221d1b810d88fdf78221f36cffcd664fb42f8aba49a79b974dcL15-R19)
[[5]](diffhunk://#diff-11c3457d1a23a4ca6ecd00d6b856289774936b6a708384cf03aff164044e7546L15-R19)
[[6]](diffhunk://#diff-2cff9cf8e6a0cc34087326d8c8149c3bbaf74c76fdbdf5a73daed13cc04249e1L15-R19)
* Updated function signatures, method parameters, and return types from
`interface{}` to `any` in various parts of the codebase, including code
generation, service logic, and logging utilities (e.g., `mlog`).
[[1]](diffhunk://#diff-175edfeea54490b8fe4e18ffcbea5835efaf8f0b8acf623359073987cae7eb76L48-R55)
[[2]](diffhunk://#diff-2b1953fb78cf3593d8c2c7d911e95b65fd0b847c30ed0b4d167d16fe6d781235L54-R74)
[[3]](diffhunk://#diff-e001b7a4b63603b9b14f00de78a4d570bb76c5f57d856a24643f071032e12356L66-R73)
[[4]](diffhunk://#diff-5582954e8a9983988dc8854ad82067fb2ac6269b988e07357ad8db1dfec5f1a0L39-R41)
[[5]](diffhunk://#diff-c5d51d56f487779a2b6207c7ad26c7a20bbadcc846ce094fe60ab4cabff58c51L107-R107)
[[6]](diffhunk://#diff-f96e6a9fdb416eb1804ceaba1fe0ac637bff22c43837f8bb849c2366ce72d4a1L116-R121)
[[7]](diffhunk://#diff-f94c83a1b08ae060d9346f4a6031fc4a7b9a0b894e02d9afaa09018b6598eac0L112-R112)
[[8]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L36-R36)
[[9]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L74-R74)
[[10]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L96-R96)
**Generated code and templates:**
* Adjusted generated files and code generation templates to output `any`
instead of `interface{}` for relevant struct fields and function
signatures, ensuring that new code generation aligns with the updated
convention.
[[1]](diffhunk://#diff-6c19859cb32c7516ea95ddc8f8235460818eb2f24d2204308e0d9e1b19e7d90fL15-R19)
[[2]](diffhunk://#diff-a15ba2f5e830b4833c47b902515a4f9e5a4f83a3707698f3229b307ec3776b41L15-R18)
[[3]](diffhunk://#diff-52e0837e84d49221d1b810d88fdf78221f36cffcd664fb42f8aba49a79b974dcL15-R19)
[[4]](diffhunk://#diff-11c3457d1a23a4ca6ecd00d6b856289774936b6a708384cf03aff164044e7546L15-R19)
[[5]](diffhunk://#diff-2cff9cf8e6a0cc34087326d8c8149c3bbaf74c76fdbdf5a73daed13cc04249e1L15-R19)
[[6]](diffhunk://#diff-175edfeea54490b8fe4e18ffcbea5835efaf8f0b8acf623359073987cae7eb76L48-R55)
[[7]](diffhunk://#diff-e001b7a4b63603b9b14f00de78a4d570bb76c5f57d856a24643f071032e12356L66-R73)
[[8]](diffhunk://#diff-5582954e8a9983988dc8854ad82067fb2ac6269b988e07357ad8db1dfec5f1a0L39-R41)
**Container and utility updates:**
* Refactored the `garray` container implementation and related
constructors/methods to use `[]any` instead of `[]interface{}`, along
with corresponding function signatures.
[[1]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L31-R31)
[[2]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L52-R52)
[[3]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L62-R62)
[[4]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L73-R86)
[[5]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L96-R97)
[[6]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L107-R114)
[[7]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L124-R124)
[[8]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L135-R143)
[[9]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L167-R167)
These changes collectively modernize the codebase and prepare it for
future Go developments by using the idiomatic `any` type.
2025-08-28 16:53:19 +08:00
|
|
|
func (a *IntArray) Merge(array any) *IntArray {
|
2020-04-07 21:25:52 +08:00
|
|
|
return a.Append(gconv.Ints(array)...)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// Fill fills an array with num entries of the value `value`,
|
|
|
|
|
// keys starting at the `startIndex` parameter.
|
2020-03-30 20:31:47 +08:00
|
|
|
func (a *IntArray) Fill(startIndex int, num int, value int) error {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Fill(startIndex, num, value)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Chunk splits an array into multiple arrays,
|
2021-06-02 09:42:27 +08:00
|
|
|
// the size of each array is determined by `size`.
|
2019-02-02 14:22:32 +08:00
|
|
|
// The last chunk may contain less than size elements.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) Chunk(size int) [][]int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Chunk(size)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// Pad pads array to the specified length with `value`.
|
2019-01-30 21:27:03 +08:00
|
|
|
// If size is positive then the array is padded on the right, or negative on the left.
|
2021-06-02 09:42:27 +08:00
|
|
|
// If the absolute value of `size` is less than or equal to the length of the array
|
2019-01-30 21:27:03 +08:00
|
|
|
// then no padding takes place.
|
|
|
|
|
func (a *IntArray) Pad(size int, value int) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.Pad(size, value)
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Rand randomly returns one item from array(no deleting).
|
2020-03-30 20:31:47 +08:00
|
|
|
func (a *IntArray) Rand() (value int, found bool) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Rand()
|
2019-02-20 19:06:08 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// Rands randomly returns `size` items from array(no deleting).
|
2019-02-20 19:06:08 +08:00
|
|
|
func (a *IntArray) Rands(size int) []int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Rands(size)
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Shuffle randomly shuffles the array.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) Shuffle() *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.Shuffle()
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 22:23:32 +08:00
|
|
|
// Reverse makes array with elements in reverse order.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) Reverse() *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.Reverse()
|
2019-06-19 09:06:52 +08:00
|
|
|
return a
|
2019-01-30 21:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// Join joins array elements with a string `glue`.
|
2019-01-30 21:27:03 +08:00
|
|
|
func (a *IntArray) Join(glue string) string {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.Join(glue)
|
2019-04-24 22:23:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CountValues counts the number of occurrences of all values in the array.
|
|
|
|
|
func (a *IntArray) CountValues() map[int]int {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.CountValues()
|
2019-04-24 22:23:32 +08:00
|
|
|
}
|
|
|
|
|
|
2019-12-25 20:56:39 +08:00
|
|
|
// Iterator is alias of IteratorAsc.
|
|
|
|
|
func (a *IntArray) Iterator(f func(k int, v int) bool) {
|
|
|
|
|
a.IteratorAsc(f)
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// IteratorAsc iterates the array readonly in ascending order with given callback function `f`.
|
|
|
|
|
// If `f` returns true, then it continues iterating; or false to stop.
|
2019-12-25 20:56:39 +08:00
|
|
|
func (a *IntArray) IteratorAsc(f func(k int, v int) bool) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.IteratorAsc(f)
|
2019-12-25 20:56:39 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// IteratorDesc iterates the array readonly in descending order with given callback function `f`.
|
|
|
|
|
// If `f` returns true, then it continues iterating; or false to stop.
|
2019-12-25 20:56:39 +08:00
|
|
|
func (a *IntArray) IteratorDesc(f func(k int, v int) bool) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.IteratorDesc(f)
|
2019-12-25 20:56:39 +08:00
|
|
|
}
|
|
|
|
|
|
2019-10-13 22:31:28 +08:00
|
|
|
// String returns current array as a string, which implements like json.Marshal does.
|
2019-04-24 22:23:32 +08:00
|
|
|
func (a *IntArray) String() string {
|
2022-03-21 22:04:15 +08:00
|
|
|
if a == nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2019-10-01 16:03:18 +08:00
|
|
|
return "[" + a.Join(",") + "]"
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2019-07-13 17:48:16 +08:00
|
|
|
|
|
|
|
|
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
2020-05-08 21:08:06 +08:00
|
|
|
// Note that do not use pointer as its receiver here.
|
|
|
|
|
func (a IntArray) MarshalJSON() ([]byte, error) {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.MarshalJSON()
|
2019-07-13 17:48:16 +08:00
|
|
|
}
|
2019-09-29 20:47:59 +08:00
|
|
|
|
|
|
|
|
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
|
|
|
|
func (a *IntArray) UnmarshalJSON(b []byte) error {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.UnmarshalJSON(b)
|
2019-09-29 20:47:59 +08:00
|
|
|
}
|
2020-01-20 19:56:42 +08:00
|
|
|
|
|
|
|
|
// UnmarshalValue is an interface implement which sets any type of value for array.
|
refactor: interface{} to any and reflect.Ptr to reflect.Pointer (#4395)
This pull request standardizes the use of the Go 1.18+ `any` type alias
instead of `interface{}` throughout the codebase. The change improves
code readability and aligns with modern Go best practices. The update
touches many files, including core data structures, code generation
templates, logging utilities, and test data, ensuring consistency across
all usages.
**Type alias migration to `any`:**
* Replaced all instances of `interface{}` with `any` in core data
structures such as `garray` and in generated model structs (e.g.,
`TableUser`, `User1`, `User2`) to modernize type usage.
[[1]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L31-R31)
[[2]](diffhunk://#diff-6c19859cb32c7516ea95ddc8f8235460818eb2f24d2204308e0d9e1b19e7d90fL15-R19)
[[3]](diffhunk://#diff-a15ba2f5e830b4833c47b902515a4f9e5a4f83a3707698f3229b307ec3776b41L15-R18)
[[4]](diffhunk://#diff-52e0837e84d49221d1b810d88fdf78221f36cffcd664fb42f8aba49a79b974dcL15-R19)
[[5]](diffhunk://#diff-11c3457d1a23a4ca6ecd00d6b856289774936b6a708384cf03aff164044e7546L15-R19)
[[6]](diffhunk://#diff-2cff9cf8e6a0cc34087326d8c8149c3bbaf74c76fdbdf5a73daed13cc04249e1L15-R19)
* Updated function signatures, method parameters, and return types from
`interface{}` to `any` in various parts of the codebase, including code
generation, service logic, and logging utilities (e.g., `mlog`).
[[1]](diffhunk://#diff-175edfeea54490b8fe4e18ffcbea5835efaf8f0b8acf623359073987cae7eb76L48-R55)
[[2]](diffhunk://#diff-2b1953fb78cf3593d8c2c7d911e95b65fd0b847c30ed0b4d167d16fe6d781235L54-R74)
[[3]](diffhunk://#diff-e001b7a4b63603b9b14f00de78a4d570bb76c5f57d856a24643f071032e12356L66-R73)
[[4]](diffhunk://#diff-5582954e8a9983988dc8854ad82067fb2ac6269b988e07357ad8db1dfec5f1a0L39-R41)
[[5]](diffhunk://#diff-c5d51d56f487779a2b6207c7ad26c7a20bbadcc846ce094fe60ab4cabff58c51L107-R107)
[[6]](diffhunk://#diff-f96e6a9fdb416eb1804ceaba1fe0ac637bff22c43837f8bb849c2366ce72d4a1L116-R121)
[[7]](diffhunk://#diff-f94c83a1b08ae060d9346f4a6031fc4a7b9a0b894e02d9afaa09018b6598eac0L112-R112)
[[8]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L36-R36)
[[9]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L74-R74)
[[10]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L96-R96)
**Generated code and templates:**
* Adjusted generated files and code generation templates to output `any`
instead of `interface{}` for relevant struct fields and function
signatures, ensuring that new code generation aligns with the updated
convention.
[[1]](diffhunk://#diff-6c19859cb32c7516ea95ddc8f8235460818eb2f24d2204308e0d9e1b19e7d90fL15-R19)
[[2]](diffhunk://#diff-a15ba2f5e830b4833c47b902515a4f9e5a4f83a3707698f3229b307ec3776b41L15-R18)
[[3]](diffhunk://#diff-52e0837e84d49221d1b810d88fdf78221f36cffcd664fb42f8aba49a79b974dcL15-R19)
[[4]](diffhunk://#diff-11c3457d1a23a4ca6ecd00d6b856289774936b6a708384cf03aff164044e7546L15-R19)
[[5]](diffhunk://#diff-2cff9cf8e6a0cc34087326d8c8149c3bbaf74c76fdbdf5a73daed13cc04249e1L15-R19)
[[6]](diffhunk://#diff-175edfeea54490b8fe4e18ffcbea5835efaf8f0b8acf623359073987cae7eb76L48-R55)
[[7]](diffhunk://#diff-e001b7a4b63603b9b14f00de78a4d570bb76c5f57d856a24643f071032e12356L66-R73)
[[8]](diffhunk://#diff-5582954e8a9983988dc8854ad82067fb2ac6269b988e07357ad8db1dfec5f1a0L39-R41)
**Container and utility updates:**
* Refactored the `garray` container implementation and related
constructors/methods to use `[]any` instead of `[]interface{}`, along
with corresponding function signatures.
[[1]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L31-R31)
[[2]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L52-R52)
[[3]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L62-R62)
[[4]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L73-R86)
[[5]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L96-R97)
[[6]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L107-R114)
[[7]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L124-R124)
[[8]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L135-R143)
[[9]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L167-R167)
These changes collectively modernize the codebase and prepare it for
future Go developments by using the idiomatic `any` type.
2025-08-28 16:53:19 +08:00
|
|
|
func (a *IntArray) UnmarshalValue(value any) error {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.UnmarshalValue(value)
|
2020-01-20 19:56:42 +08:00
|
|
|
}
|
2020-02-22 14:26:36 +08:00
|
|
|
|
2023-04-24 11:44:19 +08:00
|
|
|
// Filter iterates array and filters elements using custom callback function.
|
|
|
|
|
// It removes the element from array if callback function `filter` returns true,
|
|
|
|
|
// it or else does nothing and continues iterating.
|
2023-04-12 10:15:11 +08:00
|
|
|
func (a *IntArray) Filter(filter func(index int, value int) bool) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.Filter(filter)
|
2023-04-12 10:15:11 +08:00
|
|
|
return a
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 14:26:36 +08:00
|
|
|
// FilterEmpty removes all zero value of the array.
|
|
|
|
|
func (a *IntArray) FilterEmpty() *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.FilterEmpty()
|
2020-02-22 14:26:36 +08:00
|
|
|
return a
|
|
|
|
|
}
|
2020-03-25 23:36:56 +08:00
|
|
|
|
2021-06-02 09:42:27 +08:00
|
|
|
// Walk applies a user supplied function `f` to every item of array.
|
2020-04-18 13:30:49 +08:00
|
|
|
func (a *IntArray) Walk(f func(value int) int) *IntArray {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
a.TArray.Walk(f)
|
2020-04-18 13:30:49 +08:00
|
|
|
return a
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 23:36:56 +08:00
|
|
|
// IsEmpty checks whether the array is empty.
|
|
|
|
|
func (a *IntArray) IsEmpty() bool {
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return a.TArray.IsEmpty()
|
2020-03-25 23:36:56 +08:00
|
|
|
}
|
2022-05-23 16:51:10 +08:00
|
|
|
|
|
|
|
|
// DeepCopy implements interface for deep copy of current type.
|
refactor: interface{} to any and reflect.Ptr to reflect.Pointer (#4395)
This pull request standardizes the use of the Go 1.18+ `any` type alias
instead of `interface{}` throughout the codebase. The change improves
code readability and aligns with modern Go best practices. The update
touches many files, including core data structures, code generation
templates, logging utilities, and test data, ensuring consistency across
all usages.
**Type alias migration to `any`:**
* Replaced all instances of `interface{}` with `any` in core data
structures such as `garray` and in generated model structs (e.g.,
`TableUser`, `User1`, `User2`) to modernize type usage.
[[1]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L31-R31)
[[2]](diffhunk://#diff-6c19859cb32c7516ea95ddc8f8235460818eb2f24d2204308e0d9e1b19e7d90fL15-R19)
[[3]](diffhunk://#diff-a15ba2f5e830b4833c47b902515a4f9e5a4f83a3707698f3229b307ec3776b41L15-R18)
[[4]](diffhunk://#diff-52e0837e84d49221d1b810d88fdf78221f36cffcd664fb42f8aba49a79b974dcL15-R19)
[[5]](diffhunk://#diff-11c3457d1a23a4ca6ecd00d6b856289774936b6a708384cf03aff164044e7546L15-R19)
[[6]](diffhunk://#diff-2cff9cf8e6a0cc34087326d8c8149c3bbaf74c76fdbdf5a73daed13cc04249e1L15-R19)
* Updated function signatures, method parameters, and return types from
`interface{}` to `any` in various parts of the codebase, including code
generation, service logic, and logging utilities (e.g., `mlog`).
[[1]](diffhunk://#diff-175edfeea54490b8fe4e18ffcbea5835efaf8f0b8acf623359073987cae7eb76L48-R55)
[[2]](diffhunk://#diff-2b1953fb78cf3593d8c2c7d911e95b65fd0b847c30ed0b4d167d16fe6d781235L54-R74)
[[3]](diffhunk://#diff-e001b7a4b63603b9b14f00de78a4d570bb76c5f57d856a24643f071032e12356L66-R73)
[[4]](diffhunk://#diff-5582954e8a9983988dc8854ad82067fb2ac6269b988e07357ad8db1dfec5f1a0L39-R41)
[[5]](diffhunk://#diff-c5d51d56f487779a2b6207c7ad26c7a20bbadcc846ce094fe60ab4cabff58c51L107-R107)
[[6]](diffhunk://#diff-f96e6a9fdb416eb1804ceaba1fe0ac637bff22c43837f8bb849c2366ce72d4a1L116-R121)
[[7]](diffhunk://#diff-f94c83a1b08ae060d9346f4a6031fc4a7b9a0b894e02d9afaa09018b6598eac0L112-R112)
[[8]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L36-R36)
[[9]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L74-R74)
[[10]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L96-R96)
**Generated code and templates:**
* Adjusted generated files and code generation templates to output `any`
instead of `interface{}` for relevant struct fields and function
signatures, ensuring that new code generation aligns with the updated
convention.
[[1]](diffhunk://#diff-6c19859cb32c7516ea95ddc8f8235460818eb2f24d2204308e0d9e1b19e7d90fL15-R19)
[[2]](diffhunk://#diff-a15ba2f5e830b4833c47b902515a4f9e5a4f83a3707698f3229b307ec3776b41L15-R18)
[[3]](diffhunk://#diff-52e0837e84d49221d1b810d88fdf78221f36cffcd664fb42f8aba49a79b974dcL15-R19)
[[4]](diffhunk://#diff-11c3457d1a23a4ca6ecd00d6b856289774936b6a708384cf03aff164044e7546L15-R19)
[[5]](diffhunk://#diff-2cff9cf8e6a0cc34087326d8c8149c3bbaf74c76fdbdf5a73daed13cc04249e1L15-R19)
[[6]](diffhunk://#diff-175edfeea54490b8fe4e18ffcbea5835efaf8f0b8acf623359073987cae7eb76L48-R55)
[[7]](diffhunk://#diff-e001b7a4b63603b9b14f00de78a4d570bb76c5f57d856a24643f071032e12356L66-R73)
[[8]](diffhunk://#diff-5582954e8a9983988dc8854ad82067fb2ac6269b988e07357ad8db1dfec5f1a0L39-R41)
**Container and utility updates:**
* Refactored the `garray` container implementation and related
constructors/methods to use `[]any` instead of `[]interface{}`, along
with corresponding function signatures.
[[1]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L31-R31)
[[2]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L52-R52)
[[3]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L62-R62)
[[4]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L73-R86)
[[5]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L96-R97)
[[6]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L107-R114)
[[7]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L124-R124)
[[8]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L135-R143)
[[9]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L167-R167)
These changes collectively modernize the codebase and prepare it for
future Go developments by using the idiomatic `any` type.
2025-08-28 16:53:19 +08:00
|
|
|
func (a *IntArray) DeepCopy() any {
|
2022-06-29 14:58:27 +08:00
|
|
|
if a == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2025-11-19 18:11:04 +08:00
|
|
|
a.lazyInit()
|
|
|
|
|
return &IntArray{
|
|
|
|
|
TArray: a.TArray.DeepCopy().(*TArray[int]),
|
|
|
|
|
}
|
2022-05-23 16:51:10 +08:00
|
|
|
}
|