2 Star 1 Fork 1

mosache / YFrame

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
linked_queue.go 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
ヤ沒脩袮兲︶ 提交于 2023-10-20 18:32 . temp
package linked_queue
import (
"context"
"unsafe"
)
type LinkedQueue[T any] struct {
head unsafe.Pointer
tail unsafe.Pointer
zero T
}
type node[T any] struct {
data T
next unsafe.Pointer
}
func NewLinkedQueue[T any]() *LinkedQueue[T] {
head := &node[T]{}
headPtr := unsafe.Pointer(head)
return &LinkedQueue[T]{
head: headPtr,
tail: headPtr,
}
}
func (l *LinkedQueue[T]) Push(ctx context.Context, el T) error {
//valNode := &node[T]{data: el}
//valPtr := unsafe.Pointer(valNode)
//
//for {
// tail := atomic.LoadPointer(&l.tail)
//
//}
//
//tail.next = valNode
//l.tail = valNode
return nil
}
func (l *LinkedQueue[T]) Pop(ctx context.Context) (T, error) {
//l.mutex.Lock()
//defer l.mutex.Unlock()
//
//if l.head == l.tail {
// return l.zero, errors.New("empty")
//}
//
//head := l.head
//
//l.head = head.next
//head.next = nil
return l.zero, nil
}
func (l *LinkedQueue[T]) Size() int {
//TODO implement me
panic("implement me")
}
func (l *LinkedQueue[T]) Clear() error {
//TODO implement me
panic("implement me")
}
func (l *LinkedQueue[T]) IsEmpty() bool {
//TODO implement me
panic("implement me")
}
Go
1
https://gitee.com/mosache/YFrame.git
git@gitee.com:mosache/YFrame.git
mosache
YFrame
YFrame
v0.1.76

搜索帮助