mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-28 02:50:25 +08:00
优化链表相关代码
This commit is contained in:
@@ -4,6 +4,7 @@ package linkedlist_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/linkedlist"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"testing"
|
||||
@@ -95,6 +96,48 @@ func TestList_Push(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestList_Shift(t *testing.T) {
|
||||
var list = linkedlist.NewList[int]()
|
||||
list.Push(linkedlist.NewItem(1))
|
||||
list.Push(linkedlist.NewItem(2))
|
||||
list.Push(linkedlist.NewItem(3))
|
||||
list.Push(linkedlist.NewItem(4))
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
t.Log("=== before shift " + types.String(i) + " ===")
|
||||
list.Range(func(item *linkedlist.Item[int]) (goNext bool) {
|
||||
t.Log(item.Value)
|
||||
return true
|
||||
})
|
||||
|
||||
t.Logf("shift: %+v", list.Shift())
|
||||
|
||||
t.Log("=== after shift " + types.String(i) + " ===")
|
||||
list.Range(func(item *linkedlist.Item[int]) (goNext bool) {
|
||||
t.Log(item.Value)
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestList_RangeReverse(t *testing.T) {
|
||||
var list = linkedlist.NewList[int]()
|
||||
list.Push(linkedlist.NewItem(1))
|
||||
list.Push(linkedlist.NewItem(2))
|
||||
|
||||
var item3 = linkedlist.NewItem(3)
|
||||
list.Push(item3)
|
||||
|
||||
list.Push(linkedlist.NewItem(4))
|
||||
|
||||
//list.Push(item3)
|
||||
//list.Remove(item3)
|
||||
list.RangeReverse(func(item *linkedlist.Item[int]) (goNext bool) {
|
||||
t.Log(item.Value)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkList_Add(b *testing.B) {
|
||||
var list = linkedlist.NewList[int]()
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
||||
Reference in New Issue
Block a user