Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0631e01
add generic tree feature
joy999 Nov 24, 2025
2609dcd
add tree.lazyInit()
joy999 Nov 24, 2025
d1f5e6a
improve codes
joy999 Nov 24, 2025
0ab7df5
improve codes
joy999 Nov 24, 2025
d0e9393
improved
joy999 Nov 24, 2025
34a7e4f
improved
joy999 Nov 24, 2025
b973cd8
Merge branch 'master' into feat/kv_tree
hailaz Nov 24, 2025
024249f
chore(ci): Comment out MSSQL docker service configuration for future …
hailaz Nov 24, 2025
1def157
feat(ci): add cleanup script for Docker resources and update script p…
hailaz Nov 24, 2025
641223e
fix(ci): path
hailaz Nov 24, 2025
6208969
Merge branch 'master' into feat/kv_tree
joy999 Nov 24, 2025
197d27d
feat(ci): 启用MSSQL Docker服务并清理MySQL资源的注释
hailaz Nov 24, 2025
6f857d8
feat(ci): 添加Docker资源清理脚本中的磁盘使用情况显示
hailaz Nov 24, 2025
084474a
fix(ci): 注释掉对mssql测试的忽略逻辑
hailaz Nov 25, 2025
a4acebe
fix(ci): 注释掉清理缓存的逻辑以避免CI管道中的错误
hailaz Nov 25, 2025
9fa8743
fix(ci): 在检查Go版本不符合要求时添加清理Docker容器和镜像的逻辑
hailaz Nov 25, 2025
0812575
fix(ci): 清理mssql测试的Docker资源并恢复相关逻辑
hailaz Nov 25, 2025
a28c1ea
fix(ci): 移除mssql服务的多余空行
hailaz Nov 25, 2025
814af08
Merge branch 'master' of github.com:gogf/gf into feat/kv_tree
hailaz Nov 25, 2025
2903cc4
Merge branch 'master' into feat/kv_tree
hailaz Nov 28, 2025
c3d19d8
Merge branch 'master' into feat/kv_tree
hailaz Nov 29, 2025
7179f24
feat(container/gmap): 优化 TreeKVMap 的初始化方式,直接返回 gtree 的实例
hailaz Nov 29, 2025
91341c2
feat(container/gmap): 更新 gmap_tree_k_v_map.go 文件,添加 go:build 指令
hailaz Nov 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions container/gmap/gmap_tree_k_v_map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.

//go:build go1.24

package gmap

import (
"github.com/gogf/gf/v2/container/gtree"
)

// TreeKVMap based on red-black tree, alias of RedBlackKVTree.
type TreeKVMap[K comparable, V any] = gtree.RedBlackKVTree[K, V]

// NewTreeKVMap instantiates a tree map with the custom comparator.
// The parameter `safe` is used to specify whether using tree in concurrent-safety,
// which is false in default.
func NewTreeKVMap[K comparable, V any](comparator func(v1, v2 K) int, safe ...bool) *TreeKVMap[K, V] {
return gtree.NewRedBlackKVTree[K, V](comparator, safe...)
}

// NewTreeKVMapFrom instantiates a tree map with the custom comparator and `data` map.
// 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.
// The parameter `safe` is used to specify whether using tree in concurrent-safety,
// which is false in default.
func NewTreeKVMapFrom[K comparable, V any](comparator func(v1, v2 K) int, data map[K]V, safe ...bool) *TreeKVMap[K, V] {
return gtree.NewRedBlackKVTreeFrom(comparator, data, safe...)
}
15 changes: 12 additions & 3 deletions container/gtree/gtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ type iTree interface {
IteratorDescFrom(key any, match bool, f func(key, value any) bool)
}

// iteratorFromGetIndex returns the index of the key in the keys slice.
// iteratorFromGetIndexT returns the index of the key in the keys slice.
//
// The parameter `match` specifies whether starting iterating only if the `key` is fully matched,
// or else using index searching iterating.
// If `isIterator` is true, iterator is available; or else not.
func iteratorFromGetIndex(key any, keys []any, match bool) (index int, canIterator bool) {
func iteratorFromGetIndexT[T comparable](key T, keys []T, match bool) (index int, canIterator bool) {
if match {
for i, k := range keys {
if k == key {
Expand All @@ -176,10 +176,19 @@ func iteratorFromGetIndex(key any, keys []any, match bool) (index int, canIterat
}
}
} else {
if i, ok := key.(int); ok {
if i, ok := any(key).(int); ok {
canIterator = true
index = i
}
}
return
}

// iteratorFromGetIndex returns the index of the key in the keys slice.
//
// The parameter `match` specifies whether starting iterating only if the `key` is fully matched,
// or else using index searching iterating.
// If `isIterator` is true, iterator is available; or else not.
func iteratorFromGetIndex(key any, keys []any, match bool) (index int, canIterator bool) {
return iteratorFromGetIndexT(key, keys, match)
}
Loading
Loading