github.com/Mericusta/go-stp@v0.6.8/README.md (about)

     1  # go-stp
     2  
     3  ## map
     4  
     5  ### func
     6  
     7  - Key[K comparable, V any](tm map[K]V) []K
     8      get key slice from a map
     9  - NewMap[K comparable, V any]() *Map[K, V]
    10      make a Map struct
    11  - NewCMap[K comparable, V any]() *CMap[K, V]
    12      make a CMap struct
    13  
    14  ### struct
    15  
    16  - Map [K comparable, V any]
    17      - a shrinkable map
    18  - CMap [K comparable, V any]
    19      - a map has a sync.RWMutex
    20  
    21  ### method
    22  
    23  - Map [K comparable, V any]
    24      - func (m *Map[K, V]) Set(k K, v V)
    25      - func (m *Map[K, V]) Del(k K)
    26      - func (m Map[K, V]) Get(k K) (V, bool)
    27      - func (m Map[K, V]) Key() []K
    28      - func (m Map[K, V]) Range(f func(K, V) bool)
    29  
    30  - CMap [K comparable, V any]
    31      - func (cm *CMap[K, V]) Get(k K) (V, bool)
    32      - func (cm *CMap[K, V]) Save(k K, v V) (int, bool)
    33      - func (cm *CMap[K, V]) Remove(k K) (V, int)
    34      
    35  ## slice
    36  
    37  ### func
    38  
    39  - Compare
    40      compare any two slice
    41  
    42  ## convert
    43  
    44  ### func
    45  
    46  - ConvertStringToStringStruct
    47  
    48  split a string by splitter, then convert it to a struct, which the first several members's type must be string, eg,
    49  ```go
    50  var s string = "I am a boy,You are a girl,We are human"
    51  type _s struct {
    52      s1 string
    53      s2 string
    54      s3 string
    55      // ...
    56  }
    57  
    58  // &_s{s1: "I am a boy", s2: "You are a girl", s3: "We are human"}
    59  fmt.Println(ConvertStringToStringStruct[_s](s, ","))
    60  ```
    61  
    62  ## channel
    63  
    64  ### func
    65  
    66  - NewSharedChannel
    67  
    68  create a shared channel
    69  
    70  - NewSharedBufferChannel
    71  
    72  create a shared channel with buffer
    73  
    74  ### struct
    75  
    76  - SharedChannel[T any]
    77      - shared channel
    78  
    79  ### method
    80  
    81  - SharedChannel[T any]
    82      - func (sc *SharedChannel[T]) Share() *SharedChannel[T]
    83      - func (sc *SharedChannel[T]) Get() chan T
    84      - func (sc *SharedChannel[T]) UseCount() int64
    85      - func (sc *SharedChannel[T]) Close()
    86  
    87  ## pool
    88  
    89  ### func
    90  
    91  - NewPool[T any](c int) *Pool[T]
    92      - make an object pool with counter to allocate memory
    93      - in particular, any type that uses `Pool` needs to implement its null method, that is, the byte array element pointing to memory is 0, for example: `simpleStruct.Free`
    94  
    95  ### struct
    96  
    97  - Pool[T any]
    98      - pool struct, holding memory byte
    99  
   100  ### method
   101  
   102  - Pool[T any]
   103      - func (p *Pool[T]) Get() *T
   104  
   105  ## queue
   106  
   107  > copy from $GOROOT/src/sync/poolqueue.go
   108  
   109  ### func
   110  
   111  - func NewPoolDequeue(n int) PoolDequeue
   112  - func NewPoolChain() PoolDequeue
   113  
   114  ### interface
   115  
   116  - PoolDequeue
   117      - PushHead(val any) bool
   118      - PopHead() (any, bool)
   119      - PopTail() (any, bool)
   120  
   121  ### struct
   122  
   123  - poolDequeue
   124  - poolChain