Introduction

Concurrent-safe feature support for tree containers, with the characteristics of tree data structures supporting ordered traversal, low memory consumption, stable complexity, and suitability for large data storage. This module includes tree containers for multiple data structures: RedBlackTree, AVLTree, and BTree.

TypeData StructureAverage ComplexitySupports SortingOrdered TraversalDescription
RedBlackTreeRed-black treeO(log N)YesYesGood write performance
AVLTreeHeight-balanced treeO(log N)YesYesGood search performance
BTreeB-tree/B-treeO(log N)YesYesCommonly used for external storage

Reference link: https://en.wikipedia.org/wiki/Binary_tree

Usage Scenarios:

Associative array scenarios, sorted key-value pair scenarios, large data volume memory CURD scenarios, etc.

Usage Method:

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

API Documentation:

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

The API methods for several containers are very similar, characterized by needing to provide methods for sorting during initialization.

The gutil module provides some common basic type comparison methods that can be directly used in the program, and examples are also available later.

  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

Documentation

📄️ Tree - UsageBasic operations using tree-type data structures in the GoFrame framework. Demonstrates how to create and operate on RedBlackTree and AVL trees through example code, including adding, deleting, and traversing nodes, enabling developers to easily achieve efficient data storage and lookup.

📄️ Tree - MethodsA variety of operations for tree structures in the GoFrame framework, including NewBTree, Clone, Set, Get, etc. Detailed examples demonstrate how to use these methods for node addition, search, deletion, and more, while supporting concurrency-safe settings. Users can quickly master the techniques for using tree structures through this documentation.