Documentation
¶
Overview ¶
Package casset help you to create memory on double linked list.
Example ¶
package main import ( "fmt" "github.com/rytsh/casset" ) func main() { // create a memory with a first value // value could be anything l := casset.NewMemory[any]().GetFront().SetValue("My First Element") l.Next("second element").Next(3.14).Next(struct{ v string }{v: "4th element"}) // for e := l.GetMemory().GetFront(); e != nil; e = e.GetNextElement() { // fmt.Println(e.GetValue()) // } for e := range l.GetMemory().Range() { fmt.Println(e.GetValue()) } }
Output: My First Element second element 3.14 {4th element}
Index ¶
- type Element
- func (e *Element[T]) Delete() IElement[T]
- func (e *Element[T]) GetMemory() IMemory[T]
- func (e *Element[T]) GetNextElement() IElement[T]
- func (e *Element[T]) GetPrevElement() IElement[T]
- func (e *Element[T]) GetValue() T
- func (e *Element[T]) Next(v T) IElement[T]
- func (e *Element[T]) Prev(v T) IElement[T]
- func (e *Element[T]) SetMemory(m IMemory[T]) IElement[T]
- func (e *Element[T]) SetNextElement(element IElement[T]) IElement[T]
- func (e *Element[T]) SetPrevElement(element IElement[T]) IElement[T]
- func (e *Element[T]) SetValue(v T) IElement[T]
- type IElement
- type ILen
- type IMemory
- type Len
- type Memory
- func (m *Memory[T]) Clear() IMemory[T]
- func (m *Memory[T]) GetBack() IElement[T]
- func (m *Memory[T]) GetFront() IElement[T]
- func (m *Memory[T]) GetLen() ILen
- func (m *Memory[T]) Range() iter.Seq[IElement[T]]
- func (m *Memory[T]) RemoveRange(e1, e2 IElement[T])
- func (m *Memory[T]) SetBack(e IElement[T])
- func (m *Memory[T]) SetFront(e IElement[T])
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element[T any] struct { // contains filtered or unexported fields }
Element is an struct of double-linked list.
Example ¶
package main import ( "fmt" "github.com/rytsh/casset" ) func main() { e := casset.NewElement(1234) e.Next(5678).Next(91011) for v := e; v != nil; v = v.GetNextElement() { fmt.Println(v.GetValue()) } }
Output: 1234 5678 91011
func (*Element[T]) Delete ¶
Delete this element, reconnect prev and next if exist. When deleting current element, it will set current element to last or next element.
func (*Element[T]) GetNextElement ¶
func (*Element[T]) GetPrevElement ¶
func (*Element[T]) SetNextElement ¶
SetNextElement set next element.
func (*Element[T]) SetPrevElement ¶
SetPrevElement set previous element.
type IElement ¶
type IElement[T any] interface { // GetMemory return memory of this element. GetMemory() IMemory[T] // SetMemory set memory of this element. SetMemory(m IMemory[T]) IElement[T] // GetValue return value of this element. GetValue() T // GetNextElement return next element of this element. GetNextElement() IElement[T] // GetPrevElement return prev element of this element. GetPrevElement() IElement[T] // SetValue set value of this element. SetValue(v T) IElement[T] // SetNextElement set next element. SetNextElement(IElement[T]) IElement[T] // SetPrevElement set prev element. SetPrevElement(IElement[T]) IElement[T] // Delete this element, reconnect prev and next if exist. Delete() IElement[T] // Next return next element if exist or generate new element with argument and return new element. Next(T) IElement[T] // Prev return prev element if exist or generate new element with argument and return new element. Prev(T) IElement[T] }
func NewElement ¶
type IMemory ¶
type IMemory[T any] interface { // Clear remove all elements. Clear() IMemory[T] // RemoveRange remove range of elements including e1 and e2. // If e1 is nil, start from front. // If e2 is nil, end at back. // Both e1 and e2 are nil, remove all. RemoveRange(e1, e2 IElement[T]) GetLen() ILen GetFront() IElement[T] SetFront(e IElement[T]) GetBack() IElement[T] SetBack(e IElement[T]) Range() iter.Seq[IElement[T]] }
type Memory ¶
type Memory[T any] struct { // contains filtered or unexported fields }
Memory is main struct of linked list.
func (*Memory[T]) RemoveRange ¶ added in v0.2.0
Remove remove range of elements. If elements not inside of memory, nothing change.
Click to show internal directories.
Click to hide internal directories.