github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/structure/queues/lscq/lscq.go (about) 1 package lscq 2 3 import ( 4 "fmt" 5 "unsafe" 6 7 "github.com/songzhibin97/go-baseutils/structure/queues" 8 ) 9 10 // Assert Queue implementation 11 var _ queues.Queue[any] = (*Queue[any])(nil) 12 13 type Queue[E any] struct { 14 q *PointerQueue 15 zero E 16 } 17 18 func New[E any]() *Queue[E] { 19 return &Queue[E]{ 20 q: NewPointer(), 21 } 22 } 23 24 func (q *Queue[E]) Enqueue(value E) { 25 _ = fmt.Sprintf("%p", &value) // TODO make generic variables escape 26 q.q.Enqueue(unsafe.Pointer(&value)) 27 } 28 29 func (q *Queue[E]) Dequeue() (value E, ok bool) { 30 data, ok := q.q.Dequeue() 31 if !ok { 32 return q.zero, ok 33 } 34 return *(*E)(data), ok 35 } 36 37 func (q *Queue[E]) Peek() (value E, ok bool) { 38 //TODO implement me 39 panic("implement me") 40 } 41 42 func (q *Queue[E]) Empty() bool { 43 //TODO implement me 44 panic("implement me") 45 } 46 47 func (q *Queue[E]) Size() int { 48 //TODO implement me 49 panic("implement me") 50 } 51 52 func (q *Queue[E]) Clear() { 53 //TODO implement me 54 panic("implement me") 55 } 56 57 func (q *Queue[E]) Values() []E { 58 //TODO implement me 59 panic("implement me") 60 } 61 62 func (q *Queue[E]) String() string { 63 //TODO implement me 64 panic("implement me") 65 }