基本介绍

支持并发安全开关特性的树形容器,树形数据结构的特点是支持有序遍历、内存占用低、复杂度稳定、适合大数据量存储。该模块包含多个数据结构的树形容器:RedBlackTreeAVLTreeBTree

类型数据结构平均复杂度支持排序有序遍历说明
RedBlackTree红黑树O(log N)写入性能比较好
AVLTree高度平衡树O(log N)查找性能比较好
BTreeB树/B-树O(log N)常用于外部存储

参考连接:https://en.wikipedia.org/wiki/Binary_tree

使用场景

关联数组场景、排序键值对场景、大数据量内存CURD场景等等。

使用方式

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

接口文档

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

几种容器的API方法都非常类似,特点是需要在初始化时提供用于排序的方法。

gutil模块中提供了常用的一些基本类型比较方法,可以直接在程序中直接使用,后续也有示例。

  1. func ComparatorByte(a, b interface{}) int
  2. func ComparatorFloat32(a, b interface{}) int
  3. func ComparatorFloat64(a, b interface{}) int
  4. func ComparatorInt(a, b interface{}) int
  5. func ComparatorInt16(a, b interface{}) int
  6. func ComparatorInt32(a, b interface{}) int
  7. func ComparatorInt64(a, b interface{}) int
  8. func ComparatorInt8(a, b interface{}) int
  9. func ComparatorRune(a, b interface{}) int
  10. func ComparatorString(a, b interface{}) int
  11. func ComparatorTime(a, b interface{}) int
  12. func ComparatorUint(a, b interface{}) int
  13. func ComparatorUint16(a, b interface{}) int
  14. func ComparatorUint32(a, b interface{}) int
  15. func ComparatorUint64(a, b interface{}) int
  16. func ComparatorUint8(a, b interface{}) int

相关文档