GoFrame gtree-基本介紹

2022-04-08 15:19 更新

基本介紹

支持并發(fā)安全開關(guān)特性的樹形容器,樹形數(shù)據(jù)結(jié)構(gòu)的特點(diǎn)是支持有序遍歷、內(nèi)存占用低、復(fù)雜度穩(wěn)定、適合大數(shù)據(jù)量存儲。該模塊包含多個(gè)數(shù)據(jù)結(jié)構(gòu)的樹形容器:?RedBlackTree?、?AVLTree?和?BTree?。

類型
數(shù)據(jù)結(jié)構(gòu)
平均復(fù)雜度
支持排序
有序遍歷
說明
RedBlackTree 紅黑樹 O(log N) 寫入性能比較好
AVLTree 高度平衡樹 O(log N) 查找性能比較好
BTree B樹/B-樹 O(log N) 常用于外部存儲

參考連接:https://en.wikipedia.org/wiki/Binary_tree

使用場景:關(guān)聯(lián)數(shù)組場景、排序鍵值對場景、大數(shù)據(jù)量內(nèi)存CURD場景等等。

使用方式:

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

接口文檔:

https://pkg.go.dev/github.com/gogf/gf/v2/container/gtree

幾種容器的API方法都非常類似,特點(diǎn)是需要在初始化時(shí)提供用于排序的方法。

在?gutil?模塊中提供了常用的一些基本類型比較方法,可以直接在程序中直接使用,后續(xù)也有示例。

func ComparatorByte(a, b interface{}) int
func ComparatorFloat32(a, b interface{}) int
func ComparatorFloat64(a, b interface{}) int
func ComparatorInt(a, b interface{}) int
func ComparatorInt16(a, b interface{}) int
func ComparatorInt32(a, b interface{}) int
func ComparatorInt64(a, b interface{}) int
func ComparatorInt8(a, b interface{}) int
func ComparatorRune(a, b interface{}) int
func ComparatorString(a, b interface{}) int
func ComparatorTime(a, b interface{}) int
func ComparatorUint(a, b interface{}) int
func ComparatorUint16(a, b interface{}) int
func ComparatorUint32(a, b interface{}) int
func ComparatorUint64(a, b interface{}) int
func ComparatorUint8(a, b interface{}) int


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號