@@ -42,6 +42,15 @@ func NewRedBlackKVTree[K comparable, V any](comparator func(v1, v2 K) int, safe
4242 return & tree
4343}
4444
45+ // NewRedBlackKVTreeWithChecker instantiates a red-black tree with the custom key comparator and `nilChecker`.
46+ // The parameter `safe` is used to specify whether using tree in concurrent-safety, which is false in default.
47+ // The parameter `checker` is used to specify whether the given value is nil.
48+ func NewRedBlackKVTreeWithChecker [K comparable , V any ](comparator func (v1 , v2 K ) int , checker NilChecker [V ], safe ... bool ) * RedBlackKVTree [K , V ] {
49+ t := NewRedBlackKVTree [K , V ](comparator , safe ... )
50+ t .RegisterNilChecker (checker )
51+ return t
52+ }
53+
4554// NewRedBlackKVTreeFrom instantiates a red-black tree with the custom key comparator and `data` map.
4655// The parameter `safe` is used to specify whether using tree in concurrent-safety,
4756// which is false in default.
@@ -51,6 +60,17 @@ func NewRedBlackKVTreeFrom[K comparable, V any](comparator func(v1, v2 K) int, d
5160 return & tree
5261}
5362
63+ // NewRedBlackKVTreeWithCheckerFrom instantiates a red-black tree with the custom key comparator, `data` map and `nilChecker`.
64+ // The parameter `safe` is used to specify whether using tree in concurrent-safety, which is false in default.
65+ // The parameter `checker` is used to specify whether the given value is nil.
66+ func NewRedBlackKVTreeWithCheckerFrom [K comparable , V any ](comparator func (v1 , v2 K ) int , data map [K ]V , checker NilChecker [V ], safe ... bool ) * RedBlackKVTree [K , V ] {
67+ t := NewRedBlackKVTreeWithChecker [K , V ](comparator , checker , safe ... )
68+ for k , v := range data {
69+ t .doSet (k , v )
70+ }
71+ return t
72+ }
73+
5474// RedBlackKVTreeInit instantiates a red-black tree with the custom key comparator.
5575// The parameter `safe` is used to specify whether using tree in concurrent-safety,
5676// which is false in default.
@@ -210,7 +230,7 @@ func (tree *RedBlackKVTree[K, V]) GetOrSetFunc(key K, f func() V) V {
210230// GetOrSetFuncLock returns its `value` of `key`, or sets value with returned value of callback function `f` if it does
211231// not exist and then returns this value.
212232//
213- // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function `f`within mutex lock.
233+ // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function `f` within mutex lock.
214234func (tree * RedBlackKVTree [K , V ]) GetOrSetFuncLock (key K , f func () V ) V {
215235 tree .mu .Lock ()
216236 defer tree .mu .Unlock ()
0 commit comments