github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xcontainer/README.md (about)

     1  # XContainer
     2  
     3  go作为强类型,静态类型语言,因为缺乏泛型,缺少了大量的通用集合库,因此这里旨在提供常用的集合库,减少模版代码。
     4  
     5  ## maps
     6  ##### StringKeyBtreeMap 基于B树的key为string的map
     7  定义
     8  ```go
     9  type Entry struct {
    10  	key string
    11  	val interface{}
    12  }
    13  
    14  type StringKeyBtreeMap struct {
    15  	tree *btree.BTree
    16  }
    17  ```
    18  方法
    19  ```go
    20  func (*Entry) Less(than btree.Item) bool
    21  func (*StringKeyBtreeMap) Set(key string, val interface{})
    22  func (*StringKeyBtreeMap) GetOk(key string) (interface{}, bool)
    23  func (*StringKeyBtreeMap) Remove(key string)
    24  func (*StringKeyBtreeMap) Exist(key string) bool
    25  func (*StringKeyBtreeMap) Range(begin, end string, fn func(key string, val interface{}) bool)
    26  func (*StringKeyBtreeMap) RangeAll(fn func(key string, val interface{}))
    27  ```
    28  ## priority_queue 优先级队列
    29  定义
    30  ```go
    31  type PriorityQueue struct {
    32  	h heap.Interface
    33  }
    34  ```
    35  方法
    36  ```go
    37  func NewPriorityQueue(h heap.Interface) *PriorityQueue
    38  func (*PriorityQueue) Push(x interface{})
    39  func (*PriorityQueue) Pop() interface{}
    40  ```
    41  支持的优先级队列的元素类型有`types.Comparable`, `int64`, `string`
    42  ## queue 双向队列
    43  
    44  ## set 集合
    45  
    46  ## stack 栈