Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
张蕾
Geth-Modification
Commits
34d62c38
Commit
34d62c38
authored
Jan 01, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Encoding helpers for trie
parent
276fa6c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
12 deletions
+16
-12
encoding.go
encoding.go
+16
-0
encoding_test.go
encoding_test.go
+0
-12
No files found.
encoding.go
View file @
34d62c38
...
...
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/hex"
"strings"
_
"fmt"
)
func
CompactEncode
(
hexSlice
[]
int
)
string
{
...
...
@@ -32,6 +33,21 @@ func CompactEncode(hexSlice []int) string {
return
buff
.
String
()
}
func
CompactDecode
(
str
string
)
[]
int
{
base
:=
CompactHexDecode
(
str
)
base
=
base
[
:
len
(
base
)
-
1
]
if
base
[
0
]
>=
2
{
// && base[len(base)-1] != 16 {
base
=
append
(
base
,
16
)
}
if
base
[
0
]
%
2
==
1
{
base
=
base
[
1
:
]
}
else
{
base
=
base
[
2
:
]
}
return
base
}
func
CompactHexDecode
(
str
string
)
[]
int
{
base
:=
"0123456789abcdef"
hexSlice
:=
make
([]
int
,
0
)
...
...
encoding_test.go
View file @
34d62c38
...
...
@@ -27,18 +27,6 @@ func TestCompactEncode(t *testing.T) {
}
}
// Helper function for comparing slices
func
CompareIntSlice
(
a
,
b
[]
int
)
bool
{
if
len
(
a
)
!=
len
(
b
)
{
return
false
}
for
i
,
v
:=
range
a
{
if
v
!=
b
[
i
]
{
return
false
}
}
return
true
}
func
TestCompactHexDecode
(
t
*
testing
.
T
)
{
exp
:=
[]
int
{
7
,
6
,
6
,
5
,
7
,
2
,
6
,
2
,
16
}
...
...
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