Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skyleaworlder/bslice
:sob: 一个没用的玩意儿,恰似 2021.07.13 时的 skyleaworlder
https://github.com/skyleaworlder/bslice
Last synced: about 2 months ago
JSON representation
:sob: 一个没用的玩意儿,恰似 2021.07.13 时的 skyleaworlder
- Host: GitHub
- URL: https://github.com/skyleaworlder/bslice
- Owner: skyleaworlder
- License: mit
- Created: 2021-07-13T06:01:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-13T06:02:32.000Z (over 3 years ago)
- Last Synced: 2024-10-12T21:13:08.435Z (3 months ago)
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bslice
一个无用的数据结构。
动机是看到一道层次遍历但需要记忆上一级节点的题。写的时候必须维护两个队列,这让我很难受。于是我就想着,如果我都对一个数据结构操作就好了,所以就有了这个。
## API
```go
func (bs *Bslice) Top() (elem interface{}, err error)func (bs *Bslice) Front() (elem interface{}, err error)
func (bs *Bslice) EnqueueMultiElem(elems []interface{}, changeAfterOp bool) (size int)
func (bs *Bslice) DequeueMultiElem(num int) (elems []interface{}, size int, err error)
func (bs *Bslice) DequeueAll() (elems []interface{}, size int, err error)
```通过 `EnqueueMultiElem` 函数的 `changeAfterOp` 参数,决定下一次 `enqueue` 的队列是否改变。
## Example
```go
func main() {
bs := CreateBslice()
testEnqueueElements := [][]int{
{1, 2, 46, 18, 21, 8, 215},
{2, 4, 5, 6},
{3, 4, 4, 7, 0},
}
testEnqueueChangeOp := []bool{
false, true, false,
}for i, elems := range testEnqueueElements {
enqarr := make([]interface{}, len(elems))
for j, v := range elems {
enqarr[j] = v
}
bs.EnqueueMultiElem(enqarr, testEnqueueChangeOp[i])// print out:
// after 1 enqueue operation: &{true 0 [1 2 46 18 21 8 215] []}
// after 2 enqueue operation: &{false 1 [1 2 46 18 21 8 215 2 4 5 6] []}
// after 3 enqueue operation: &{false 1 [1 2 46 18 21 8 215 2 4 5 6] [3 4 4 7 0]}
fmt.Println("after ", i+1, " enqueue operation:", bs)
}deqarr, n, err := bs.DequeueMultiElem(2)
// print out: &{false 1 [46 18 21 8 215 2 4 5 6] [3 4 4 7 0]} [1 2] 2
fmt.Println(bs, deqarr, n, err)deqarr, n, err = bs.DequeueMultiElem(len(testEnqueueElements) - 2)
// print out: &{false 1 [18 21 8 215 2 4 5 6] [3 4 4 7 0]} [46] 1
fmt.Println(bs, deqarr, n, err)deqarr, n, err = bs.DequeueAll()
// print out: &{false 1 [] [3 4 4 7 0]} [18 21 8 215 2 4 5 6] 8
fmt.Println(bs, deqarr, n, err)
}
```