GoCollections/main.go

77 lines
1.6 KiB
Go
Raw Normal View History

2021-05-20 17:32:35 +08:00
package main
import (
"fmt"
2021-05-21 09:48:33 +08:00
"github.com/tursom/GoCollections/collections"
"github.com/tursom/GoCollections/exceptions"
2022-03-21 11:02:41 +08:00
"github.com/tursom/GoCollections/lang"
2021-05-22 17:10:26 +08:00
"time"
2021-05-20 17:32:35 +08:00
)
func main() {
2022-03-23 10:15:18 +08:00
_, err := exceptions.Try(func() (any, exceptions.Exception) {
2021-05-21 09:41:58 +08:00
panic("test")
2022-03-23 10:15:18 +08:00
}, func(r any) (any, exceptions.Exception) {
2021-05-21 09:41:58 +08:00
fmt.Println("recover from panic", r)
2022-03-23 10:15:18 +08:00
return nil, exceptions.NewIndexOutOfBound(fmt.Sprint(r), nil)
2021-05-21 10:31:49 +08:00
})
2021-05-21 16:57:33 +08:00
exceptions.Print(err)
2021-05-21 09:41:58 +08:00
2022-03-21 11:02:41 +08:00
list := collections.NewConcurrentLinkedQueue[lang.Int]()
target := collections.NewArrayListByCapacity[lang.Int](10000)
2021-05-22 17:10:26 +08:00
fmt.Println("list", list)
go func() {
for i := 0; i < 1000000; i++ {
2022-03-21 11:02:41 +08:00
list.Offer()
2021-05-22 17:10:26 +08:00
//fmt.Println(offer)
2022-03-21 11:02:41 +08:00
//if element != nil {
// target.Add(element)
//}
2021-05-22 17:10:26 +08:00
}
fmt.Println("target:", target)
}()
2021-05-20 17:32:35 +08:00
2021-05-22 17:10:26 +08:00
go func() {
for i := 0; i < 1000; i++ {
2022-03-21 11:02:41 +08:00
err = list.Push(lang.Int(i))
2021-05-22 17:10:26 +08:00
//fmt.Println(err)
2021-05-20 17:32:35 +08:00
}
2021-05-22 17:10:26 +08:00
time.Sleep(time.Second * 2)
2021-05-20 17:32:35 +08:00
fmt.Println(list)
2021-05-22 17:10:26 +08:00
}()
//
//for i := 0; i < 100; i++ {
// fmt.Println(list)
//}
time.Sleep(time.Second * 10)
fmt.Println("target:", target)
//for i := 0; i < 20; i++ {
// list.Push(i)
// fmt.Println(list)
//}
//
//for i := 0; i < 20; i++ {
// list.Offer()
// fmt.Println(list)
//}
//
//for i := 0; i < 25; i++ {
// list.Push(i)
// fmt.Println(list)
//}
//
2022-03-23 10:15:18 +08:00
//_ = collections.LoopMutable(list, func(element any, iterator collections.MutableIterator) (err exceptions.Exception) {
2021-05-22 17:10:26 +08:00
// if element.(int)&1 == 0 {
// err = iterator.Remove()
// }
// fmt.Println(list)
// return
//})
2021-05-20 17:32:35 +08:00
//for i := 0; i < 10; i++ {
// list.Remove(i * 2)
// fmt.Println(list)
//}
}