mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
change default value from unsafe to safe for garray/gmap/glist/gset/grong/gtree/gjson/gparser
This commit is contained in:
@ -5,15 +5,3 @@
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package garray
|
||||
|
||||
type apiSliceInterface interface {
|
||||
Slice() []interface{}
|
||||
}
|
||||
|
||||
type apiSliceInt interface {
|
||||
Slice() []int
|
||||
}
|
||||
|
||||
type apiSliceString interface {
|
||||
Slice() []string
|
||||
}
|
||||
|
||||
@ -23,40 +23,40 @@ type IntArray struct {
|
||||
}
|
||||
|
||||
// NewIntArray creates and returns an empty array.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewIntArray(unsafe ...bool) *IntArray {
|
||||
return NewIntArraySize(0, 0, unsafe...)
|
||||
func NewIntArray(safe ...bool) *IntArray {
|
||||
return NewIntArraySize(0, 0, safe...)
|
||||
}
|
||||
|
||||
// NewIntArraySize create and returns an array with given size and cap.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewIntArraySize(size int, cap int, unsafe ...bool) *IntArray {
|
||||
func NewIntArraySize(size int, cap int, safe ...bool) *IntArray {
|
||||
return &IntArray{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: make([]int, size, cap),
|
||||
}
|
||||
}
|
||||
|
||||
// NewIntArrayFrom creates and returns an array with given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewIntArrayFrom(array []int, unsafe ...bool) *IntArray {
|
||||
func NewIntArrayFrom(array []int, safe ...bool) *IntArray {
|
||||
return &IntArray{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: array,
|
||||
}
|
||||
}
|
||||
|
||||
// NewIntArrayFromCopy creates and returns an array from a copy of given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewIntArrayFromCopy(array []int, unsafe ...bool) *IntArray {
|
||||
func NewIntArrayFromCopy(array []int, safe ...bool) *IntArray {
|
||||
newArray := make([]int, len(array))
|
||||
copy(newArray, array)
|
||||
return &IntArray{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: newArray,
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,55 +23,55 @@ type Array struct {
|
||||
}
|
||||
|
||||
// New creates and returns an empty array.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func New(unsafe ...bool) *Array {
|
||||
return NewArraySize(0, 0, unsafe...)
|
||||
func New(safe ...bool) *Array {
|
||||
return NewArraySize(0, 0, safe...)
|
||||
}
|
||||
|
||||
// See New.
|
||||
func NewArray(unsafe ...bool) *Array {
|
||||
return NewArraySize(0, 0, unsafe...)
|
||||
func NewArray(safe ...bool) *Array {
|
||||
return NewArraySize(0, 0, safe...)
|
||||
}
|
||||
|
||||
// NewArraySize create and returns an array with given size and cap.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewArraySize(size int, cap int, unsafe ...bool) *Array {
|
||||
func NewArraySize(size int, cap int, safe ...bool) *Array {
|
||||
return &Array{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: make([]interface{}, size, cap),
|
||||
}
|
||||
}
|
||||
|
||||
// See NewArrayFrom.
|
||||
func NewFrom(array []interface{}, unsafe ...bool) *Array {
|
||||
return NewArrayFrom(array, unsafe...)
|
||||
func NewFrom(array []interface{}, safe ...bool) *Array {
|
||||
return NewArrayFrom(array, safe...)
|
||||
}
|
||||
|
||||
// See NewArrayFromCopy.
|
||||
func NewFromCopy(array []interface{}, unsafe ...bool) *Array {
|
||||
return NewArrayFromCopy(array, unsafe...)
|
||||
func NewFromCopy(array []interface{}, safe ...bool) *Array {
|
||||
return NewArrayFromCopy(array, safe...)
|
||||
}
|
||||
|
||||
// NewArrayFrom creates and returns an array with given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewArrayFrom(array []interface{}, unsafe ...bool) *Array {
|
||||
func NewArrayFrom(array []interface{}, safe ...bool) *Array {
|
||||
return &Array{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: array,
|
||||
}
|
||||
}
|
||||
|
||||
// NewArrayFromCopy creates and returns an array from a copy of given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewArrayFromCopy(array []interface{}, unsafe ...bool) *Array {
|
||||
func NewArrayFromCopy(array []interface{}, safe ...bool) *Array {
|
||||
newArray := make([]interface{}, len(array))
|
||||
copy(newArray, array)
|
||||
return &Array{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: newArray,
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,40 +24,40 @@ type StringArray struct {
|
||||
}
|
||||
|
||||
// NewStringArray creates and returns an empty array.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewStringArray(unsafe ...bool) *StringArray {
|
||||
return NewStringArraySize(0, 0, unsafe...)
|
||||
func NewStringArray(safe ...bool) *StringArray {
|
||||
return NewStringArraySize(0, 0, safe...)
|
||||
}
|
||||
|
||||
// NewStringArraySize create and returns an array with given size and cap.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewStringArraySize(size int, cap int, unsafe ...bool) *StringArray {
|
||||
func NewStringArraySize(size int, cap int, safe ...bool) *StringArray {
|
||||
return &StringArray{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: make([]string, size, cap),
|
||||
}
|
||||
}
|
||||
|
||||
// NewStringArrayFrom creates and returns an array with given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewStringArrayFrom(array []string, unsafe ...bool) *StringArray {
|
||||
func NewStringArrayFrom(array []string, safe ...bool) *StringArray {
|
||||
return &StringArray{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: array,
|
||||
}
|
||||
}
|
||||
|
||||
// NewStringArrayFromCopy creates and returns an array from a copy of given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewStringArrayFromCopy(array []string, unsafe ...bool) *StringArray {
|
||||
func NewStringArrayFromCopy(array []string, safe ...bool) *StringArray {
|
||||
newArray := make([]string, len(array))
|
||||
copy(newArray, array)
|
||||
return &StringArray{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: newArray,
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,18 +27,18 @@ type SortedIntArray struct {
|
||||
}
|
||||
|
||||
// NewSortedIntArray creates and returns an empty sorted array.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedIntArray(unsafe ...bool) *SortedIntArray {
|
||||
return NewSortedIntArraySize(0, unsafe...)
|
||||
func NewSortedIntArray(safe ...bool) *SortedIntArray {
|
||||
return NewSortedIntArraySize(0, safe...)
|
||||
}
|
||||
|
||||
// NewSortedIntArraySize create and returns an sorted array with given size and cap.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedIntArraySize(cap int, unsafe ...bool) *SortedIntArray {
|
||||
func NewSortedIntArraySize(cap int, safe ...bool) *SortedIntArray {
|
||||
return &SortedIntArray{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: make([]int, 0, cap),
|
||||
unique: gtype.NewBool(),
|
||||
comparator: func(v1, v2 int) int {
|
||||
@ -54,22 +54,22 @@ func NewSortedIntArraySize(cap int, unsafe ...bool) *SortedIntArray {
|
||||
}
|
||||
|
||||
// NewIntArrayFrom creates and returns an sorted array with given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedIntArrayFrom(array []int, unsafe ...bool) *SortedIntArray {
|
||||
a := NewSortedIntArraySize(0, unsafe...)
|
||||
func NewSortedIntArrayFrom(array []int, safe ...bool) *SortedIntArray {
|
||||
a := NewSortedIntArraySize(0, safe...)
|
||||
a.array = array
|
||||
sort.Ints(a.array)
|
||||
return a
|
||||
}
|
||||
|
||||
// NewSortedIntArrayFromCopy creates and returns an sorted array from a copy of given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedIntArrayFromCopy(array []int, unsafe ...bool) *SortedIntArray {
|
||||
func NewSortedIntArrayFromCopy(array []int, safe ...bool) *SortedIntArray {
|
||||
newArray := make([]int, len(array))
|
||||
copy(newArray, array)
|
||||
return NewSortedIntArrayFrom(newArray, unsafe...)
|
||||
return NewSortedIntArrayFrom(newArray, safe...)
|
||||
}
|
||||
|
||||
// SetArray sets the underlying slice array with the given <array>.
|
||||
|
||||
@ -27,21 +27,21 @@ type SortedArray struct {
|
||||
}
|
||||
|
||||
// NewSortedArray creates and returns an empty sorted array.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety, which is false in default.
|
||||
// The parameter <comparator> used to compare values to sort in array,
|
||||
// if it returns value < 0, means v1 < v2;
|
||||
// if it returns value = 0, means v1 = v2;
|
||||
// if it returns value > 0, means v1 > v2;
|
||||
func NewSortedArray(comparator func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray {
|
||||
return NewSortedArraySize(0, comparator, unsafe...)
|
||||
func NewSortedArray(comparator func(v1, v2 interface{}) int, safe ...bool) *SortedArray {
|
||||
return NewSortedArraySize(0, comparator, safe...)
|
||||
}
|
||||
|
||||
// NewSortedArraySize create and returns an sorted array with given size and cap.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedArraySize(cap int, comparator func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray {
|
||||
func NewSortedArraySize(cap int, comparator func(v1, v2 interface{}) int, safe ...bool) *SortedArray {
|
||||
return &SortedArray{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
unique: gtype.NewBool(),
|
||||
array: make([]interface{}, 0, cap),
|
||||
comparator: comparator,
|
||||
@ -49,10 +49,10 @@ func NewSortedArraySize(cap int, comparator func(v1, v2 interface{}) int, unsafe
|
||||
}
|
||||
|
||||
// NewSortedArrayFrom creates and returns an sorted array with given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedArrayFrom(array []interface{}, comparator func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray {
|
||||
a := NewSortedArraySize(0, comparator, unsafe...)
|
||||
func NewSortedArrayFrom(array []interface{}, comparator func(v1, v2 interface{}) int, safe ...bool) *SortedArray {
|
||||
a := NewSortedArraySize(0, comparator, safe...)
|
||||
a.array = array
|
||||
sort.Slice(a.array, func(i, j int) bool {
|
||||
return a.comparator(a.array[i], a.array[j]) < 0
|
||||
@ -61,12 +61,12 @@ func NewSortedArrayFrom(array []interface{}, comparator func(v1, v2 interface{})
|
||||
}
|
||||
|
||||
// NewSortedArrayFromCopy creates and returns an sorted array from a copy of given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedArrayFromCopy(array []interface{}, comparator func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray {
|
||||
func NewSortedArrayFromCopy(array []interface{}, comparator func(v1, v2 interface{}) int, safe ...bool) *SortedArray {
|
||||
newArray := make([]interface{}, len(array))
|
||||
copy(newArray, array)
|
||||
return NewSortedArrayFrom(newArray, comparator, unsafe...)
|
||||
return NewSortedArrayFrom(newArray, comparator, safe...)
|
||||
}
|
||||
|
||||
// SetArray sets the underlying slice array with the given <array>.
|
||||
|
||||
@ -28,18 +28,18 @@ type SortedStringArray struct {
|
||||
}
|
||||
|
||||
// NewSortedStringArray creates and returns an empty sorted array.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedStringArray(unsafe ...bool) *SortedStringArray {
|
||||
return NewSortedStringArraySize(0, unsafe...)
|
||||
func NewSortedStringArray(safe ...bool) *SortedStringArray {
|
||||
return NewSortedStringArraySize(0, safe...)
|
||||
}
|
||||
|
||||
// NewSortedStringArraySize create and returns an sorted array with given size and cap.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedStringArraySize(cap int, unsafe ...bool) *SortedStringArray {
|
||||
func NewSortedStringArraySize(cap int, safe ...bool) *SortedStringArray {
|
||||
return &SortedStringArray{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
array: make([]string, 0, cap),
|
||||
unique: gtype.NewBool(),
|
||||
comparator: func(v1, v2 string) int {
|
||||
@ -49,22 +49,22 @@ func NewSortedStringArraySize(cap int, unsafe ...bool) *SortedStringArray {
|
||||
}
|
||||
|
||||
// NewSortedStringArrayFrom creates and returns an sorted array with given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedStringArrayFrom(array []string, unsafe ...bool) *SortedStringArray {
|
||||
a := NewSortedStringArraySize(0, unsafe...)
|
||||
func NewSortedStringArrayFrom(array []string, safe ...bool) *SortedStringArray {
|
||||
a := NewSortedStringArraySize(0, safe...)
|
||||
a.array = array
|
||||
sort.Strings(a.array)
|
||||
return a
|
||||
}
|
||||
|
||||
// NewSortedStringArrayFromCopy creates and returns an sorted array from a copy of given slice <array>.
|
||||
// The parameter <unsafe> used to specify whether using array in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using array in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewSortedStringArrayFromCopy(array []string, unsafe ...bool) *SortedStringArray {
|
||||
func NewSortedStringArrayFromCopy(array []string, safe ...bool) *SortedStringArray {
|
||||
newArray := make([]string, len(array))
|
||||
copy(newArray, array)
|
||||
return NewSortedStringArrayFrom(newArray, unsafe...)
|
||||
return NewSortedStringArrayFrom(newArray, safe...)
|
||||
}
|
||||
|
||||
// SetArray sets the underlying slice array with the given <array>.
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
|
||||
func Example_basic() {
|
||||
// 创建普通的数组,默认并发安全(带锁)
|
||||
a := garray.New()
|
||||
a := garray.New(true)
|
||||
|
||||
// 添加数据项
|
||||
for i := 0; i < 10; i++ {
|
||||
|
||||
@ -659,7 +659,7 @@ func TestIntArray_Remove(t *testing.T) {
|
||||
func TestIntArray_LockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s1 := []int{1, 2, 3, 4}
|
||||
a1 := garray.NewIntArrayFrom(s1)
|
||||
a1 := garray.NewIntArrayFrom(s1, true)
|
||||
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 3)
|
||||
@ -704,7 +704,7 @@ func TestIntArray_SortFunc(t *testing.T) {
|
||||
func TestIntArray_RLockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s1 := []int{1, 2, 3, 4}
|
||||
a1 := garray.NewIntArrayFrom(s1)
|
||||
a1 := garray.NewIntArrayFrom(s1, true)
|
||||
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 1)
|
||||
@ -736,7 +736,7 @@ func TestIntArray_RLockFunc(t *testing.T) {
|
||||
func TestSortedIntArray_LockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s1 := []int{1, 2, 3, 4}
|
||||
a1 := garray.NewSortedIntArrayFrom(s1)
|
||||
a1 := garray.NewSortedIntArrayFrom(s1, true)
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 3)
|
||||
//go1
|
||||
@ -767,7 +767,7 @@ func TestSortedIntArray_LockFunc(t *testing.T) {
|
||||
func TestSortedIntArray_RLockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s1 := []int{1, 2, 3, 4}
|
||||
a1 := garray.NewSortedIntArrayFrom(s1)
|
||||
a1 := garray.NewSortedIntArrayFrom(s1, true)
|
||||
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 1)
|
||||
|
||||
@ -746,7 +746,7 @@ func TestSortedArray_LockFunc(t *testing.T) {
|
||||
return strings.Compare(gconv.String(v1), gconv.String(v2))
|
||||
}
|
||||
s1 := []interface{}{"a", "b", "c", "d"}
|
||||
a1 := garray.NewSortedArrayFrom(s1, func1)
|
||||
a1 := garray.NewSortedArrayFrom(s1, func1, true)
|
||||
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 3)
|
||||
@ -781,7 +781,7 @@ func TestSortedArray_RLockFunc(t *testing.T) {
|
||||
return strings.Compare(gconv.String(v1), gconv.String(v2))
|
||||
}
|
||||
s1 := []interface{}{"a", "b", "c", "d"}
|
||||
a1 := garray.NewSortedArrayFrom(s1, func1)
|
||||
a1 := garray.NewSortedArrayFrom(s1, func1, true)
|
||||
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 3)
|
||||
@ -844,7 +844,7 @@ func TestSortedArray_Merge(t *testing.T) {
|
||||
func TestArray_LockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s1 := []interface{}{"a", "b", "c", "d"}
|
||||
a1 := garray.NewArrayFrom(s1)
|
||||
a1 := garray.NewArrayFrom(s1, true)
|
||||
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 3)
|
||||
@ -876,7 +876,7 @@ func TestArray_LockFunc(t *testing.T) {
|
||||
func TestArray_RLockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s1 := []interface{}{"a", "b", "c", "d"}
|
||||
a1 := garray.NewArrayFrom(s1)
|
||||
a1 := garray.NewArrayFrom(s1, true)
|
||||
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 1)
|
||||
|
||||
@ -700,7 +700,7 @@ func TestStringArray_RLockFunc(t *testing.T) {
|
||||
func TestSortedStringArray_LockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s1 := []string{"a", "b", "c", "d"}
|
||||
a1 := garray.NewSortedStringArrayFrom(s1)
|
||||
a1 := garray.NewSortedStringArrayFrom(s1, true)
|
||||
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 3)
|
||||
@ -732,7 +732,7 @@ func TestSortedStringArray_LockFunc(t *testing.T) {
|
||||
func TestSortedStringArray_RLockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s1 := []string{"a", "b", "c", "d"}
|
||||
a1 := garray.NewSortedStringArrayFrom(s1)
|
||||
a1 := garray.NewSortedStringArrayFrom(s1, true)
|
||||
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 1)
|
||||
@ -805,7 +805,7 @@ func TestStringArray_SortFunc(t *testing.T) {
|
||||
func TestStringArray_LockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s1 := []string{"a", "b", "c", "d"}
|
||||
a1 := garray.NewStringArrayFrom(s1)
|
||||
a1 := garray.NewStringArrayFrom(s1, true)
|
||||
|
||||
ch1 := make(chan int64, 3)
|
||||
ch2 := make(chan int64, 3)
|
||||
|
||||
@ -23,9 +23,9 @@ type (
|
||||
)
|
||||
|
||||
// New creates and returns a new empty doubly linked list.
|
||||
func New(unsafe ...bool) *List {
|
||||
func New(safe ...bool) *List {
|
||||
return &List{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
list: list.New(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,10 +12,10 @@ type Map = AnyAnyMap
|
||||
type HashMap = AnyAnyMap
|
||||
|
||||
// New returns an empty hash map.
|
||||
// The parameter <unsafe> used to specify whether using map in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func New(unsafe ...bool) *Map {
|
||||
return NewAnyAnyMap(unsafe...)
|
||||
// The parameter <safe> used to specify whether using map in concurrent-safety,
|
||||
// which is false in default.
|
||||
func New(safe ...bool) *Map {
|
||||
return NewAnyAnyMap(safe...)
|
||||
}
|
||||
|
||||
// NewFrom returns a hash map from given map <data>.
|
||||
@ -23,15 +23,15 @@ func New(unsafe ...bool) *Map {
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
// The parameter <unsafe> used to specify whether using tree in un-concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewFrom(data map[interface{}]interface{}, unsafe ...bool) *Map {
|
||||
return NewAnyAnyMapFrom(data, unsafe...)
|
||||
func NewFrom(data map[interface{}]interface{}, safe ...bool) *Map {
|
||||
return NewAnyAnyMapFrom(data, safe...)
|
||||
}
|
||||
|
||||
// NewHashMap returns an empty hash map.
|
||||
// The parameter <unsafe> used to specify whether using map in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func NewHashMap(unsafe ...bool) *Map {
|
||||
return NewAnyAnyMap(unsafe...)
|
||||
// The parameter <safe> used to specify whether using map in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewHashMap(safe ...bool) *Map {
|
||||
return NewAnyAnyMap(safe...)
|
||||
}
|
||||
|
||||
// NewHashMapFrom returns a hash map from given map <data>.
|
||||
@ -39,6 +39,6 @@ func NewHashMap(unsafe ...bool) *Map {
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
// The parameter <unsafe> used to specify whether using tree in un-concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewHashMapFrom(data map[interface{}]interface{}, unsafe ...bool) *Map {
|
||||
return NewAnyAnyMapFrom(data, unsafe...)
|
||||
func NewHashMapFrom(data map[interface{}]interface{}, safe ...bool) *Map {
|
||||
return NewAnyAnyMapFrom(data, safe...)
|
||||
}
|
||||
|
||||
@ -21,11 +21,11 @@ type AnyAnyMap struct {
|
||||
}
|
||||
|
||||
// NewAnyAnyMap returns an empty hash map.
|
||||
// The parameter <unsafe> used to specify whether using map in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func NewAnyAnyMap(unsafe ...bool) *AnyAnyMap {
|
||||
// The parameter <safe> used to specify whether using map in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewAnyAnyMap(safe ...bool) *AnyAnyMap {
|
||||
return &AnyAnyMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: make(map[interface{}]interface{}),
|
||||
}
|
||||
}
|
||||
@ -33,9 +33,9 @@ func NewAnyAnyMap(unsafe ...bool) *AnyAnyMap {
|
||||
// NewAnyAnyMapFrom returns a hash map from given map <data>.
|
||||
// Note that, the param <data> map will be set as the underlying data map(no deep copy),
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
func NewAnyAnyMapFrom(data map[interface{}]interface{}, unsafe ...bool) *AnyAnyMap {
|
||||
func NewAnyAnyMapFrom(data map[interface{}]interface{}, safe ...bool) *AnyAnyMap {
|
||||
return &AnyAnyMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
@ -53,8 +53,8 @@ func (m *AnyAnyMap) Iterator(f func(k interface{}, v interface{}) bool) {
|
||||
}
|
||||
|
||||
// Clone returns a new hash map with copy of current map data.
|
||||
func (m *AnyAnyMap) Clone(unsafe ...bool) *AnyAnyMap {
|
||||
return NewFrom(m.Map(), unsafe...)
|
||||
func (m *AnyAnyMap) Clone(safe ...bool) *AnyAnyMap {
|
||||
return NewFrom(m.Map(), safe...)
|
||||
}
|
||||
|
||||
// Map returns a copy of the data of the hash map.
|
||||
@ -161,25 +161,25 @@ func (m *AnyAnyMap) GetOrSetFuncLock(key interface{}, f func() interface{}) inte
|
||||
// GetVar returns a gvar.Var with the value by given <key>.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *AnyAnyMap) GetVar(key interface{}) *gvar.Var {
|
||||
return gvar.New(m.Get(key), true)
|
||||
return gvar.New(m.Get(key))
|
||||
}
|
||||
|
||||
// GetVarOrSet returns a gvar.Var with result from GetVarOrSet.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *AnyAnyMap) GetVarOrSet(key interface{}, value interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSet(key, value), true)
|
||||
return gvar.New(m.GetOrSet(key, value))
|
||||
}
|
||||
|
||||
// GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *AnyAnyMap) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSetFunc(key, f), true)
|
||||
return gvar.New(m.GetOrSetFunc(key, f))
|
||||
}
|
||||
|
||||
// GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *AnyAnyMap) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSetFuncLock(key, f), true)
|
||||
return gvar.New(m.GetOrSetFuncLock(key, f))
|
||||
}
|
||||
|
||||
// SetIfNotExist sets <value> to the map if the <key> does not exist, then return true.
|
||||
|
||||
@ -21,11 +21,11 @@ type IntAnyMap struct {
|
||||
}
|
||||
|
||||
// NewIntAnyMap returns an empty IntAnyMap object.
|
||||
// The parameter <unsafe> used to specify whether using map in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func NewIntAnyMap(unsafe ...bool) *IntAnyMap {
|
||||
// The parameter <safe> used to specify whether using map in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewIntAnyMap(safe ...bool) *IntAnyMap {
|
||||
return &IntAnyMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: make(map[int]interface{}),
|
||||
}
|
||||
}
|
||||
@ -33,9 +33,9 @@ func NewIntAnyMap(unsafe ...bool) *IntAnyMap {
|
||||
// NewIntAnyMapFrom returns a hash map from given map <data>.
|
||||
// Note that, the param <data> map will be set as the underlying data map(no deep copy),
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
func NewIntAnyMapFrom(data map[int]interface{}, unsafe ...bool) *IntAnyMap {
|
||||
func NewIntAnyMapFrom(data map[int]interface{}, safe ...bool) *IntAnyMap {
|
||||
return &IntAnyMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
@ -161,25 +161,25 @@ func (m *IntAnyMap) GetOrSetFuncLock(key int, f func() interface{}) interface{}
|
||||
// GetVar returns a gvar.Var with the value by given <key>.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *IntAnyMap) GetVar(key int) *gvar.Var {
|
||||
return gvar.New(m.Get(key), true)
|
||||
return gvar.New(m.Get(key))
|
||||
}
|
||||
|
||||
// GetVarOrSet returns a gvar.Var with result from GetVarOrSet.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *IntAnyMap) GetVarOrSet(key int, value interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSet(key, value), true)
|
||||
return gvar.New(m.GetOrSet(key, value))
|
||||
}
|
||||
|
||||
// GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *IntAnyMap) GetVarOrSetFunc(key int, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSetFunc(key, f), true)
|
||||
return gvar.New(m.GetOrSetFunc(key, f))
|
||||
}
|
||||
|
||||
// GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *IntAnyMap) GetVarOrSetFuncLock(key int, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSetFuncLock(key, f), true)
|
||||
return gvar.New(m.GetOrSetFuncLock(key, f))
|
||||
}
|
||||
|
||||
// SetIfNotExist sets <value> to the map if the <key> does not exist, then return true.
|
||||
|
||||
@ -18,11 +18,11 @@ type IntIntMap struct {
|
||||
}
|
||||
|
||||
// NewIntIntMap returns an empty IntIntMap object.
|
||||
// The parameter <unsafe> used to specify whether using map in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func NewIntIntMap(unsafe ...bool) *IntIntMap {
|
||||
// The parameter <safe> used to specify whether using map in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewIntIntMap(safe ...bool) *IntIntMap {
|
||||
return &IntIntMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: make(map[int]int),
|
||||
}
|
||||
}
|
||||
@ -30,9 +30,9 @@ func NewIntIntMap(unsafe ...bool) *IntIntMap {
|
||||
// NewIntIntMapFrom returns a hash map from given map <data>.
|
||||
// Note that, the param <data> map will be set as the underlying data map(no deep copy),
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
func NewIntIntMapFrom(data map[int]int, unsafe ...bool) *IntIntMap {
|
||||
func NewIntIntMapFrom(data map[int]int, safe ...bool) *IntIntMap {
|
||||
return &IntIntMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,11 +19,11 @@ type IntStrMap struct {
|
||||
}
|
||||
|
||||
// NewIntStrMap returns an empty IntStrMap object.
|
||||
// The parameter <unsafe> used to specify whether using map in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func NewIntStrMap(unsafe ...bool) *IntStrMap {
|
||||
// The parameter <safe> used to specify whether using map in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewIntStrMap(safe ...bool) *IntStrMap {
|
||||
return &IntStrMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: make(map[int]string),
|
||||
}
|
||||
}
|
||||
@ -31,9 +31,9 @@ func NewIntStrMap(unsafe ...bool) *IntStrMap {
|
||||
// NewIntStrMapFrom returns a hash map from given map <data>.
|
||||
// Note that, the param <data> map will be set as the underlying data map(no deep copy),
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
func NewIntStrMapFrom(data map[int]string, unsafe ...bool) *IntStrMap {
|
||||
func NewIntStrMapFrom(data map[int]string, safe ...bool) *IntStrMap {
|
||||
return &IntStrMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,11 +21,11 @@ type StrAnyMap struct {
|
||||
}
|
||||
|
||||
// NewStrAnyMap returns an empty StrAnyMap object.
|
||||
// The parameter <unsafe> used to specify whether using map in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func NewStrAnyMap(unsafe ...bool) *StrAnyMap {
|
||||
// The parameter <safe> used to specify whether using map in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewStrAnyMap(safe ...bool) *StrAnyMap {
|
||||
return &StrAnyMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: make(map[string]interface{}),
|
||||
}
|
||||
}
|
||||
@ -33,9 +33,9 @@ func NewStrAnyMap(unsafe ...bool) *StrAnyMap {
|
||||
// NewStrAnyMapFrom returns a hash map from given map <data>.
|
||||
// Note that, the param <data> map will be set as the underlying data map(no deep copy),
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
func NewStrAnyMapFrom(data map[string]interface{}, unsafe ...bool) *StrAnyMap {
|
||||
func NewStrAnyMapFrom(data map[string]interface{}, safe ...bool) *StrAnyMap {
|
||||
return &StrAnyMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
@ -163,25 +163,25 @@ func (m *StrAnyMap) GetOrSetFuncLock(key string, f func() interface{}) interface
|
||||
// GetVar returns a gvar.Var with the value by given <key>.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *StrAnyMap) GetVar(key string) *gvar.Var {
|
||||
return gvar.New(m.Get(key), true)
|
||||
return gvar.New(m.Get(key))
|
||||
}
|
||||
|
||||
// GetVarOrSet returns a gvar.Var with result from GetVarOrSet.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *StrAnyMap) GetVarOrSet(key string, value interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSet(key, value), true)
|
||||
return gvar.New(m.GetOrSet(key, value))
|
||||
}
|
||||
|
||||
// GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *StrAnyMap) GetVarOrSetFunc(key string, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSetFunc(key, f), true)
|
||||
return gvar.New(m.GetOrSetFunc(key, f))
|
||||
}
|
||||
|
||||
// GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *StrAnyMap) GetVarOrSetFuncLock(key string, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSetFuncLock(key, f), true)
|
||||
return gvar.New(m.GetOrSetFuncLock(key, f))
|
||||
}
|
||||
|
||||
// SetIfNotExist sets <value> to the map if the <key> does not exist, then return true.
|
||||
|
||||
@ -20,11 +20,11 @@ type StrIntMap struct {
|
||||
}
|
||||
|
||||
// NewStrIntMap returns an empty StrIntMap object.
|
||||
// The parameter <unsafe> used to specify whether using map in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func NewStrIntMap(unsafe ...bool) *StrIntMap {
|
||||
// The parameter <safe> used to specify whether using map in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewStrIntMap(safe ...bool) *StrIntMap {
|
||||
return &StrIntMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: make(map[string]int),
|
||||
}
|
||||
}
|
||||
@ -32,9 +32,9 @@ func NewStrIntMap(unsafe ...bool) *StrIntMap {
|
||||
// NewStrIntMapFrom returns a hash map from given map <data>.
|
||||
// Note that, the param <data> map will be set as the underlying data map(no deep copy),
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
func NewStrIntMapFrom(data map[string]int, unsafe ...bool) *StrIntMap {
|
||||
func NewStrIntMapFrom(data map[string]int, safe ...bool) *StrIntMap {
|
||||
return &StrIntMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,21 +19,21 @@ type StrStrMap struct {
|
||||
}
|
||||
|
||||
// NewStrStrMap returns an empty StrStrMap object.
|
||||
// The parameter <unsafe> used to specify whether using map in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func NewStrStrMap(unsafe ...bool) *StrStrMap {
|
||||
// The parameter <safe> used to specify whether using map in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewStrStrMap(safe ...bool) *StrStrMap {
|
||||
return &StrStrMap{
|
||||
data: make(map[string]string),
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
}
|
||||
}
|
||||
|
||||
// NewStrStrMapFrom returns a hash map from given map <data>.
|
||||
// Note that, the param <data> map will be set as the underlying data map(no deep copy),
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
func NewStrStrMapFrom(data map[string]string, unsafe ...bool) *StrStrMap {
|
||||
func NewStrStrMapFrom(data map[string]string, safe ...bool) *StrStrMap {
|
||||
return &StrStrMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,21 +29,21 @@ type gListMapNode struct {
|
||||
|
||||
// NewListMap returns an empty link map.
|
||||
// ListMap is backed by a hash table to store values and doubly-linked list to store ordering.
|
||||
// The parameter <unsafe> used to specify whether using map in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func NewListMap(unsafe ...bool) *ListMap {
|
||||
// The parameter <safe> used to specify whether using map in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewListMap(safe ...bool) *ListMap {
|
||||
return &ListMap{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
data: make(map[interface{}]*glist.Element),
|
||||
list: glist.New(true),
|
||||
list: glist.New(),
|
||||
}
|
||||
}
|
||||
|
||||
// NewListMapFrom returns a link map from given map <data>.
|
||||
// Note that, the param <data> map will be set as the underlying data map(no deep copy),
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
func NewListMapFrom(data map[interface{}]interface{}, unsafe ...bool) *ListMap {
|
||||
m := NewListMap(unsafe...)
|
||||
func NewListMapFrom(data map[interface{}]interface{}, safe ...bool) *ListMap {
|
||||
m := NewListMap(safe...)
|
||||
m.Sets(data)
|
||||
return m
|
||||
}
|
||||
@ -78,15 +78,15 @@ func (m *ListMap) IteratorDesc(f func(key interface{}, value interface{}) bool)
|
||||
}
|
||||
|
||||
// Clone returns a new link map with copy of current map data.
|
||||
func (m *ListMap) Clone(unsafe ...bool) *ListMap {
|
||||
return NewListMapFrom(m.Map(), unsafe...)
|
||||
func (m *ListMap) Clone(safe ...bool) *ListMap {
|
||||
return NewListMapFrom(m.Map(), safe...)
|
||||
}
|
||||
|
||||
// Clear deletes all data of the map, it will remake a new underlying data map.
|
||||
func (m *ListMap) Clear() {
|
||||
m.mu.Lock()
|
||||
m.data = make(map[interface{}]*glist.Element)
|
||||
m.list = glist.New(true)
|
||||
m.list = glist.New()
|
||||
m.mu.Unlock()
|
||||
}
|
||||
|
||||
@ -210,25 +210,25 @@ func (m *ListMap) GetOrSetFuncLock(key interface{}, f func() interface{}) interf
|
||||
// GetVar returns a gvar.Var with the value by given <key>.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *ListMap) GetVar(key interface{}) *gvar.Var {
|
||||
return gvar.New(m.Get(key), true)
|
||||
return gvar.New(m.Get(key))
|
||||
}
|
||||
|
||||
// GetVarOrSet returns a gvar.Var with result from GetVarOrSet.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *ListMap) GetVarOrSet(key interface{}, value interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSet(key, value), true)
|
||||
return gvar.New(m.GetOrSet(key, value))
|
||||
}
|
||||
|
||||
// GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *ListMap) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSetFunc(key, f), true)
|
||||
return gvar.New(m.GetOrSetFunc(key, f))
|
||||
}
|
||||
|
||||
// GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (m *ListMap) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(m.GetOrSetFuncLock(key, f), true)
|
||||
return gvar.New(m.GetOrSetFuncLock(key, f))
|
||||
}
|
||||
|
||||
// SetIfNotExist sets <value> to the map if the <key> does not exist, then return true.
|
||||
|
||||
@ -16,8 +16,8 @@ type TreeMap = gtree.RedBlackTree
|
||||
// NewTreeMap instantiates a tree map with the custom comparator.
|
||||
// The parameter <unsafe> used to specify whether using tree in un-concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewTreeMap(comparator func(v1, v2 interface{}) int, unsafe ...bool) *TreeMap {
|
||||
return gtree.NewRedBlackTree(comparator, unsafe...)
|
||||
func NewTreeMap(comparator func(v1, v2 interface{}) int, safe ...bool) *TreeMap {
|
||||
return gtree.NewRedBlackTree(comparator, safe...)
|
||||
}
|
||||
|
||||
// NewTreeMapFrom instantiates a tree map with the custom comparator and <data> map.
|
||||
@ -25,6 +25,6 @@ func NewTreeMap(comparator func(v1, v2 interface{}) int, unsafe ...bool) *TreeMa
|
||||
// there might be some concurrent-safe issues when changing the map outside.
|
||||
// The parameter <unsafe> used to specify whether using tree in un-concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewTreeMapFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *TreeMap {
|
||||
return gtree.NewRedBlackTreeFrom(comparator, data, unsafe...)
|
||||
func NewTreeMapFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *TreeMap {
|
||||
return gtree.NewRedBlackTreeFrom(comparator, data, safe...)
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ type ExpireFunc func(interface{})
|
||||
// Note that the expiration time unit is ** milliseconds **.
|
||||
func New(expire int, newFunc NewFunc, expireFunc ...ExpireFunc) *Pool {
|
||||
r := &Pool{
|
||||
list: glist.New(),
|
||||
list: glist.New(true),
|
||||
closed: gtype.NewBool(),
|
||||
Expire: int64(expire),
|
||||
NewFunc: newFunc,
|
||||
|
||||
@ -50,7 +50,7 @@ func New(limit ...int) *Queue {
|
||||
q.limit = limit[0]
|
||||
q.C = make(chan interface{}, limit[0])
|
||||
} else {
|
||||
q.list = glist.New()
|
||||
q.list = glist.New(true)
|
||||
q.events = make(chan struct{}, math.MaxInt32)
|
||||
q.C = make(chan interface{}, gDEFAULT_QUEUE_SIZE)
|
||||
go q.startAsyncLoop()
|
||||
|
||||
@ -18,13 +18,12 @@ type Ring struct {
|
||||
ring *ring.Ring // Underlying ring.
|
||||
len *gtype.Int // Length(already used size).
|
||||
cap *gtype.Int // Capability(>=len).
|
||||
dirty *gtype.Bool // Dirty, which means the len and cap should be recalculated.
|
||||
// It's marked dirty when the size of ring changes.
|
||||
dirty *gtype.Bool // Dirty, which means the len and cap should be recalculated. It's marked dirty when the size of ring changes.
|
||||
}
|
||||
|
||||
func New(cap int, unsafe ...bool) *Ring {
|
||||
func New(cap int, safe ...bool) *Ring {
|
||||
return &Ring{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
ring: ring.New(cap),
|
||||
len: gtype.NewInt(),
|
||||
cap: gtype.NewInt(cap),
|
||||
|
||||
@ -21,28 +21,28 @@ type Set struct {
|
||||
// New create and returns a new set, which contains un-repeated items.
|
||||
// The parameter <unsafe> used to specify whether using set in un-concurrent-safety,
|
||||
// which is false in default.
|
||||
func New(unsafe ...bool) *Set {
|
||||
return NewSet(unsafe...)
|
||||
func New(safe ...bool) *Set {
|
||||
return NewSet(safe...)
|
||||
}
|
||||
|
||||
// See New.
|
||||
func NewSet(unsafe ...bool) *Set {
|
||||
func NewSet(safe ...bool) *Set {
|
||||
return &Set{
|
||||
m: make(map[interface{}]struct{}),
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
}
|
||||
}
|
||||
|
||||
// NewFrom returns a new set from <items>.
|
||||
// Parameter <items> can be either a variable of any type, or a slice.
|
||||
func NewFrom(items interface{}, unsafe ...bool) *Set {
|
||||
func NewFrom(items interface{}, safe ...bool) *Set {
|
||||
m := make(map[interface{}]struct{})
|
||||
for _, v := range gconv.Interfaces(items) {
|
||||
m[v] = struct{}{}
|
||||
}
|
||||
return &Set{
|
||||
m: m,
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,22 +21,22 @@ type IntSet struct {
|
||||
// New create and returns a new set, which contains un-repeated items.
|
||||
// The parameter <unsafe> used to specify whether using set in un-concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewIntSet(unsafe ...bool) *IntSet {
|
||||
func NewIntSet(safe ...bool) *IntSet {
|
||||
return &IntSet{
|
||||
m: make(map[int]struct{}),
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
}
|
||||
}
|
||||
|
||||
// NewIntSetFrom returns a new set from <items>.
|
||||
func NewIntSetFrom(items []int, unsafe ...bool) *IntSet {
|
||||
func NewIntSetFrom(items []int, safe ...bool) *IntSet {
|
||||
m := make(map[int]struct{})
|
||||
for _, v := range items {
|
||||
m[v] = struct{}{}
|
||||
}
|
||||
return &IntSet{
|
||||
m: m,
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,22 +21,22 @@ type StringSet struct {
|
||||
// New create and returns a new set, which contains un-repeated items.
|
||||
// The parameter <unsafe> used to specify whether using set in un-concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewStringSet(unsafe ...bool) *StringSet {
|
||||
func NewStringSet(safe ...bool) *StringSet {
|
||||
return &StringSet{
|
||||
m: make(map[string]struct{}),
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
}
|
||||
}
|
||||
|
||||
// NewStringSetFrom returns a new set from <items>.
|
||||
func NewStringSetFrom(items []string, unsafe ...bool) *StringSet {
|
||||
func NewStringSetFrom(items []string, safe ...bool) *StringSet {
|
||||
m := make(map[string]struct{})
|
||||
for _, v := range items {
|
||||
m[v] = struct{}{}
|
||||
}
|
||||
return &StringSet{
|
||||
m: m,
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -42,8 +42,8 @@ func TestIntSet_Iterator(t *testing.T) {
|
||||
s.Add(1).Add(2).Add(3)
|
||||
gtest.Assert(s.Size(), 3)
|
||||
|
||||
a1 := garray.New()
|
||||
a2 := garray.New()
|
||||
a1 := garray.New(true)
|
||||
a2 := garray.New(true)
|
||||
s.Iterator(func(v int) bool {
|
||||
a1.Append(1)
|
||||
return false
|
||||
|
||||
@ -42,8 +42,8 @@ func TestStringSet_Iterator(t *testing.T) {
|
||||
s.Add("1").Add("2").Add("3")
|
||||
gtest.Assert(s.Size(), 3)
|
||||
|
||||
a1 := garray.New()
|
||||
a2 := garray.New()
|
||||
a1 := garray.New(true)
|
||||
a2 := garray.New(true)
|
||||
s.Iterator(func(v string) bool {
|
||||
a1.Append("1")
|
||||
return false
|
||||
|
||||
@ -63,8 +63,8 @@ func TestSet_Iterator(t *testing.T) {
|
||||
s.Add(1).Add(2).Add(3)
|
||||
gtest.Assert(s.Size(), 3)
|
||||
|
||||
a1 := garray.New()
|
||||
a2 := garray.New()
|
||||
a1 := garray.New(true)
|
||||
a2 := garray.New(true)
|
||||
s.Iterator(func(v interface{}) bool {
|
||||
a1.Append(1)
|
||||
return false
|
||||
|
||||
@ -32,20 +32,20 @@ type AVLTreeNode struct {
|
||||
}
|
||||
|
||||
// NewAVLTree instantiates an AVL tree with the custom key comparator.
|
||||
// The parameter <unsafe> used to specify whether using tree in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using tree in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewAVLTree(comparator func(v1, v2 interface{}) int, unsafe ...bool) *AVLTree {
|
||||
func NewAVLTree(comparator func(v1, v2 interface{}) int, safe ...bool) *AVLTree {
|
||||
return &AVLTree{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
comparator: comparator,
|
||||
}
|
||||
}
|
||||
|
||||
// NewAVLTreeFrom instantiates an AVL tree with the custom key comparator and data map.
|
||||
// The parameter <unsafe> used to specify whether using tree in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using tree in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewAVLTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *AVLTree {
|
||||
tree := NewAVLTree(comparator, unsafe...)
|
||||
func NewAVLTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *AVLTree {
|
||||
tree := NewAVLTree(comparator, safe...)
|
||||
for k, v := range data {
|
||||
tree.put(k, v, nil, &tree.root)
|
||||
}
|
||||
@ -53,7 +53,7 @@ func NewAVLTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{
|
||||
}
|
||||
|
||||
// Clone returns a new tree with a copy of current tree.
|
||||
func (tree *AVLTree) Clone(unsafe ...bool) *AVLTree {
|
||||
func (tree *AVLTree) Clone(safe ...bool) *AVLTree {
|
||||
newTree := NewAVLTree(tree.comparator, !tree.mu.IsSafe())
|
||||
newTree.Sets(tree.Map())
|
||||
return newTree
|
||||
@ -167,25 +167,25 @@ func (tree *AVLTree) GetOrSetFuncLock(key interface{}, f func() interface{}) int
|
||||
// GetVar returns a gvar.Var with the value by given <key>.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *AVLTree) GetVar(key interface{}) *gvar.Var {
|
||||
return gvar.New(tree.Get(key), true)
|
||||
return gvar.New(tree.Get(key))
|
||||
}
|
||||
|
||||
// GetVarOrSet returns a gvar.Var with result from GetVarOrSet.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *AVLTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var {
|
||||
return gvar.New(tree.GetOrSet(key, value), true)
|
||||
return gvar.New(tree.GetOrSet(key, value))
|
||||
}
|
||||
|
||||
// GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *AVLTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(tree.GetOrSetFunc(key, f), true)
|
||||
return gvar.New(tree.GetOrSetFunc(key, f))
|
||||
}
|
||||
|
||||
// GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *AVLTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(tree.GetOrSetFuncLock(key, f), true)
|
||||
return gvar.New(tree.GetOrSetFuncLock(key, f))
|
||||
}
|
||||
|
||||
// SetIfNotExist sets <value> to the map if the <key> does not exist, then return true.
|
||||
|
||||
@ -39,25 +39,25 @@ type BTreeEntry struct {
|
||||
}
|
||||
|
||||
// NewBTree instantiates a B-tree with <m> (maximum number of children) and a custom key comparator.
|
||||
// The parameter <unsafe> used to specify whether using tree in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using tree in concurrent-safety,
|
||||
// which is false in default.
|
||||
// Note that the <m> must be greater or equal than 3, or else it panics.
|
||||
func NewBTree(m int, comparator func(v1, v2 interface{}) int, unsafe ...bool) *BTree {
|
||||
func NewBTree(m int, comparator func(v1, v2 interface{}) int, safe ...bool) *BTree {
|
||||
if m < 3 {
|
||||
panic("Invalid order, should be at least 3")
|
||||
}
|
||||
return &BTree{
|
||||
comparator: comparator,
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
m: m,
|
||||
}
|
||||
}
|
||||
|
||||
// NewBTreeFrom instantiates a B-tree with <m> (maximum number of children), a custom key comparator and data map.
|
||||
// The parameter <unsafe> used to specify whether using tree in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using tree in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewBTreeFrom(m int, comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *BTree {
|
||||
tree := NewBTree(m, comparator, unsafe...)
|
||||
func NewBTreeFrom(m int, comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *BTree {
|
||||
tree := NewBTree(m, comparator, safe...)
|
||||
for k, v := range data {
|
||||
tree.doSet(k, v)
|
||||
}
|
||||
@ -65,7 +65,7 @@ func NewBTreeFrom(m int, comparator func(v1, v2 interface{}) int, data map[inter
|
||||
}
|
||||
|
||||
// Clone returns a new tree with a copy of current tree.
|
||||
func (tree *BTree) Clone(unsafe ...bool) *BTree {
|
||||
func (tree *BTree) Clone(safe ...bool) *BTree {
|
||||
newTree := NewBTree(tree.m, tree.comparator, !tree.mu.IsSafe())
|
||||
newTree.Sets(tree.Map())
|
||||
return newTree
|
||||
@ -168,25 +168,25 @@ func (tree *BTree) GetOrSetFuncLock(key interface{}, f func() interface{}) inter
|
||||
// GetVar returns a gvar.Var with the value by given <key>.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *BTree) GetVar(key interface{}) *gvar.Var {
|
||||
return gvar.New(tree.Get(key), true)
|
||||
return gvar.New(tree.Get(key))
|
||||
}
|
||||
|
||||
// GetVarOrSet returns a gvar.Var with result from GetVarOrSet.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *BTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var {
|
||||
return gvar.New(tree.GetOrSet(key, value), true)
|
||||
return gvar.New(tree.GetOrSet(key, value))
|
||||
}
|
||||
|
||||
// GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *BTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(tree.GetOrSetFunc(key, f), true)
|
||||
return gvar.New(tree.GetOrSetFunc(key, f))
|
||||
}
|
||||
|
||||
// GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *BTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(tree.GetOrSetFuncLock(key, f), true)
|
||||
return gvar.New(tree.GetOrSetFuncLock(key, f))
|
||||
}
|
||||
|
||||
// SetIfNotExist sets <value> to the map if the <key> does not exist, then return true.
|
||||
|
||||
@ -39,20 +39,20 @@ type RedBlackTreeNode struct {
|
||||
}
|
||||
|
||||
// NewRedBlackTree instantiates a red-black tree with the custom key comparator.
|
||||
// The parameter <unsafe> used to specify whether using tree in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using tree in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewRedBlackTree(comparator func(v1, v2 interface{}) int, unsafe ...bool) *RedBlackTree {
|
||||
func NewRedBlackTree(comparator func(v1, v2 interface{}) int, safe ...bool) *RedBlackTree {
|
||||
return &RedBlackTree{
|
||||
mu: rwmutex.New(unsafe...),
|
||||
mu: rwmutex.New(safe...),
|
||||
comparator: comparator,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRedBlackTreeFrom instantiates a red-black tree with the custom key comparator and <data> map.
|
||||
// The parameter <unsafe> used to specify whether using tree in un-concurrent-safety,
|
||||
// The parameter <safe> used to specify whether using tree in concurrent-safety,
|
||||
// which is false in default.
|
||||
func NewRedBlackTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *RedBlackTree {
|
||||
tree := NewRedBlackTree(comparator, unsafe...)
|
||||
func NewRedBlackTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *RedBlackTree {
|
||||
tree := NewRedBlackTree(comparator, safe...)
|
||||
for k, v := range data {
|
||||
tree.doSet(k, v)
|
||||
}
|
||||
@ -60,7 +60,7 @@ func NewRedBlackTreeFrom(comparator func(v1, v2 interface{}) int, data map[inter
|
||||
}
|
||||
|
||||
// Clone returns a new tree with a copy of current tree.
|
||||
func (tree *RedBlackTree) Clone(unsafe ...bool) *RedBlackTree {
|
||||
func (tree *RedBlackTree) Clone(safe ...bool) *RedBlackTree {
|
||||
newTree := NewRedBlackTree(tree.comparator, !tree.mu.IsSafe())
|
||||
newTree.Sets(tree.Map())
|
||||
return newTree
|
||||
@ -190,25 +190,25 @@ func (tree *RedBlackTree) GetOrSetFuncLock(key interface{}, f func() interface{}
|
||||
// GetVar returns a gvar.Var with the value by given <key>.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *RedBlackTree) GetVar(key interface{}) *gvar.Var {
|
||||
return gvar.New(tree.Get(key), true)
|
||||
return gvar.New(tree.Get(key))
|
||||
}
|
||||
|
||||
// GetVarOrSet returns a gvar.Var with result from GetVarOrSet.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *RedBlackTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var {
|
||||
return gvar.New(tree.GetOrSet(key, value), true)
|
||||
return gvar.New(tree.GetOrSet(key, value))
|
||||
}
|
||||
|
||||
// GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *RedBlackTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(tree.GetOrSetFunc(key, f), true)
|
||||
return gvar.New(tree.GetOrSetFunc(key, f))
|
||||
}
|
||||
|
||||
// GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
func (tree *RedBlackTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var {
|
||||
return gvar.New(tree.GetOrSetFuncLock(key, f), true)
|
||||
return gvar.New(tree.GetOrSetFuncLock(key, f))
|
||||
}
|
||||
|
||||
// SetIfNotExist sets <value> to the map if the <key> does not exist, then return true.
|
||||
|
||||
@ -23,11 +23,11 @@ type Var struct {
|
||||
}
|
||||
|
||||
// New returns a new Var with given <value>.
|
||||
// The parameter <unsafe> used to specify whether using Var in un-concurrent-safety,
|
||||
// which is false in default, means concurrent-safe.
|
||||
func New(value interface{}, unsafe ...bool) *Var {
|
||||
// The parameter <safe> used to specify whether using Var in concurrent-safety,
|
||||
// which is false in default.
|
||||
func New(value interface{}, safe ...bool) *Var {
|
||||
v := &Var{}
|
||||
if len(unsafe) == 0 || !unsafe[0] {
|
||||
if len(safe) > 0 && !safe[0] {
|
||||
v.safe = true
|
||||
v.value = gtype.NewInterface(value)
|
||||
} else {
|
||||
|
||||
@ -162,7 +162,7 @@ const (
|
||||
|
||||
var (
|
||||
// Instance map.
|
||||
instances = gmap.NewStrAnyMap()
|
||||
instances = gmap.NewStrAnyMap(true)
|
||||
)
|
||||
|
||||
// New creates ORM DB object with global configurations.
|
||||
|
||||
@ -611,13 +611,13 @@ func (bs *dbBase) rowsToResult(rows *sql.Rows) (Result, error) {
|
||||
// 多个记录循环时该变量指向的是同一个内存地址
|
||||
for i, column := range values {
|
||||
if column == nil {
|
||||
row[columns[i]] = gvar.New(nil, true)
|
||||
row[columns[i]] = gvar.New(nil)
|
||||
} else {
|
||||
// 由于 sql.RawBytes 是slice类型, 这里必须使用值复制
|
||||
v := make([]byte, len(column))
|
||||
copy(v, column)
|
||||
//fmt.Println(columns[i], types[i], string(v), v, bs.db.convertValue(v, types[i]))
|
||||
row[columns[i]] = gvar.New(bs.db.convertValue(v, types[i]), true)
|
||||
row[columns[i]] = gvar.New(bs.db.convertValue(v, types[i]))
|
||||
}
|
||||
}
|
||||
records = append(records, row)
|
||||
|
||||
@ -145,7 +145,7 @@ func (bs *dbBase) SetDebug(debug bool) {
|
||||
}
|
||||
bs.debug.Set(debug)
|
||||
if debug && bs.sqls == nil {
|
||||
bs.sqls = gring.New(gDEFAULT_DEBUG_SQL_LENGTH)
|
||||
bs.sqls = gring.New(gDEFAULT_DEBUG_SQL_LENGTH, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -57,9 +57,9 @@ type PoolStats struct {
|
||||
|
||||
var (
|
||||
// Instance map
|
||||
instances = gmap.NewStrAnyMap()
|
||||
instances = gmap.NewStrAnyMap(true)
|
||||
// Pool map.
|
||||
pools = gmap.NewStrAnyMap()
|
||||
pools = gmap.NewStrAnyMap(true)
|
||||
)
|
||||
|
||||
// New creates a redis client object with given configuration.
|
||||
@ -177,8 +177,8 @@ func (r *Redis) Stats() *PoolStats {
|
||||
}
|
||||
|
||||
// Do sends a command to the server and returns the received reply.
|
||||
// Do automatically get a connection from pool, and close it when reply received.
|
||||
// It does not really "close" the connection, but drop it back to the connection pool.
|
||||
// Do automatically get a connection from pool, and close it when the reply received.
|
||||
// It does not really "close" the connection, but drops it back to the connection pool.
|
||||
func (r *Redis) Do(command string, args ...interface{}) (interface{}, error) {
|
||||
conn := &Conn{r.pool.Get()}
|
||||
defer conn.Close()
|
||||
@ -188,7 +188,7 @@ func (r *Redis) Do(command string, args ...interface{}) (interface{}, error) {
|
||||
// DoVar returns value from Do as gvar.Var.
|
||||
func (r *Redis) DoVar(command string, args ...interface{}) (*gvar.Var, error) {
|
||||
v, err := r.Do(command, args...)
|
||||
return gvar.New(v, true), err
|
||||
return gvar.New(v), err
|
||||
}
|
||||
|
||||
// Deprecated.
|
||||
|
||||
@ -15,7 +15,7 @@ const (
|
||||
|
||||
var (
|
||||
// Configuration groups.
|
||||
configs = gmap.NewStrAnyMap()
|
||||
configs = gmap.NewStrAnyMap(true)
|
||||
)
|
||||
|
||||
// SetConfig sets the global configuration for specified group.
|
||||
|
||||
@ -11,11 +11,11 @@ import "github.com/gogf/gf/g/container/gvar"
|
||||
// DoVar returns value from Do as gvar.Var.
|
||||
func (c *Conn) DoVar(command string, args ...interface{}) (*gvar.Var, error) {
|
||||
v, err := c.Do(command, args...)
|
||||
return gvar.New(v, true), err
|
||||
return gvar.New(v), err
|
||||
}
|
||||
|
||||
// ReceiveVar receives a single reply as gvar.Var from the Redis server.
|
||||
func (c *Conn) ReceiveVar() (*gvar.Var, error) {
|
||||
v, err := c.Receive()
|
||||
return gvar.New(v, true), err
|
||||
return gvar.New(v), err
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ func (j *Json) Get(pattern string, def ...interface{}) interface{} {
|
||||
|
||||
// GetVar returns a *gvar.Var with value by given <pattern>.
|
||||
func (j *Json) GetVar(pattern string, def ...interface{}) *gvar.Var {
|
||||
return gvar.New(j.Get(pattern, def...), true)
|
||||
return gvar.New(j.Get(pattern, def...))
|
||||
}
|
||||
|
||||
// GetMap gets the value by specified <pattern>,
|
||||
@ -76,7 +76,7 @@ func (j *Json) GetMap(pattern string, def ...interface{}) map[string]interface{}
|
||||
// GetJson gets the value by specified <pattern>,
|
||||
// and converts it to a un-concurrent-safe Json object.
|
||||
func (j *Json) GetJson(pattern string, def ...interface{}) *Json {
|
||||
return New(j.Get(pattern, def...), true)
|
||||
return New(j.Get(pattern, def...))
|
||||
}
|
||||
|
||||
// GetJsons gets the value by specified <pattern>,
|
||||
@ -86,7 +86,7 @@ func (j *Json) GetJsons(pattern string, def ...interface{}) []*Json {
|
||||
if len(array) > 0 {
|
||||
jsonSlice := make([]*Json, len(array))
|
||||
for i := 0; i < len(array); i++ {
|
||||
jsonSlice[i] = New(array[i], true)
|
||||
jsonSlice[i] = New(array[i])
|
||||
}
|
||||
return jsonSlice
|
||||
}
|
||||
@ -100,7 +100,7 @@ func (j *Json) GetJsonMap(pattern string, def ...interface{}) map[string]*Json {
|
||||
if len(m) > 0 {
|
||||
jsonMap := make(map[string]*Json, len(m))
|
||||
for k, v := range m {
|
||||
jsonMap[k] = New(v, true)
|
||||
jsonMap[k] = New(v)
|
||||
}
|
||||
return jsonMap
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ import (
|
||||
// or it will make no sense.
|
||||
// The <unsafe> param specifies whether using this Json object
|
||||
// in un-concurrent-safe context, which is false in default.
|
||||
func New(data interface{}, unsafe ...bool) *Json {
|
||||
func New(data interface{}, safe ...bool) *Json {
|
||||
j := (*Json)(nil)
|
||||
switch data.(type) {
|
||||
case string, []byte:
|
||||
@ -79,18 +79,10 @@ func New(data interface{}, unsafe ...bool) *Json {
|
||||
}
|
||||
}
|
||||
}
|
||||
j.mu = rwmutex.New(unsafe...)
|
||||
j.mu = rwmutex.New(safe...)
|
||||
return j
|
||||
}
|
||||
|
||||
// NewUnsafe creates a un-concurrent-safe Json object.
|
||||
func NewUnsafe(data ...interface{}) *Json {
|
||||
if len(data) > 0 {
|
||||
return New(data[0], true)
|
||||
}
|
||||
return New(nil, true)
|
||||
}
|
||||
|
||||
// Valid checks whether <data> is a valid JSON data type.
|
||||
func Valid(data interface{}) bool {
|
||||
return json.Valid(gconv.Bytes(data))
|
||||
@ -120,41 +112,41 @@ func DecodeTo(data interface{}, v interface{}) error {
|
||||
}
|
||||
|
||||
// DecodeToJson codes <data>(string/[]byte) to a Json object.
|
||||
func DecodeToJson(data interface{}, unsafe ...bool) (*Json, error) {
|
||||
func DecodeToJson(data interface{}, safe ...bool) (*Json, error) {
|
||||
if v, err := Decode(gconv.Bytes(data)); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return New(v, unsafe...), nil
|
||||
return New(v, safe...), nil
|
||||
}
|
||||
}
|
||||
|
||||
// Load loads content from specified file <path>,
|
||||
// and creates a Json object from its content.
|
||||
func Load(path string, unsafe ...bool) (*Json, error) {
|
||||
return doLoadContent(gfile.Ext(path), gfcache.GetBinContents(path), unsafe...)
|
||||
func Load(path string, safe ...bool) (*Json, error) {
|
||||
return doLoadContent(gfile.Ext(path), gfcache.GetBinContents(path), safe...)
|
||||
}
|
||||
|
||||
func LoadJson(data interface{}, unsafe ...bool) (*Json, error) {
|
||||
return doLoadContent("json", gconv.Bytes(data), unsafe...)
|
||||
func LoadJson(data interface{}, safe ...bool) (*Json, error) {
|
||||
return doLoadContent("json", gconv.Bytes(data), safe...)
|
||||
}
|
||||
|
||||
func LoadXml(data interface{}, unsafe ...bool) (*Json, error) {
|
||||
return doLoadContent("xml", gconv.Bytes(data), unsafe...)
|
||||
func LoadXml(data interface{}, safe ...bool) (*Json, error) {
|
||||
return doLoadContent("xml", gconv.Bytes(data), safe...)
|
||||
}
|
||||
|
||||
func LoadYaml(data interface{}, unsafe ...bool) (*Json, error) {
|
||||
return doLoadContent("yaml", gconv.Bytes(data), unsafe...)
|
||||
func LoadYaml(data interface{}, safe ...bool) (*Json, error) {
|
||||
return doLoadContent("yaml", gconv.Bytes(data), safe...)
|
||||
}
|
||||
|
||||
func LoadToml(data interface{}, unsafe ...bool) (*Json, error) {
|
||||
return doLoadContent("toml", gconv.Bytes(data), unsafe...)
|
||||
func LoadToml(data interface{}, safe ...bool) (*Json, error) {
|
||||
return doLoadContent("toml", gconv.Bytes(data), safe...)
|
||||
}
|
||||
|
||||
func doLoadContent(dataType string, data []byte, unsafe ...bool) (*Json, error) {
|
||||
func doLoadContent(dataType string, data []byte, safe ...bool) (*Json, error) {
|
||||
var err error
|
||||
var result interface{}
|
||||
if len(data) == 0 {
|
||||
return New(nil, unsafe...), nil
|
||||
return New(nil, safe...), nil
|
||||
}
|
||||
if dataType == "" {
|
||||
dataType = checkDataType(data)
|
||||
@ -194,15 +186,15 @@ func doLoadContent(dataType string, data []byte, unsafe ...bool) (*Json, error)
|
||||
return nil, fmt.Errorf(`json decoding failed for content: %s`, string(data))
|
||||
}
|
||||
}
|
||||
return New(result, unsafe...), nil
|
||||
return New(result, safe...), nil
|
||||
}
|
||||
|
||||
func LoadContent(data interface{}, unsafe ...bool) (*Json, error) {
|
||||
func LoadContent(data interface{}, safe ...bool) (*Json, error) {
|
||||
content := gconv.Bytes(data)
|
||||
if len(content) == 0 {
|
||||
return New(nil, unsafe...), nil
|
||||
return New(nil, safe...), nil
|
||||
}
|
||||
return doLoadContent(checkDataType(content), content, unsafe...)
|
||||
return doLoadContent(checkDataType(content), content, safe...)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -24,18 +24,6 @@ func Test_New(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_NewUnsafe(t *testing.T) {
|
||||
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
|
||||
gtest.Case(t, func() {
|
||||
j := gjson.NewUnsafe(data)
|
||||
gtest.Assert(j.Get("n"), "123456789")
|
||||
gtest.Assert(j.Get("m"), g.Map{"k": "v"})
|
||||
gtest.Assert(j.Get("m.k"), "v")
|
||||
gtest.Assert(j.Get("a"), g.Slice{1, 2, 3})
|
||||
gtest.Assert(j.Get("a.1"), 2)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Valid(t *testing.T) {
|
||||
data1 := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
|
||||
data2 := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]`)
|
||||
|
||||
@ -175,7 +175,7 @@ func Test_Load_TOML2(t *testing.T) {
|
||||
|
||||
func Test_Load_Basic(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
j := gjson.NewUnsafe()
|
||||
j := gjson.New(nil)
|
||||
gtest.Assert(j.Value(), nil)
|
||||
_, err := gjson.Decode(nil)
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
@ -15,22 +15,14 @@ import (
|
||||
// or it will make no sense.
|
||||
// The <unsafe> param specifies whether using this Parser object
|
||||
// in un-concurrent-safe context, which is false in default.
|
||||
func New(value interface{}, unsafe ...bool) *Parser {
|
||||
return &Parser{gjson.New(value, unsafe...)}
|
||||
}
|
||||
|
||||
// NewUnsafe creates a un-concurrent-safe Parser object.
|
||||
func NewUnsafe(value ...interface{}) *Parser {
|
||||
if len(value) > 0 {
|
||||
return &Parser{gjson.New(value[0], false)}
|
||||
}
|
||||
return &Parser{gjson.New(nil, false)}
|
||||
func New(value interface{}, safe ...bool) *Parser {
|
||||
return &Parser{gjson.New(value, safe...)}
|
||||
}
|
||||
|
||||
// Load loads content from specified file <path>,
|
||||
// and creates a Parser object from its content.
|
||||
func Load(path string, unsafe ...bool) (*Parser, error) {
|
||||
if j, e := gjson.Load(path, unsafe...); e == nil {
|
||||
func Load(path string, safe ...bool) (*Parser, error) {
|
||||
if j, e := gjson.Load(path, safe...); e == nil {
|
||||
return &Parser{j}, nil
|
||||
} else {
|
||||
return nil, e
|
||||
@ -40,8 +32,8 @@ func Load(path string, unsafe ...bool) (*Parser, error) {
|
||||
// LoadContent creates a Parser object from given content,
|
||||
// it checks the data type of <content> automatically,
|
||||
// supporting JSON, XML, YAML and TOML types of data.
|
||||
func LoadContent(data interface{}, unsafe ...bool) (*Parser, error) {
|
||||
if j, e := gjson.LoadContent(data, unsafe...); e == nil {
|
||||
func LoadContent(data interface{}, safe ...bool) (*Parser, error) {
|
||||
if j, e := gjson.LoadContent(data, safe...); e == nil {
|
||||
return &Parser{j}, nil
|
||||
} else {
|
||||
return nil, e
|
||||
|
||||
@ -28,7 +28,7 @@ func Test_New(t *testing.T) {
|
||||
func Test_NewUnsafe(t *testing.T) {
|
||||
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
|
||||
gtest.Case(t, func() {
|
||||
j := gparser.NewUnsafe(data)
|
||||
j := gparser.New(data)
|
||||
gtest.Assert(j.Get("n"), "123456789")
|
||||
gtest.Assert(j.Get("m"), g.Map{"k": "v"})
|
||||
gtest.Assert(j.Get("m.k"), "v")
|
||||
|
||||
@ -176,7 +176,7 @@ func Test_Load_TOML2(t *testing.T) {
|
||||
|
||||
func Test_Load_Nil(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
p := gparser.NewUnsafe()
|
||||
p := gparser.New(nil)
|
||||
gtest.Assert(p.Value(), nil)
|
||||
file := "test22222.json"
|
||||
filePath := gfile.Pwd() + gfile.Separator + file
|
||||
|
||||
@ -29,7 +29,7 @@ const (
|
||||
)
|
||||
|
||||
// 单例对象存储器
|
||||
var instances = gmap.NewStrAnyMap()
|
||||
var instances = gmap.NewStrAnyMap(true)
|
||||
|
||||
// 获取单例对象
|
||||
func Get(key string) interface{} {
|
||||
|
||||
@ -14,8 +14,8 @@ import (
|
||||
)
|
||||
|
||||
// NewVar returns a *gvar.Var.
|
||||
func NewVar(i interface{}, unsafe ...bool) *Var {
|
||||
return gvar.New(i, unsafe...)
|
||||
func NewVar(i interface{}, safe ...bool) *Var {
|
||||
return gvar.New(i, safe...)
|
||||
}
|
||||
|
||||
// Wait blocks until all the web servers shutdown.
|
||||
|
||||
@ -54,5 +54,5 @@ func Get(key string, def ...interface{}) *gvar.Var {
|
||||
value = v
|
||||
}
|
||||
}
|
||||
return gvar.New(value, true)
|
||||
return gvar.New(value)
|
||||
}
|
||||
|
||||
@ -15,12 +15,15 @@ type Mutex struct {
|
||||
safe bool
|
||||
}
|
||||
|
||||
func New(unsafe ...bool) *Mutex {
|
||||
// New creates and returns a new *Mutex.
|
||||
// The parameter <safe> is used to specify whether using this mutex in concurrent-safety,
|
||||
// which is false in default.
|
||||
func New(safe ...bool) *Mutex {
|
||||
mu := new(Mutex)
|
||||
if len(unsafe) > 0 {
|
||||
mu.safe = !unsafe[0]
|
||||
if len(safe) > 0 {
|
||||
mu.safe = safe[0]
|
||||
} else {
|
||||
mu.safe = true
|
||||
mu.safe = false
|
||||
}
|
||||
return mu
|
||||
}
|
||||
@ -29,14 +32,14 @@ func (mu *Mutex) IsSafe() bool {
|
||||
return mu.safe
|
||||
}
|
||||
|
||||
func (mu *Mutex) Lock(force ...bool) {
|
||||
if mu.safe || (len(force) > 0 && force[0]) {
|
||||
func (mu *Mutex) Lock() {
|
||||
if mu.safe {
|
||||
mu.Mutex.Lock()
|
||||
}
|
||||
}
|
||||
|
||||
func (mu *Mutex) Unlock(force ...bool) {
|
||||
if mu.safe || (len(force) > 0 && force[0]) {
|
||||
func (mu *Mutex) Unlock() {
|
||||
if mu.safe {
|
||||
mu.Mutex.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ func TestMutexIsSafe(t *testing.T) {
|
||||
func TestSafeMutex(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
safeLock := mutex.New(false)
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
|
||||
go func() {
|
||||
safeLock.Lock()
|
||||
@ -70,7 +70,7 @@ func TestSafeMutex(t *testing.T) {
|
||||
func TestUnsafeMutex(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
unsafeLock := mutex.New(true)
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
|
||||
go func() {
|
||||
unsafeLock.Lock()
|
||||
|
||||
@ -15,12 +15,15 @@ type RWMutex struct {
|
||||
safe bool
|
||||
}
|
||||
|
||||
func New(unsafe ...bool) *RWMutex {
|
||||
// New creates and returns a new *RWMutex.
|
||||
// The parameter <safe> is used to specify whether using this mutex in concurrent-safety,
|
||||
// which is false in default.
|
||||
func New(safe ...bool) *RWMutex {
|
||||
mu := new(RWMutex)
|
||||
if len(unsafe) > 0 {
|
||||
mu.safe = !unsafe[0]
|
||||
if len(safe) > 0 {
|
||||
mu.safe = safe[0]
|
||||
} else {
|
||||
mu.safe = true
|
||||
mu.safe = false
|
||||
}
|
||||
return mu
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ func TestRwmutexIsSafe(t *testing.T) {
|
||||
func TestSafeRwmutex(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
safeLock := rwmutex.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
|
||||
go func() {
|
||||
safeLock.Lock()
|
||||
@ -70,7 +70,7 @@ func TestSafeRwmutex(t *testing.T) {
|
||||
func TestSafeReaderRwmutex(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
safeLock := rwmutex.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
|
||||
go func() {
|
||||
safeLock.RLock()
|
||||
@ -109,7 +109,7 @@ func TestSafeReaderRwmutex(t *testing.T) {
|
||||
func TestUnsafeRwmutex(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
unsafeLock := rwmutex.New(true)
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
|
||||
go func() {
|
||||
unsafeLock.Lock()
|
||||
|
||||
@ -20,11 +20,11 @@ func (r *Request) SetParam(key string, value interface{}) {
|
||||
func (r *Request) GetParam(key string, def ...interface{}) *gvar.Var {
|
||||
if r.params != nil {
|
||||
if v, ok := r.params[key]; ok {
|
||||
return gvar.New(v, true)
|
||||
return gvar.New(v)
|
||||
}
|
||||
}
|
||||
if len(def) > 0 {
|
||||
return gvar.New(def[0], true)
|
||||
return gvar.New(def[0])
|
||||
}
|
||||
return gvar.New(nil, true)
|
||||
return gvar.New(nil)
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ func (r *Request) GetPost(key string, def ...interface{}) []string {
|
||||
}
|
||||
|
||||
func (r *Request) GetPostVar(key string, def ...interface{}) *gvar.Var {
|
||||
return gvar.New(r.GetPostString(key, def...), true)
|
||||
return gvar.New(r.GetPostString(key, def...))
|
||||
}
|
||||
|
||||
func (r *Request) GetPostString(key string, def ...interface{}) string {
|
||||
|
||||
@ -57,7 +57,7 @@ func (r *Request) GetQuery(key string, def ...interface{}) []string {
|
||||
}
|
||||
|
||||
func (r *Request) GetQueryVar(key string, def ...interface{}) *gvar.Var {
|
||||
return gvar.New(r.GetQueryString(key, def...), true)
|
||||
return gvar.New(r.GetQueryString(key, def...))
|
||||
}
|
||||
|
||||
func (r *Request) GetQueryString(key string, def ...interface{}) string {
|
||||
|
||||
@ -30,9 +30,9 @@ func (r *Request) GetRequest(key string, def ...interface{}) []string {
|
||||
func (r *Request) GetRequestVar(key string, def ...interface{}) *gvar.Var {
|
||||
value := r.GetRequest(key, def...)
|
||||
if value != nil {
|
||||
return gvar.New(value[0], true)
|
||||
return gvar.New(value[0])
|
||||
}
|
||||
return gvar.New(nil, true)
|
||||
return gvar.New(nil)
|
||||
}
|
||||
|
||||
func (r *Request) GetRequestString(key string, def ...interface{}) string {
|
||||
|
||||
@ -125,7 +125,7 @@ var (
|
||||
methodsMap = make(map[string]struct{})
|
||||
|
||||
// WebServer表,用以存储和检索名称与Server对象之间的关联关系
|
||||
serverMapping = gmap.NewStrAnyMap()
|
||||
serverMapping = gmap.NewStrAnyMap(true)
|
||||
|
||||
// 正常运行的WebServer数量,如果没有运行、失败或者全部退出,那么该值为0
|
||||
serverRunning = gtype.NewInt()
|
||||
@ -342,7 +342,7 @@ func (s *Server) GetRouteMap() string {
|
||||
}
|
||||
}
|
||||
return r
|
||||
}, false)
|
||||
})
|
||||
}
|
||||
m[item.domain].Add(item)
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ func (s *Server) AddStaticPath(prefix string, path string) {
|
||||
r = strings.Compare(s1, s2)
|
||||
}
|
||||
return r
|
||||
}, false)
|
||||
})
|
||||
for _, v := range s.config.StaticPaths {
|
||||
array.Add(v.prefix)
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ func (s *Server) searchHookHandler(method, path, domain, hook string) []*handler
|
||||
}
|
||||
|
||||
// 多层链表遍历检索,从数组末尾的链表开始遍历,末尾的深度高优先级也高
|
||||
pushedSet := gset.NewStringSet(true)
|
||||
pushedSet := gset.NewStringSet()
|
||||
for i := len(lists) - 1; i >= 0; i-- {
|
||||
for e := lists[i].Front(); e != nil; e = e.Next() {
|
||||
handler := e.Value.(*handlerItem)
|
||||
|
||||
@ -57,7 +57,7 @@ func (s *Session) init() {
|
||||
}
|
||||
// 否则执行初始化创建
|
||||
s.id = s.request.Cookie.MakeSessionId()
|
||||
s.data = gmap.NewStrAnyMap()
|
||||
s.data = gmap.NewStrAnyMap(true)
|
||||
s.server.sessions.Set(s.id, s.data, s.server.GetSessionMaxAge()*1000)
|
||||
}
|
||||
}
|
||||
@ -114,7 +114,7 @@ func (s *Session) Get(key string, def ...interface{}) interface{} {
|
||||
|
||||
// 获取SESSION,建议都用该方法获取参数
|
||||
func (s *Session) GetVar(key string, def ...interface{}) *gvar.Var {
|
||||
return gvar.New(s.Get(key, def...), true)
|
||||
return gvar.New(s.Get(key, def...))
|
||||
}
|
||||
|
||||
// 删除session
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
|
||||
var (
|
||||
// 用于测试的端口数组,随机获取
|
||||
ports = garray.NewIntArray()
|
||||
ports = garray.NewIntArray(true)
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@ -31,7 +31,7 @@ const (
|
||||
|
||||
var (
|
||||
// 连接池对象map,键名为地址端口,键值为对应的连接池对象
|
||||
pools = gmap.NewStrAnyMap()
|
||||
pools = gmap.NewStrAnyMap(true)
|
||||
)
|
||||
|
||||
// 创建TCP链接池对象
|
||||
|
||||
@ -28,7 +28,7 @@ type Server struct {
|
||||
}
|
||||
|
||||
// Map for name to server, for singleton purpose.
|
||||
var serverMapping = gmap.NewStrAnyMap()
|
||||
var serverMapping = gmap.NewStrAnyMap(true)
|
||||
|
||||
// GetServer returns the TCP server with specified <name>,
|
||||
// or it returns a new normal TCP server named <name> if it does not exist.
|
||||
|
||||
@ -26,7 +26,7 @@ type Server struct {
|
||||
}
|
||||
|
||||
// Server表,用以存储和检索名称与Server对象之间的关联关系
|
||||
var serverMapping = gmap.NewStrAnyMap()
|
||||
var serverMapping = gmap.NewStrAnyMap(true)
|
||||
|
||||
// 获取/创建一个空配置的UDP Server
|
||||
// 单例模式,请保证name的唯一性
|
||||
|
||||
@ -61,11 +61,11 @@ const (
|
||||
// newMemCache creates and returns a new memory cache object.
|
||||
func newMemCache(lruCap ...int) *memCache {
|
||||
c := &memCache{
|
||||
lruGetList: glist.New(),
|
||||
lruGetList: glist.New(true),
|
||||
data: make(map[interface{}]memCacheItem),
|
||||
expireTimes: make(map[interface{}]int64),
|
||||
expireSets: make(map[int64]*gset.Set),
|
||||
eventList: glist.New(),
|
||||
eventList: glist.New(true),
|
||||
closed: gtype.NewBool(),
|
||||
}
|
||||
if len(lruCap) > 0 {
|
||||
@ -92,7 +92,7 @@ func (c *memCache) getExpireSet(expire int64) (expireSet *gset.Set) {
|
||||
// It creates and returns a new set for <expire> if it does not exist.
|
||||
func (c *memCache) getOrNewExpireSet(expire int64) (expireSet *gset.Set) {
|
||||
if expireSet = c.getExpireSet(expire); expireSet == nil {
|
||||
expireSet = gset.New()
|
||||
expireSet = gset.New(true)
|
||||
c.expireSetMu.Lock()
|
||||
if es, ok := c.expireSets[expire]; ok {
|
||||
expireSet = es
|
||||
|
||||
@ -28,9 +28,9 @@ type memCacheLru struct {
|
||||
func newMemCacheLru(cache *memCache) *memCacheLru {
|
||||
lru := &memCacheLru{
|
||||
cache: cache,
|
||||
data: gmap.New(),
|
||||
list: glist.New(),
|
||||
rawList: glist.New(),
|
||||
data: gmap.New(true),
|
||||
list: glist.New(true),
|
||||
rawList: glist.New(true),
|
||||
closed: gtype.NewBool(),
|
||||
}
|
||||
gtimer.AddSingleton(time.Second, lru.SyncAndClear)
|
||||
|
||||
@ -48,8 +48,8 @@ func New(file ...string) *Config {
|
||||
}
|
||||
c := &Config{
|
||||
name: gtype.NewString(name),
|
||||
paths: garray.NewStringArray(),
|
||||
jsons: gmap.NewStrAnyMap(),
|
||||
paths: garray.NewStringArray(true),
|
||||
jsons: gmap.NewStrAnyMap(true),
|
||||
vc: gtype.NewBool(),
|
||||
}
|
||||
// Customized dir path from env/cmd.
|
||||
@ -276,7 +276,7 @@ func (c *Config) getJson(file ...string) *gjson.Json {
|
||||
}
|
||||
content = gfile.GetContents(filePath)
|
||||
}
|
||||
if j, err := gjson.LoadContent(content); err == nil {
|
||||
if j, err := gjson.LoadContent(content, true); err == nil {
|
||||
j.SetViolenceCheck(c.vc.Val())
|
||||
// Add monitor for this configuration file,
|
||||
// any changes of this file will refresh its cache in Config object.
|
||||
@ -315,9 +315,9 @@ func (c *Config) Get(pattern string, def ...interface{}) interface{} {
|
||||
|
||||
func (c *Config) GetVar(pattern string, def ...interface{}) *gvar.Var {
|
||||
if j := c.getJson(); j != nil {
|
||||
return gvar.New(j.Get(pattern, def...), true)
|
||||
return gvar.New(j.Get(pattern, def...))
|
||||
}
|
||||
return gvar.New(nil, true)
|
||||
return gvar.New(nil)
|
||||
}
|
||||
|
||||
func (c *Config) Contains(pattern string) bool {
|
||||
|
||||
@ -10,7 +10,7 @@ import "github.com/gogf/gf/g/container/gmap"
|
||||
|
||||
var (
|
||||
// Customized configuration content.
|
||||
configs = gmap.NewStrStrMap()
|
||||
configs = gmap.NewStrStrMap(true)
|
||||
)
|
||||
|
||||
// SetContent sets customized configuration content for specified <file>.
|
||||
|
||||
@ -17,7 +17,7 @@ const (
|
||||
|
||||
var (
|
||||
// Instances map.
|
||||
instances = gmap.NewStrAnyMap()
|
||||
instances = gmap.NewStrAnyMap(true)
|
||||
)
|
||||
|
||||
// Instance returns an instance of Config with default settings.
|
||||
|
||||
@ -28,5 +28,5 @@ func (c *gCmdOption) Get(key string, def ...string) string {
|
||||
// GetVar returns the option value as *gvar.Var object specified by <key>,
|
||||
// if value does not exist, then returns <def> as its default value.
|
||||
func (c *gCmdOption) GetVar(key string, def ...string) *gvar.Var {
|
||||
return gvar.New(c.Get(key, def...), true)
|
||||
return gvar.New(c.Get(key, def...))
|
||||
}
|
||||
|
||||
@ -28,5 +28,5 @@ func (c *gCmdValue) Get(index int, def ...string) string {
|
||||
// GetVar returns value by index <index> as *gvar.Var object,
|
||||
// if value does not exist, then returns <def> as its default value.
|
||||
func (c *gCmdValue) GetVar(index int, def ...string) *gvar.Var {
|
||||
return gvar.New(c.Get(index, def...), true)
|
||||
return gvar.New(c.Get(index, def...))
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ func New() *Cron {
|
||||
return &Cron{
|
||||
idGen: gtype.NewInt64(),
|
||||
status: gtype.NewInt(STATUS_RUNNING),
|
||||
entries: gmap.NewStrAnyMap(),
|
||||
entries: gmap.NewStrAnyMap(true),
|
||||
logPath: gtype.NewString(),
|
||||
logLevel: gtype.NewInt(glog.LEVEL_PROD),
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ import (
|
||||
func TestCron_Add_Close(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
_, err1 := cron.Add("* * * * * *", func() {
|
||||
//glog.Println("cron1")
|
||||
array.Append(1)
|
||||
@ -74,7 +74,7 @@ func TestCron_Basic(t *testing.T) {
|
||||
func TestCron_Remove(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
cron.Add("* * * * * *", func() {
|
||||
array.Append(1)
|
||||
}, "add")
|
||||
@ -110,7 +110,7 @@ func TestCron_AddSingleton(t *testing.T) {
|
||||
// keep this
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
cron.AddSingleton("* * * * * *", func() {
|
||||
array.Append(1)
|
||||
time.Sleep(50 * time.Second)
|
||||
@ -125,7 +125,7 @@ func TestCron_AddSingleton(t *testing.T) {
|
||||
func TestCron_AddOnce1(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
cron.AddOnce("* * * * * *", func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -142,7 +142,7 @@ func TestCron_AddOnce1(t *testing.T) {
|
||||
func TestCron_AddOnce2(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
cron.AddOnce("@every 2s", func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -156,7 +156,7 @@ func TestCron_AddOnce2(t *testing.T) {
|
||||
func TestCron_AddTimes(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
cron.AddTimes("* * * * * *", 2, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -169,7 +169,7 @@ func TestCron_AddTimes(t *testing.T) {
|
||||
func TestCron_DelayAdd(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
cron.DelayAdd(500*time.Millisecond, "* * * * * *", func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -186,7 +186,7 @@ func TestCron_DelayAdd(t *testing.T) {
|
||||
func TestCron_DelayAddSingleton(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
cron.DelayAddSingleton(500*time.Millisecond, "* * * * * *", func() {
|
||||
array.Append(1)
|
||||
time.Sleep(10 * time.Second)
|
||||
@ -201,7 +201,7 @@ func TestCron_DelayAddSingleton(t *testing.T) {
|
||||
func TestCron_DelayAddOnce(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
cron.DelayAddOnce(500*time.Millisecond, "* * * * * *", func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -218,7 +218,7 @@ func TestCron_DelayAddOnce(t *testing.T) {
|
||||
func TestCron_DelayAddTimes(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
cron.DelayAddTimes(500*time.Millisecond, "* * * * * *", 2, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
|
||||
@ -20,7 +20,7 @@ func TestCron_Entry_Operations(t *testing.T) {
|
||||
|
||||
gtest.Case(t, func() {
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
cron.DelayAddTimes(500*time.Millisecond, "* * * * * *", 2, func() {
|
||||
glog.Println("add times")
|
||||
array.Append(1)
|
||||
@ -35,7 +35,7 @@ func TestCron_Entry_Operations(t *testing.T) {
|
||||
})
|
||||
|
||||
cron := gcron.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
entry, err1 := cron.Add("* * * * * *", func() {
|
||||
glog.Println("add")
|
||||
array.Append(1)
|
||||
|
||||
@ -24,7 +24,7 @@ func Search(name string, prioritySearchPaths ...string) (realPath string, err er
|
||||
}
|
||||
// TODO move search paths to internal package variable.
|
||||
// Search paths array.
|
||||
array := garray.NewStringArray(true)
|
||||
array := garray.NewStringArray()
|
||||
array.Append(prioritySearchPaths...)
|
||||
array.Append(Pwd(), SelfDir())
|
||||
if path := MainPkgPath(); path != "" {
|
||||
|
||||
@ -43,7 +43,7 @@ func Test_GFlock_Base(t *testing.T) {
|
||||
func Test_GFlock_Lock(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
fileName := "testLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
lock := gflock.New(fileName)
|
||||
lock2 := gflock.New(fileName)
|
||||
|
||||
@ -73,7 +73,7 @@ func Test_GFlock_Lock(t *testing.T) {
|
||||
func Test_GFlock_RLock(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
fileName := "testRLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
lock := gflock.New(fileName)
|
||||
lock2 := gflock.New(fileName)
|
||||
|
||||
@ -101,7 +101,7 @@ func Test_GFlock_RLock(t *testing.T) {
|
||||
func Test_GFlock_TryLock(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
fileName := "testTryLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
lock := gflock.New(fileName)
|
||||
lock2 := gflock.New(fileName)
|
||||
|
||||
@ -139,7 +139,7 @@ func Test_GFlock_TryLock(t *testing.T) {
|
||||
func Test_GFlock_TryRLock(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
fileName := "testTryRLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
lock := gflock.New(fileName)
|
||||
lock2 := gflock.New(fileName)
|
||||
go func() {
|
||||
|
||||
@ -38,7 +38,7 @@ type File struct {
|
||||
|
||||
var (
|
||||
// 全局文件指针池Map, 不过期
|
||||
pools = gmap.NewStrAnyMap()
|
||||
pools = gmap.NewStrAnyMap(true)
|
||||
)
|
||||
|
||||
// 获得文件对象,并自动创建指针池(过期时间单位:毫秒)
|
||||
|
||||
@ -70,7 +70,7 @@ var (
|
||||
// 默认的watchers是否初始化,使用时才创建
|
||||
watcherInited = gtype.NewBool()
|
||||
// 回调方法ID与对象指针的映射哈希表,用于根据ID快速查找回调对象
|
||||
callbackIdMap = gmap.NewIntAnyMap()
|
||||
callbackIdMap = gmap.NewIntAnyMap(true)
|
||||
// 回调函数的ID生成器(原子操作)
|
||||
callbackIdGenerator = gtype.NewInt()
|
||||
)
|
||||
@ -81,7 +81,7 @@ func New() (*Watcher, error) {
|
||||
cache: gcache.New(),
|
||||
events: gqueue.New(),
|
||||
closeChan: make(chan struct{}),
|
||||
callbacks: gmap.NewStrAnyMap(),
|
||||
callbacks: gmap.NewStrAnyMap(true),
|
||||
}
|
||||
if watcher, err := fsnotify.NewWatcher(); err == nil {
|
||||
w.watcher = watcher
|
||||
|
||||
@ -56,7 +56,7 @@ func (w *Watcher) addWithCallbackFunc(path string, callbackFunc func(event *Even
|
||||
w.callbacks.LockFunc(func(m map[string]interface{}) {
|
||||
list := (*glist.List)(nil)
|
||||
if v, ok := m[path]; !ok {
|
||||
list = glist.New()
|
||||
list = glist.New(true)
|
||||
m[path] = list
|
||||
} else {
|
||||
list = v.(*glist.List)
|
||||
|
||||
@ -22,7 +22,7 @@ type Locker struct {
|
||||
// A memory locker can lock/unlock with dynamic string key.
|
||||
func New() *Locker {
|
||||
return &Locker{
|
||||
m: gmap.NewStrAnyMap(),
|
||||
m: gmap.NewStrAnyMap(true),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ import (
|
||||
func Test_Locker_Lock(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
key := "testLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.Lock(key)
|
||||
array.Append(1)
|
||||
@ -42,7 +42,7 @@ func Test_Locker_Lock(t *testing.T) {
|
||||
|
||||
gtest.Case(t, func() {
|
||||
key := "testLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
lock := gmlock.New()
|
||||
go func() {
|
||||
lock.Lock(key)
|
||||
@ -70,7 +70,7 @@ func Test_Locker_Lock(t *testing.T) {
|
||||
func Test_Locker_TryLock(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
key := "testTryLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.Lock(key)
|
||||
array.Append(1)
|
||||
@ -105,7 +105,7 @@ func Test_Locker_LockFunc(t *testing.T) {
|
||||
//no expire
|
||||
gtest.Case(t, func() {
|
||||
key := "testLockFunc"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.LockFunc(key, func() {
|
||||
array.Append(1)
|
||||
@ -130,7 +130,7 @@ func Test_Locker_TryLockFunc(t *testing.T) {
|
||||
//no expire
|
||||
gtest.Case(t, func() {
|
||||
key := "testTryLockFunc"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.TryLockFunc(key, func() {
|
||||
array.Append(1)
|
||||
|
||||
@ -19,7 +19,7 @@ func Test_Locker_RLock(t *testing.T) {
|
||||
//RLock before Lock
|
||||
gtest.Case(t, func() {
|
||||
key := "testRLockBeforeLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.RLock(key)
|
||||
array.Append(1)
|
||||
@ -41,7 +41,7 @@ func Test_Locker_RLock(t *testing.T) {
|
||||
//Lock before RLock
|
||||
gtest.Case(t, func() {
|
||||
key := "testLockBeforeRLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.Lock(key)
|
||||
array.Append(1)
|
||||
@ -63,7 +63,7 @@ func Test_Locker_RLock(t *testing.T) {
|
||||
//Lock before RLocks
|
||||
gtest.Case(t, func() {
|
||||
key := "testLockBeforeRLocks"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.Lock(key)
|
||||
array.Append(1)
|
||||
@ -95,7 +95,7 @@ func Test_Locker_TryRLock(t *testing.T) {
|
||||
//Lock before TryRLock
|
||||
gtest.Case(t, func() {
|
||||
key := "testLockBeforeTryRLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.Lock(key)
|
||||
array.Append(1)
|
||||
@ -118,7 +118,7 @@ func Test_Locker_TryRLock(t *testing.T) {
|
||||
//Lock before TryRLocks
|
||||
gtest.Case(t, func() {
|
||||
key := "testLockBeforeTryRLocks"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.Lock(key)
|
||||
array.Append(1)
|
||||
@ -150,7 +150,7 @@ func Test_Locker_RLockFunc(t *testing.T) {
|
||||
//RLockFunc before Lock
|
||||
gtest.Case(t, func() {
|
||||
key := "testRLockFuncBeforeLock"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.RLockFunc(key, func() {
|
||||
array.Append(1)
|
||||
@ -172,7 +172,7 @@ func Test_Locker_RLockFunc(t *testing.T) {
|
||||
//Lock before RLockFunc
|
||||
gtest.Case(t, func() {
|
||||
key := "testLockBeforeRLockFunc"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.Lock(key)
|
||||
array.Append(1)
|
||||
@ -194,7 +194,7 @@ func Test_Locker_RLockFunc(t *testing.T) {
|
||||
//Lock before RLockFuncs
|
||||
gtest.Case(t, func() {
|
||||
key := "testLockBeforeRLockFuncs"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.Lock(key)
|
||||
array.Append(1)
|
||||
@ -226,7 +226,7 @@ func Test_Locker_TryRLockFunc(t *testing.T) {
|
||||
//Lock before TryRLockFunc
|
||||
gtest.Case(t, func() {
|
||||
key := "testLockBeforeTryRLockFunc"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.Lock(key)
|
||||
array.Append(1)
|
||||
@ -248,7 +248,7 @@ func Test_Locker_TryRLockFunc(t *testing.T) {
|
||||
//Lock before TryRLockFuncs
|
||||
gtest.Case(t, func() {
|
||||
key := "testLockBeforeTryRLockFuncs"
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
gmlock.Lock(key)
|
||||
array.Append(1)
|
||||
|
||||
@ -91,7 +91,7 @@ func Test_Mutex_IsLocked(t *testing.T) {
|
||||
func Test_Mutex_Unlock(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
mu := gmutex.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
mu.LockFunc(func() {
|
||||
array.Append(1)
|
||||
@ -129,7 +129,7 @@ func Test_Mutex_Unlock(t *testing.T) {
|
||||
func Test_Mutex_LockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
mu := gmutex.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
mu.LockFunc(func() {
|
||||
array.Append(1)
|
||||
@ -154,7 +154,7 @@ func Test_Mutex_LockFunc(t *testing.T) {
|
||||
func Test_Mutex_TryLockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
mu := gmutex.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
mu.LockFunc(func() {
|
||||
array.Append(1)
|
||||
@ -185,7 +185,7 @@ func Test_Mutex_TryLockFunc(t *testing.T) {
|
||||
func Test_Mutex_RLockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
mu := gmutex.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
mu.LockFunc(func() {
|
||||
array.Append(1)
|
||||
@ -209,7 +209,7 @@ func Test_Mutex_RLockFunc(t *testing.T) {
|
||||
|
||||
gtest.Case(t, func() {
|
||||
mu := gmutex.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
mu.RLockFunc(func() {
|
||||
@ -240,7 +240,7 @@ func Test_Mutex_RLockFunc(t *testing.T) {
|
||||
func Test_Mutex_TryRLockFunc(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
mu := gmutex.New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
go func() {
|
||||
mu.LockFunc(func() {
|
||||
array.Append(1)
|
||||
|
||||
@ -23,10 +23,10 @@ type Msg struct {
|
||||
}
|
||||
|
||||
// 本地进程通信接收消息队列(按照分组进行构建的map,键值为*gqueue.Queue对象)
|
||||
var commReceiveQueues = gmap.NewStrAnyMap()
|
||||
var commReceiveQueues = gmap.NewStrAnyMap(true)
|
||||
|
||||
// (用于发送)已建立的PID对应的Conn通信对象,键值为一个Pool,防止并行使用同一个通信对象造成数据重叠
|
||||
var commPidConnMap = gmap.NewIntAnyMap()
|
||||
var commPidConnMap = gmap.NewIntAnyMap(true)
|
||||
|
||||
// 获取指定进程的通信文件地址
|
||||
func getCommFilePath(pid int) string {
|
||||
|
||||
@ -20,7 +20,7 @@ type Manager struct {
|
||||
// 创建一个进程管理器
|
||||
func NewManager() *Manager {
|
||||
return &Manager{
|
||||
processes: gmap.NewIntAnyMap(),
|
||||
processes: gmap.NewIntAnyMap(true),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ func New(limit ...int) *Pool {
|
||||
p := &Pool{
|
||||
limit: -1,
|
||||
count: gtype.NewInt(),
|
||||
list: glist.New(),
|
||||
list: glist.New(true),
|
||||
closed: gtype.NewBool(),
|
||||
}
|
||||
if len(limit) > 0 && limit[0] > 0 {
|
||||
|
||||
@ -37,17 +37,17 @@ type SPathCacheItem struct {
|
||||
|
||||
var (
|
||||
// 单个目录路径对应的SPath对象指针,用于路径检索对象复用
|
||||
pathsMap = gmap.NewStrAnyMap()
|
||||
pathsCacheMap = gmap.NewStrAnyMap()
|
||||
pathsMap = gmap.NewStrAnyMap(true)
|
||||
pathsCacheMap = gmap.NewStrAnyMap(true)
|
||||
)
|
||||
|
||||
// 创建一个搜索对象
|
||||
func New(path string, cache bool) *SPath {
|
||||
sp := &SPath{
|
||||
paths: garray.NewStringArray(),
|
||||
paths: garray.NewStringArray(true),
|
||||
}
|
||||
if cache {
|
||||
sp.cache = gmap.NewStrStrMap()
|
||||
sp.cache = gmap.NewStrStrMap(true)
|
||||
}
|
||||
if len(path) > 0 {
|
||||
if _, err := sp.Add(path); err != nil {
|
||||
|
||||
@ -73,7 +73,7 @@ func (t *Timer) newWheel(level int, slot int, interval time.Duration) *wheel {
|
||||
intervalMs: interval.Nanoseconds() / 1e6,
|
||||
}
|
||||
for i := int64(0); i < w.number; i++ {
|
||||
w.slots[i] = glist.New()
|
||||
w.slots[i] = glist.New(true)
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ import (
|
||||
|
||||
func TestSetTimeout(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
gtimer.SetTimeout(200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -29,7 +29,7 @@ func TestSetTimeout(t *testing.T) {
|
||||
|
||||
func TestSetInterval(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
gtimer.SetInterval(200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -40,7 +40,7 @@ func TestSetInterval(t *testing.T) {
|
||||
|
||||
func TestAddEntry(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
gtimer.AddEntry(200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
}, false, 2, gtimer.STATUS_READY)
|
||||
@ -51,7 +51,7 @@ func TestAddEntry(t *testing.T) {
|
||||
|
||||
func TestAddSingleton(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
gtimer.AddSingleton(200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
time.Sleep(10000 * time.Millisecond)
|
||||
@ -63,7 +63,7 @@ func TestAddSingleton(t *testing.T) {
|
||||
|
||||
func TestAddTimes(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
gtimer.AddTimes(200*time.Millisecond, 2, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -74,7 +74,7 @@ func TestAddTimes(t *testing.T) {
|
||||
|
||||
func TestDelayAdd(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
gtimer.DelayAdd(200*time.Millisecond, 200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -87,7 +87,7 @@ func TestDelayAdd(t *testing.T) {
|
||||
|
||||
func TestDelayAddEntry(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
gtimer.DelayAddEntry(200*time.Millisecond, 200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
}, false, 2, gtimer.STATUS_READY)
|
||||
@ -100,7 +100,7 @@ func TestDelayAddEntry(t *testing.T) {
|
||||
|
||||
func TestDelayAddSingleton(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
gtimer.DelayAddSingleton(200*time.Millisecond, 200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
time.Sleep(10000 * time.Millisecond)
|
||||
@ -114,7 +114,7 @@ func TestDelayAddSingleton(t *testing.T) {
|
||||
|
||||
func TestDelayAddOnce(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
gtimer.DelayAddOnce(200*time.Millisecond, 200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -127,7 +127,7 @@ func TestDelayAddOnce(t *testing.T) {
|
||||
|
||||
func TestDelayAddTimes(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
gtimer.DelayAddTimes(200*time.Millisecond, 200*time.Millisecond, 2, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
|
||||
@ -23,7 +23,7 @@ func New() *gtimer.Timer {
|
||||
func TestTimer_Add_Close(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
//fmt.Println("start", time.Now())
|
||||
timer.Add(200*time.Millisecond, func() {
|
||||
//fmt.Println("entry1", time.Now())
|
||||
@ -52,7 +52,7 @@ func TestTimer_Add_Close(t *testing.T) {
|
||||
func TestTimer_Start_Stop_Close(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.Add(200*time.Millisecond, func() {
|
||||
//glog.Println("add...")
|
||||
array.Append(1)
|
||||
@ -75,7 +75,7 @@ func TestTimer_Start_Stop_Close(t *testing.T) {
|
||||
func TestTimer_AddSingleton(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.AddSingleton(200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
time.Sleep(10 * time.Second)
|
||||
@ -91,7 +91,7 @@ func TestTimer_AddSingleton(t *testing.T) {
|
||||
func TestTimer_AddOnce(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.AddOnce(200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -113,7 +113,7 @@ func TestTimer_AddOnce(t *testing.T) {
|
||||
func TestTimer_AddTimes(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.AddTimes(200*time.Millisecond, 2, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -125,7 +125,7 @@ func TestTimer_AddTimes(t *testing.T) {
|
||||
func TestTimer_DelayAdd(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.DelayAdd(200*time.Millisecond, 200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -139,7 +139,7 @@ func TestTimer_DelayAdd(t *testing.T) {
|
||||
func TestTimer_DelayAddEntry(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.DelayAddEntry(200*time.Millisecond, 200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
}, false, 100, gtimer.STATUS_READY)
|
||||
@ -153,7 +153,7 @@ func TestTimer_DelayAddEntry(t *testing.T) {
|
||||
func TestTimer_DelayAddSingleton(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.DelayAddSingleton(200*time.Millisecond, 200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
time.Sleep(10 * time.Second)
|
||||
@ -169,7 +169,7 @@ func TestTimer_DelayAddSingleton(t *testing.T) {
|
||||
func TestTimer_DelayAddOnce(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.DelayAddOnce(200*time.Millisecond, 200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -187,7 +187,7 @@ func TestTimer_DelayAddOnce(t *testing.T) {
|
||||
func TestTimer_DelayAddTimes(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.DelayAddTimes(200*time.Millisecond, 500*time.Millisecond, 2, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -208,7 +208,7 @@ func TestTimer_DelayAddTimes(t *testing.T) {
|
||||
func TestTimer_AddLessThanInterval(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := gtimer.New(10, 100*time.Millisecond)
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.Add(20*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -226,7 +226,7 @@ func TestTimer_AddLessThanInterval(t *testing.T) {
|
||||
func TestTimer_AddLeveledEntry1(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
//glog.Println("start")
|
||||
timer.DelayAdd(1000*time.Millisecond, 1001*time.Millisecond, func() {
|
||||
//glog.Println("add")
|
||||
@ -243,7 +243,7 @@ func TestTimer_AddLeveledEntry1(t *testing.T) {
|
||||
func TestTimer_Exit(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
timer.Add(200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
gtimer.Exit()
|
||||
|
||||
@ -18,7 +18,7 @@ import (
|
||||
|
||||
func TestEntry_Start_Stop_Close(t *testing.T) {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
entry := timer.Add(200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -39,7 +39,7 @@ func TestEntry_Start_Stop_Close(t *testing.T) {
|
||||
|
||||
func TestEntry_Singleton(t *testing.T) {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
entry := timer.Add(200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
time.Sleep(10 * time.Second)
|
||||
@ -56,7 +56,7 @@ func TestEntry_Singleton(t *testing.T) {
|
||||
|
||||
func TestEntry_SetTimes(t *testing.T) {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
entry := timer.Add(200*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
@ -67,7 +67,7 @@ func TestEntry_SetTimes(t *testing.T) {
|
||||
|
||||
func TestEntry_Run(t *testing.T) {
|
||||
timer := New()
|
||||
array := garray.New()
|
||||
array := garray.New(true)
|
||||
entry := timer.Add(1000*time.Millisecond, func() {
|
||||
array.Append(1)
|
||||
})
|
||||
|
||||
@ -57,7 +57,7 @@ func ParseContent(content string, params Params) (string, error) {
|
||||
// The parameter <path> specifies the template directory path to load template files.
|
||||
func New(path ...string) *View {
|
||||
view := &View{
|
||||
paths: garray.NewStringArray(),
|
||||
paths: garray.NewStringArray(true),
|
||||
data: make(map[string]interface{}),
|
||||
funcMap: make(map[string]interface{}),
|
||||
delimiters: make([]string, 2),
|
||||
|
||||
@ -31,7 +31,7 @@ const (
|
||||
var (
|
||||
// Templates cache map for template folder.
|
||||
// TODO Note that there's no expiring logic for this map.
|
||||
templates = gmap.NewStrAnyMap()
|
||||
templates = gmap.NewStrAnyMap(true)
|
||||
)
|
||||
|
||||
// getTemplate returns the template object associated with given template folder <path>.
|
||||
|
||||
@ -15,7 +15,7 @@ const (
|
||||
|
||||
var (
|
||||
// Instances map.
|
||||
instances = gmap.NewStrAnyMap()
|
||||
instances = gmap.NewStrAnyMap(true)
|
||||
)
|
||||
|
||||
// Instance returns an instance of View with default settings.
|
||||
|
||||
@ -26,7 +26,7 @@ const (
|
||||
|
||||
var (
|
||||
// 默认错误消息管理对象(并发安全)
|
||||
errorMsgMap = gmap.NewStrStrMap()
|
||||
errorMsgMap = gmap.NewStrStrMap(true)
|
||||
|
||||
// 单规则正则对象,这里使用包内部变量存储,不需要多次解析
|
||||
ruleRegex, _ = regexp.Compile(gSINGLE_RULE_PATTERN)
|
||||
|
||||
Reference in New Issue
Block a user