Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
barehead123 opened this issue Mar 14, 2024 · 1 comment
Open

Comments

@barehead123
Copy link

barehead123 commented Mar 14, 2024

下面是测试代码


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 barehead123 changed the title Bug , 跳表处理 价格相同,id 不通的情况有问题 Bug , 跳表处理 价格相同,id 不同的情况有问题 Mar 14, 2024
@reeveshen
Copy link

解决了吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants