Something went wrong. Try again.
Fork of micro-editor/micro
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344package buffer
// TEStack is a simple implementation of a LIFO stack for text eventstype TEStack struct { Top *Element Size int}
// An Element which is stored in the Stacktype Element struct { Value *TextEvent Next *Element}
// Len returns the stack's lengthfunc (s *TEStack) Len() int { return s.Size}
// Push a new element onto the stackfunc (s *TEStack) Push(value *TextEvent) { s.Top = &Element{value, s.Top} s.Size++}
// Pop removes the top element from the stack and returns its value// If the stack is empty, return nilfunc (s *TEStack) Pop() (value *TextEvent) { if s.Size > 0 { value, s.Top = s.Top.Value, s.Top.Next s.Size-- return } return nil}
// Peek returns the top element of the stack without removing itfunc (s *TEStack) Peek() *TextEvent { if s.Size > 0 { return s.Top.Value } return nil}