Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
6e73f767
Commit
6e73f767
authored
Dec 14, 2018
by
vipwzw
Committed by
33cn
Dec 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update chain33
parent
f7cf6dfe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
353 additions
and
2 deletions
+353
-2
create_plugin_file_template.go
...chain33/cmd/tools/strategy/create_plugin_file_template.go
+2
-2
skiplist.go
vendor/github.com/33cn/chain33/common/skiplist/skiplist.go
+272
-0
skiplist_test.go
.../github.com/33cn/chain33/common/skiplist/skiplist_test.go
+79
-0
No files found.
vendor/github.com/33cn/chain33/cmd/tools/strategy/create_plugin_file_template.go
View file @
6e73f767
...
@@ -15,8 +15,8 @@ import (
...
@@ -15,8 +15,8 @@ import (
_ "github.com/33cn/chain33/system"
_ "github.com/33cn/chain33/system"
_ "${PROJECTPATH}/plugin"
_ "${PROJECTPATH}/plugin"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/cli"
"github.com/33cn/chain33/util/cli"
)
)
func main() {
func main() {
...
...
vendor/github.com/33cn/chain33/common/skiplist/skiplist.go
0 → 100644
View file @
6e73f767
package
skiplist
import
(
"fmt"
"math/rand"
)
const
maxLevel
=
32
const
prob
=
0.35
// SkipValue 跳跃表节点的Value值
type
SkipValue
struct
{
Score
int64
Value
interface
{}
}
// Compare 比较函数,这样的比较排序是从大到小
func
(
v
*
SkipValue
)
Compare
(
value
*
SkipValue
)
int
{
if
v
.
Score
>
value
.
Score
{
return
-
1
}
else
if
v
.
Score
==
value
.
Score
{
return
0
}
return
1
}
// skipListNode 跳跃表节点
type
skipListNode
struct
{
next
[]
*
skipListNode
prev
*
skipListNode
Value
*
SkipValue
}
// SkipList 跳跃表
type
SkipList
struct
{
header
,
tail
*
skipListNode
findcount
int
count
int
level
int
}
// Iterator 跳跃表迭代器
type
Iterator
struct
{
list
*
SkipList
node
*
skipListNode
}
// First 获取第一个节点Value值
func
(
sli
*
Iterator
)
First
()
*
SkipValue
{
if
sli
.
list
.
header
.
next
[
0
]
==
nil
{
return
nil
}
sli
.
node
=
sli
.
list
.
header
.
next
[
0
]
return
sli
.
node
.
Value
}
// Last 获取最后一个节点Value值
func
(
sli
*
Iterator
)
Last
()
*
SkipValue
{
if
sli
.
list
.
tail
==
nil
{
return
nil
}
sli
.
node
=
sli
.
list
.
tail
return
sli
.
node
.
Value
}
// Prev 获取上一个节点
func
(
node
*
skipListNode
)
Prev
()
*
skipListNode
{
if
node
==
nil
||
node
.
prev
==
nil
{
return
nil
}
return
node
.
prev
}
// Next 获取下一个节点
func
(
node
*
skipListNode
)
Next
()
*
skipListNode
{
if
node
==
nil
||
node
.
next
[
0
]
==
nil
{
return
nil
}
return
node
.
next
[
0
]
}
// Seek 迭代器在跳跃表中查找某个位置在传参后面或者与传参相等的SkipValue
func
(
sli
*
Iterator
)
Seek
(
value
*
SkipValue
)
*
SkipValue
{
x
:=
sli
.
list
.
find
(
value
)
if
x
.
next
[
0
]
==
nil
{
return
nil
}
sli
.
node
=
x
.
next
[
0
]
return
sli
.
node
.
Value
}
func
newskipListNode
(
level
int
,
value
*
SkipValue
)
*
skipListNode
{
node
:=
&
skipListNode
{}
node
.
next
=
make
([]
*
skipListNode
,
level
)
node
.
Value
=
value
return
node
}
//NewSkipList 构建一个跳跃表
func
NewSkipList
(
min
*
SkipValue
)
*
SkipList
{
sl
:=
&
SkipList
{}
sl
.
level
=
1
sl
.
header
=
newskipListNode
(
maxLevel
,
min
)
return
sl
}
func
randomLevel
()
int
{
level
:=
1
t
:=
prob
*
0xFFFF
for
rand
.
Int
()
&
0xFFFF
<
int
(
t
)
{
level
++
if
level
==
maxLevel
{
break
}
}
return
level
}
// GetIterator 获取迭代器
func
(
sl
*
SkipList
)
GetIterator
()
*
Iterator
{
it
:=
&
Iterator
{}
it
.
list
=
sl
it
.
First
()
return
it
}
// Len 返回节点数
func
(
sl
*
SkipList
)
Len
()
int
{
return
sl
.
count
}
// Level 返回跳跃表的层级
func
(
sl
*
SkipList
)
Level
()
int
{
return
sl
.
level
}
func
(
sl
*
SkipList
)
find
(
value
*
SkipValue
)
*
skipListNode
{
x
:=
sl
.
header
for
i
:=
sl
.
level
-
1
;
i
>=
0
;
i
--
{
for
x
.
next
[
i
]
!=
nil
&&
x
.
next
[
i
]
.
Value
.
Compare
(
value
)
<
0
{
sl
.
findcount
++
x
=
x
.
next
[
i
]
}
}
return
x
}
// FindCount 返回查询次数
func
(
sl
*
SkipList
)
FindCount
()
int
{
return
sl
.
findcount
}
// Find 查找某个跳跃表中的SkipValue
func
(
sl
*
SkipList
)
Find
(
value
*
SkipValue
)
*
SkipValue
{
x
:=
sl
.
find
(
value
)
if
x
.
next
[
0
]
!=
nil
&&
x
.
next
[
0
]
.
Value
.
Compare
(
value
)
==
0
{
return
x
.
next
[
0
]
.
Value
}
return
nil
}
// FindGreaterOrEqual 在跳跃表中查找某个位置在传参后面或者与传参相等的SkipValue
func
(
sl
*
SkipList
)
FindGreaterOrEqual
(
value
*
SkipValue
)
*
SkipValue
{
x
:=
sl
.
find
(
value
)
if
x
.
next
[
0
]
!=
nil
{
return
x
.
next
[
0
]
.
Value
}
return
nil
}
// Insert 插入节点
func
(
sl
*
SkipList
)
Insert
(
value
*
SkipValue
)
int
{
var
update
[
maxLevel
]
*
skipListNode
x
:=
sl
.
header
for
i
:=
sl
.
level
-
1
;
i
>=
0
;
i
--
{
for
x
.
next
[
i
]
!=
nil
&&
x
.
next
[
i
]
.
Value
.
Compare
(
value
)
<=
0
{
x
=
x
.
next
[
i
]
}
update
[
i
]
=
x
}
//if x.next[0] != nil && x.next[0].Value.Compare(value) == 0 { //update
// x.next[0].Value = value
// return 0
//}
level
:=
randomLevel
()
if
level
>
sl
.
level
{
for
i
:=
sl
.
level
;
i
<
level
;
i
++
{
update
[
i
]
=
sl
.
header
}
sl
.
level
=
level
}
x
=
newskipListNode
(
level
,
value
)
for
i
:=
0
;
i
<
level
;
i
++
{
x
.
next
[
i
]
=
update
[
i
]
.
next
[
i
]
update
[
i
]
.
next
[
i
]
=
x
}
//形成一个双向链表
if
update
[
0
]
!=
sl
.
header
{
x
.
prev
=
update
[
0
]
}
if
x
.
next
[
0
]
!=
nil
{
x
.
next
[
0
]
.
prev
=
x
}
else
{
sl
.
tail
=
x
}
sl
.
count
++
return
1
}
// Delete 删除节点
func
(
sl
*
SkipList
)
Delete
(
value
*
SkipValue
)
int
{
var
update
[
maxLevel
]
*
skipListNode
x
:=
sl
.
header
for
i
:=
sl
.
level
-
1
;
i
>=
0
;
i
--
{
for
x
.
next
[
i
]
!=
nil
&&
x
.
next
[
i
]
.
Value
.
Compare
(
value
)
<
0
{
x
=
x
.
next
[
i
]
}
update
[
i
]
=
x
}
if
x
.
next
[
0
]
==
nil
||
x
.
next
[
0
]
.
Value
.
Compare
(
value
)
!=
0
{
//not find
return
0
}
x
=
x
.
next
[
0
]
for
i
:=
0
;
i
<
sl
.
level
;
i
++
{
if
update
[
i
]
.
next
[
i
]
==
x
{
update
[
i
]
.
next
[
i
]
=
x
.
next
[
i
]
}
}
if
x
.
next
[
0
]
!=
nil
{
x
.
next
[
0
]
.
prev
=
x
.
prev
}
else
{
sl
.
tail
=
x
.
prev
}
for
sl
.
level
>
1
&&
sl
.
header
.
next
[
sl
.
level
-
1
]
==
nil
{
sl
.
level
--
}
sl
.
count
--
return
1
}
// Print 测试用的输出函数
func
(
sl
*
SkipList
)
Print
()
{
if
sl
.
count
>
0
{
r
:=
sl
.
header
for
i
:=
sl
.
level
-
1
;
i
>=
0
;
i
--
{
e
:=
r
.
next
[
i
]
//fmt.Print(i)
for
e
!=
nil
{
fmt
.
Print
(
e
.
Value
.
Score
)
fmt
.
Print
(
" "
)
fmt
.
Print
(
e
.
Value
)
fmt
.
Println
(
""
)
e
=
e
.
next
[
i
]
}
fmt
.
Println
()
}
}
else
{
fmt
.
Println
(
"空"
)
}
}
//Walk 遍历整个结构,如果cb 返回false 那么停止遍历
func
(
sl
*
SkipList
)
Walk
(
cb
func
(
value
interface
{})
bool
)
{
for
e
:=
sl
.
header
.
Next
();
e
!=
nil
;
e
=
e
.
Next
()
{
if
cb
==
nil
{
return
}
if
!
cb
(
e
.
Value
.
Value
)
{
return
}
}
}
vendor/github.com/33cn/chain33/common/skiplist/skiplist_test.go
0 → 100644
View file @
6e73f767
package
skiplist
import
(
"testing"
"github.com/stretchr/testify/assert"
)
var
(
s1
=
&
SkipValue
{
1
,
"111"
}
s2
=
&
SkipValue
{
2
,
"222"
}
s3
=
&
SkipValue
{
3
,
"333"
}
)
func
TestInsert
(
t
*
testing
.
T
)
{
l
:=
NewSkipList
(
nil
)
l
.
Insert
(
s1
)
assert
.
Equal
(
t
,
1
,
l
.
Len
())
l
.
Insert
(
s2
)
assert
.
Equal
(
t
,
2
,
l
.
Len
())
iter
:=
l
.
GetIterator
()
assert
.
Equal
(
t
,
int64
(
2
),
iter
.
First
()
.
Score
)
assert
.
Equal
(
t
,
"222"
,
iter
.
First
()
.
Value
.
(
string
))
assert
.
Equal
(
t
,
int64
(
1
),
iter
.
Last
()
.
Score
)
assert
.
Equal
(
t
,
"111"
,
iter
.
Last
()
.
Value
.
(
string
))
}
func
TestFind
(
t
*
testing
.
T
)
{
l
:=
NewSkipList
(
nil
)
l
.
Insert
(
s1
)
assert
.
Equal
(
t
,
s1
,
l
.
Find
(
s1
))
l
.
Insert
(
s2
)
assert
.
Equal
(
t
,
s2
,
l
.
Find
(
s2
))
l
.
Insert
(
s3
)
assert
.
Equal
(
t
,
s3
,
l
.
Find
(
s3
))
}
func
TestDelete
(
t
*
testing
.
T
)
{
l
:=
NewSkipList
(
nil
)
l
.
Insert
(
s1
)
l
.
Insert
(
s2
)
l
.
Delete
(
s1
)
assert
.
Equal
(
t
,
1
,
l
.
Len
())
assert
.
Equal
(
t
,
(
*
SkipValue
)(
nil
),
l
.
Find
(
s1
))
assert
.
Equal
(
t
,
s2
,
l
.
Find
(
s2
))
}
func
TestWalk
(
t
*
testing
.
T
)
{
l
:=
NewSkipList
(
nil
)
l
.
Insert
(
s1
)
l
.
Insert
(
s2
)
var
data
[
2
]
string
i
:=
0
l
.
Walk
(
func
(
value
interface
{})
bool
{
data
[
i
]
=
value
.
(
string
)
i
++
return
true
})
assert
.
Equal
(
t
,
data
[
0
],
"222"
)
assert
.
Equal
(
t
,
data
[
1
],
"111"
)
var
data2
[
2
]
string
i
=
0
l
.
Walk
(
func
(
value
interface
{})
bool
{
data2
[
i
]
=
value
.
(
string
)
i
++
return
false
})
assert
.
Equal
(
t
,
data2
[
0
],
"222"
)
assert
.
Equal
(
t
,
data2
[
1
],
""
)
l
.
Walk
(
nil
)
iter
:=
l
.
GetIterator
()
assert
.
Equal
(
t
,
int64
(
2
),
iter
.
First
()
.
Score
)
assert
.
Equal
(
t
,
"222"
,
iter
.
First
()
.
Value
.
(
string
))
assert
.
Equal
(
t
,
int64
(
1
),
iter
.
Last
()
.
Score
)
assert
.
Equal
(
t
,
"111"
,
iter
.
Last
()
.
Value
.
(
string
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment