Commit 875ff0f5 authored by jiangpeng's avatar jiangpeng Committed by vipwzw

mempool:adapt chain33 skiplist

parent 5b1424ea
...@@ -37,6 +37,10 @@ func (item *priceScore) Compare(cmp skiplist.Scorer) int { ...@@ -37,6 +37,10 @@ func (item *priceScore) Compare(cmp skiplist.Scorer) int {
return skiplist.Small return skiplist.Small
} }
func (item *priceScore) ByteSize() int64 {
return int64(proto.Size(item.Value))
}
// NewQueue 创建队列 // NewQueue 创建队列
func NewQueue(subcfg subConfig) *Queue { func NewQueue(subcfg subConfig) *Queue {
return &Queue{ return &Queue{
......
...@@ -115,6 +115,7 @@ func TestTimeCompetition(t *testing.T) { ...@@ -115,6 +115,7 @@ func TestTimeCompetition(t *testing.T) {
cache.Push(item3) cache.Push(item3)
assert.Equal(t, false, cache.Exist(string(item1.Value.Hash()))) assert.Equal(t, false, cache.Exist(string(item1.Value.Hash())))
assert.Equal(t, true, cache.Exist(string(item3.Value.Hash()))) assert.Equal(t, true, cache.Exist(string(item3.Value.Hash())))
assert.Equal(t, int64(item3.Value.Size()), cache.GetCacheBytes())
} }
func TestPriceCompetition(t *testing.T) { func TestPriceCompetition(t *testing.T) {
...@@ -123,6 +124,7 @@ func TestPriceCompetition(t *testing.T) { ...@@ -123,6 +124,7 @@ func TestPriceCompetition(t *testing.T) {
cache.Push(item4) cache.Push(item4)
assert.Equal(t, false, cache.Exist(string(item3.Value.Hash()))) assert.Equal(t, false, cache.Exist(string(item3.Value.Hash())))
assert.Equal(t, true, cache.Exist(string(item4.Value.Hash()))) assert.Equal(t, true, cache.Exist(string(item4.Value.Hash())))
assert.Equal(t, int64(item4.Value.Size()), cache.GetCacheBytes())
} }
func TestAddDuplicateItem(t *testing.T) { func TestAddDuplicateItem(t *testing.T) {
......
...@@ -42,6 +42,10 @@ func (item *scoreScore) Compare(cmp skiplist.Scorer) int { ...@@ -42,6 +42,10 @@ func (item *scoreScore) Compare(cmp skiplist.Scorer) int {
return skiplist.Small return skiplist.Small
} }
func (item *scoreScore) ByteSize() int64 {
return int64(proto.Size(item.Value))
}
// NewQueue 创建队列 // NewQueue 创建队列
func NewQueue(subcfg subConfig) *Queue { func NewQueue(subcfg subConfig) *Queue {
return &Queue{ return &Queue{
......
...@@ -116,6 +116,7 @@ func TestTimeCompetition(t *testing.T) { ...@@ -116,6 +116,7 @@ func TestTimeCompetition(t *testing.T) {
cache.Push(item3) cache.Push(item3)
assert.Equal(t, false, cache.Exist(string(item1.Value.Hash()))) assert.Equal(t, false, cache.Exist(string(item1.Value.Hash())))
assert.Equal(t, true, cache.Exist(string(item3.Value.Hash()))) assert.Equal(t, true, cache.Exist(string(item3.Value.Hash())))
assert.Equal(t, int64(item3.Value.Size()), cache.GetCacheBytes())
} }
func TestPriceCompetition(t *testing.T) { func TestPriceCompetition(t *testing.T) {
...@@ -124,6 +125,7 @@ func TestPriceCompetition(t *testing.T) { ...@@ -124,6 +125,7 @@ func TestPriceCompetition(t *testing.T) {
cache.Push(item4) cache.Push(item4)
assert.Equal(t, false, cache.Exist(string(item3.Value.Hash()))) assert.Equal(t, false, cache.Exist(string(item3.Value.Hash())))
assert.Equal(t, true, cache.Exist(string(item4.Value.Hash()))) assert.Equal(t, true, cache.Exist(string(item4.Value.Hash())))
assert.Equal(t, int64(item4.Value.Size()), cache.GetCacheBytes())
} }
func TestAddDuplicateItem(t *testing.T) { func TestAddDuplicateItem(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment