lightning-engine icon indicating copy to clipboard operation
lightning-engine copied to clipboard

Bug , 跳表处理 价格相同,id 不同的情况有问题

Open barehead123 opened this issue 1 year ago • 1 comments

下面是测试代码


package main

import (
	"fmt"
	"github.com/shopspring/decimal"
	mainlog "lightning-engine/log"
	skiplist2 "lightning-engine/pqueue/skiplist"
	"strconv"
)

type entrust struct {
	Id     string
	Amount decimal.Decimal
}

func (e *entrust) GetId() string {
	return e.Id
}

func (e *entrust) GetAmount() decimal.Decimal {
	return e.Amount
}

func (e *entrust) GetUserId() int64 {
	return 0
}
func (e *entrust) SetAmount(a decimal.Decimal) {
	e.Amount = a
}

var skiplist *skiplist2.SkipList

func main() {
	mainlog.InitLog()

	skiplist, _ = skiplist2.NewSkipList()
	add := 0
	for z := 0; z < 2; z++ {
		for k := 0; k < 2; k++ {
			add = add + 10000

			for i := 0; i < 10000; i++ {
				price := decimal.NewFromInt(int64(i))
				e := &entrust{
					Id:     strconv.Itoa(i + add),
					Amount: price,
				}
				skiplist.Insert(price, e)
			}

			success := 0
			failed := 0
			for i := 0; i < 10000; i++ {
				price := decimal.NewFromInt(int64(i))
				node, _ := skiplist.Find(price, strconv.Itoa(i+add))
				if node == nil || !node.Score().Equal(price) {
					failed++
				} else {
					success++
				}
			}

			fmt.Println("success:", success, "failed:", failed)

			for i := 9999; i >= 0; i-- {
				price := decimal.NewFromInt(int64(i))
				skiplist.Delete(price, strconv.Itoa(i+add))
				//skiplist.Delete(decimal.NewFromInt(int64(i)), strconv.Itoa(i+add))
			}
			if skiplist.GetSize() > 0 || skiplist.GetLevel() > 1 {
				fmt.Println("error", skiplist.GetSize(), skiplist.GetLevel())
			} else {
				fmt.Println("success")
			}
		}

		for k := 0; k < 1; k++ {
			add = add + 10000

			for i := 0; i < 10000; i++ {
				price := decimal.NewFromInt(int64(123))
				e := &entrust{
					Id:     strconv.Itoa(i + add),
					Amount: decimal.NewFromInt(int64(123)),
				}
				skiplist.Insert(price, e)
			}

			success := 0
			failed := 0
			for i := 0; i < 10000; i++ {
				price := decimal.NewFromInt(int64(123))
				node, _ := skiplist.Find(price, strconv.Itoa(i+add))
				if node == nil || !node.Score().Equal(price) {
					failed++
				} else {
					success++
				}
			}

			fmt.Println("success:", success, "failed:", failed)

			for i := 9999; i >= 0; i-- {
				price := decimal.NewFromInt(int64(123))
				skiplist.Delete(price, strconv.Itoa(i+add))
			}
			if skiplist.GetSize() > 0 || skiplist.GetLevel() > 1 {
				fmt.Println("error", skiplist.GetSize(), skiplist.GetLevel())
			} else {
				fmt.Println("success")
			}
		}
	}
}

barehead123 avatar Mar 14 '24 05:03 barehead123

解决了吗

reeveshen avatar Nov 23 '24 16:11 reeveshen