Categorygithub.com/tansoz/golinkedlist
repositorypackage
1.0.1
Repository: https://github.com/tansoz/golinkedlist.git
Documentation: pkg.go.dev

# README

GoLinkedList

Install:

go get -u github.com/tansoz/golinkedlist

APIs:

  • LinkedList

    • func NewLinkedList() *LinkedList

      linkedList := NewLinkedList()       // new a LinkedList object  
      
    • func (linkedList *LinkedList) ForEach(fn func(node *Node) bool)

      linkedList.ForEach(func(node *Node, index int64)bool{
          return [condition]
      })
      
    • func (linkedList *LinkedList) GetHeadNode() *Node

      node := linkedList.GetHeadNode()
      
    • func (linkedList *LinkedList) GetTailNode() *Node

      node := linkedList.GetTailNode()
      
    • func (linkedList *LinkedList) HeadInsert(data unsafe.Pointer)

      // 1 2 3 4 5
      a := 6
      linkedList.HeadInsert(unsafe.Pointer(&a))
      // 6 1 2 3 4 5
      
    • func (linkedList *LinkedList) Insert(prevNode *Node, nextNode *Node, data unsafe.Pointer) *Node

      a := 123
      linkedList.Insert(nil,linkedList.GetHeadNode(),unsafe.Pointer(&a))
      
    • func (linkedList *LinkedList) InsertNode(prevNode *Node, nextNode *Node, node *Node)

      a := 123
      node := NewNode(&a)
      linkedList.InsertNode(nil,linkedList.GetHeadNode(),node)
      
    • func (linkedList *LinkedList) Items() chan *Node

      for node := range linkedList.Items(){
          fmt.Println(node)
      }
      
    • func (linkedList *LinkedList) Len() int64

      len := linkedList.Len() // count the length of the linked-list
      
    • func (linkedList *LinkedList) Merge(list *LinkedList)

      l1.Merge(l2)
      
    • func (linkedList *LinkedList) Move(node *Node, target *Node)

      linkedList.Move(node,targetNode)
      
    • func (linkedList *LinkedList) RangeSort(fn func(a unsafe.Pointer, b unsafe.Pointer) int, from *Node, to *Node)

      parameter fn can use nil

      // 5 6 2 1 3 4
      linkedList.RangeSort(function(a unsafe.Pointer, b unsafe.Pointer){
          return *(int)(b) - *(int)(a)
      }int,nil,nil)
      // 1 2 3 4 5 6
      linkedList.RangeSort(function(a unsafe.Pointer, b unsafe.Pointer){
          return *(int)(a) - *(int)(b)
      }int,nil,nil)
      // 6 5 4 3 2 1
      linkedList.RangeSort(nil,nil,nil)
      // 1 2 3 4 5 6
      
    • func (linkedList *LinkedList) RemoveNode(node *Node)

      linkedList.RemoveNode(node)
      
    • func (linkedList *LinkedList) Reverse()

      // 5 2 3 1 4
      linkedList.Reverse()
      // 4 1 3 2 5
      
    • func (linkedList *LinkedList) String() string

      linkedList.String()
      
    • func (linkedList *LinkedList) Swap(a *Node, b *Node) (*Node, *Node)

      linkedList.Swap(node1,node2)
      
    • func (linkedList *LinkedList) TailInsert(data unsafe.Pointer)

      // 1 2 3 4 5
      a := 6
      linkedList.TailInsert(unsafe.Pointer(&a))
      // 1 2 3 4 5 6
      
    • func (linkedList *LinkedList) ToArray() []unsafe.Pointer

      linkedList.ToArray()
      
    • func (linkedList *LinkedList) Get(index int64, data unsafe.Pointer) unsafe.Pointer

      node := linkedList.Get(5)
      
    • func (linkedList *LinkedList) Set(index int64, data unsafe.Pointer) unsafe.Pointer

      a := 1
      linkedList.Set(0,unsafe.Pointer(&a))
      
    • func (linkedList *LinkedList) GetCyclePrevNode(node *Node) *Node

      linkedList.GetCyclePrevNode(node)
      
    • func (linkedList *LinkedList) GetCycleNextNode(node *Node) *Node

      linkedList.GetCycleNextNode(node)
      
    • func (linkedList *LinkedList) ReplaceNode(replaceNode *Node, targetNode *Node) *Node

      linkedList.ReplaceNode(node1,node2)
      
  • Node

    • func NewNode(data unsafe.Pointer) *Node
      a := 1
      node := NewNode(unsafe.Pointer(&a))
      
    • func (node *Node) GetData() unsafe.Pointer
      a := 1
      node := NewNode(unsafe.Pointer(&a))
      fmt.Println(*(int)(node.GetData()))
      // 1
      
    • func (node *Node) GetNextNode() *Node
      node.GetNextNode()
      
    • func (node *Node) GetPrevNode() *Node
      node.GetPrevNode()
      
    • func (node *Node) SetData(data unsafe.Pointer) unsafe.Pointer
      c := 2
      node.SetData(unsafe.Pointer(&c))
      
    • func (node *Node) String() string
      node.String()
      
    • func (node *Node) Swap(b *Node)
      node.String(node2)
      
    • func (node *Node) Iterator(flag direct) chan *Node
      // 1->2->3->4->5
      
      for n := range node.Iterator(FORWARD){   // Assuming node is the third node. That is 3.
          fmt.Println(*(int)(n.GetData()))
      }
      /*
      output:
      3
      4
      5
      */
      
      for n := range node.Iterator(BACKWARD){   // Assuming node is the third node. That is 3.
          fmt.Println(*(int)(n.GetData()))
      }
      /*
      output:
      3
      2
      1
      */
      

The feature i want but do not achieve yet:

  • Thread safe
  • Merge Linked-list
  • To []unsafe.Pointer

Some functions wait for me to fixed:

  • RangeSort