MCPcopy
hub / github.com/gogf/gf / ExampleIntSet_AddIfNotExistFuncLock

Function ExampleIntSet_AddIfNotExistFuncLock

container/gset/gset_z_example_int_test.go:85–96  ·  view source on GitHub ↗

AddIfNotExistFunc checks whether item exists in the set, it adds the item to set and returns true if it does not exists in the set and function `f` returns true, or else it does nothing and returns false. Note that, the function `f` is executed without writing lock.

()

Source from the content-addressed store, hash-verified

83// or else it does nothing and returns false.
84// Note that, the function `f` is executed without writing lock.
85func ExampleIntSet_AddIfNotExistFuncLock() {
86 intSet := gset.NewIntSetFrom([]int{1, 2, 3})
87 intSet.Add(1)
88 fmt.Println(intSet.Slice())
89 fmt.Println(intSet.AddIfNotExistFuncLock(4, func() bool {
90 return true
91 }))
92
93 // May Output:
94 // [1 2 3]
95 // true
96}
97
98// Clear deletes all items of the set.
99func ExampleIntSet_Clear() {

Callers

nothing calls this directly

Calls 4

NewIntSetFromFunction · 0.92
AddMethod · 0.65
SliceMethod · 0.45
AddIfNotExistFuncLockMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…