Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
parity-test-sync
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
parity-test-sync
Commits
dc4f3fe4
Commit
dc4f3fe4
authored
9 years ago
by
Marek Kotewicz
Browse files
Options
Downloads
Plain Diff
Merge pull request #15 from gavofyork/ddtrie
Trie takes a reference to HashDB.
parents
6bc56ad0
d94c5513
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/trie.rs
+12
-12
12 additions, 12 deletions
src/trie.rs
with
12 additions
and
12 deletions
src/trie.rs
+
12
−
12
View file @
dc4f3fe4
...
@@ -299,8 +299,8 @@ impl <'a>Node<'a> {
...
@@ -299,8 +299,8 @@ impl <'a>Node<'a> {
/// assert!(t.db_items_remaining().is_empty());
/// assert!(t.db_items_remaining().is_empty());
/// }
/// }
/// ```
/// ```
pub
struct
TrieDB
<
'db
,
T
>
where
T
:
'db
+
HashDB
{
pub
struct
TrieDB
<
'db
>
{
db
:
&
'db
mut
T
,
db
:
&
'db
mut
HashDB
,
root
:
&
'db
mut
H256
,
root
:
&
'db
mut
H256
,
pub
hash_count
:
usize
,
pub
hash_count
:
usize
,
}
}
...
@@ -311,12 +311,12 @@ enum MaybeChanged<'a> {
...
@@ -311,12 +311,12 @@ enum MaybeChanged<'a> {
Changed
(
Bytes
),
Changed
(
Bytes
),
}
}
impl
<
'db
,
T
>
TrieDB
<
'db
,
T
>
where
T
:
'db
+
HashDB
{
impl
<
'db
>
TrieDB
<
'db
>
{
/// Create a new trie with the backing database `db` and empty `root`
/// Create a new trie with the backing database `db` and empty `root`
/// Initialise to the state entailed by the genesis block.
/// Initialise to the state entailed by the genesis block.
/// This guarantees the trie is built correctly.
/// This guarantees the trie is built correctly.
pub
fn
new
(
db
:
&
'db
mut
T
,
root
:
&
'db
mut
H256
)
->
Self
{
pub
fn
new
(
db
:
&
'db
mut
HashDB
,
root
:
&
'db
mut
H256
)
->
Self
{
let
mut
r
=
TrieDB
{
let
mut
r
=
TrieDB
{
db
:
db
,
db
:
db
,
root
:
root
,
root
:
root
,
hash_count
:
0
hash_count
:
0
...
@@ -329,7 +329,7 @@ impl<'db, T> TrieDB<'db, T> where T: 'db + HashDB {
...
@@ -329,7 +329,7 @@ impl<'db, T> TrieDB<'db, T> where T: 'db + HashDB {
/// Create a new trie with the backing database `db` and `root`
/// Create a new trie with the backing database `db` and `root`
/// Panics, if `root` does not exist
/// Panics, if `root` does not exist
pub
fn
new_existing
(
db
:
&
'db
mut
T
,
root
:
&
'db
mut
H256
)
->
Self
{
pub
fn
new_existing
(
db
:
&
'db
mut
HashDB
,
root
:
&
'db
mut
H256
)
->
Self
{
assert!
(
db
.exists
(
root
));
assert!
(
db
.exists
(
root
));
TrieDB
{
TrieDB
{
db
:
db
,
db
:
db
,
...
@@ -339,7 +339,7 @@ impl<'db, T> TrieDB<'db, T> where T: 'db + HashDB {
...
@@ -339,7 +339,7 @@ impl<'db, T> TrieDB<'db, T> where T: 'db + HashDB {
}
}
/// Get the backing database.
/// Get the backing database.
pub
fn
db
(
&
'db
self
)
->
&
'db
T
{
pub
fn
db
(
&
'db
self
)
->
&
'db
HashDB
{
self
.db
self
.db
}
}
...
@@ -364,7 +364,7 @@ impl<'db, T> TrieDB<'db, T> where T: 'db + HashDB {
...
@@ -364,7 +364,7 @@ impl<'db, T> TrieDB<'db, T> where T: 'db + HashDB {
/// Determine occurances of items in the backing database which are not related to this
/// Determine occurances of items in the backing database which are not related to this
/// trie.
/// trie.
pub
fn
db_items_remaining
(
&
self
)
->
HashMap
<
H256
,
i32
>
{
pub
fn
db_items_remaining
(
&
self
)
->
HashMap
<
H256
,
i32
>
{
let
mut
ret
=
self
.db
()
.keys
();
let
mut
ret
=
self
.db
.keys
();
for
(
k
,
v
)
in
Self
::
to_map
(
self
.keys
())
.into_iter
()
{
for
(
k
,
v
)
in
Self
::
to_map
(
self
.keys
())
.into_iter
()
{
let
keycount
=
*
ret
.get
(
&
k
)
.unwrap_or
(
&
0
);
let
keycount
=
*
ret
.get
(
&
k
)
.unwrap_or
(
&
0
);
match
keycount
==
v
as
i32
{
match
keycount
==
v
as
i32
{
...
@@ -892,7 +892,7 @@ impl<'db, T> TrieDB<'db, T> where T: 'db + HashDB {
...
@@ -892,7 +892,7 @@ impl<'db, T> TrieDB<'db, T> where T: 'db + HashDB {
}
}
}
}
impl
<
'db
,
T
>
Trie
for
TrieDB
<
'db
,
T
>
where
T
:
'db
+
HashDB
{
impl
<
'db
>
Trie
for
TrieDB
<
'db
>
{
fn
root
(
&
self
)
->
&
H256
{
&
self
.root
}
fn
root
(
&
self
)
->
&
H256
{
&
self
.root
}
fn
contains
(
&
self
,
key
:
&
[
u8
])
->
bool
{
fn
contains
(
&
self
,
key
:
&
[
u8
])
->
bool
{
...
@@ -915,7 +915,7 @@ impl<'db, T> Trie for TrieDB<'db, T> where T: 'db + HashDB {
...
@@ -915,7 +915,7 @@ impl<'db, T> Trie for TrieDB<'db, T> where T: 'db + HashDB {
}
}
}
}
impl
<
'db
,
T
>
fmt
::
Debug
for
TrieDB
<
'db
,
T
>
where
T
:
'db
+
HashDB
{
impl
<
'db
>
fmt
::
Debug
for
TrieDB
<
'db
>
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
try
!
(
writeln!
(
f
,
"c={:?} ["
,
self
.hash_count
));
try
!
(
writeln!
(
f
,
"c={:?} ["
,
self
.hash_count
));
let
root_rlp
=
self
.db
.lookup
(
&
self
.root
)
.expect
(
"Trie root not found!"
);
let
root_rlp
=
self
.db
.lookup
(
&
self
.root
)
.expect
(
"Trie root not found!"
);
...
@@ -960,7 +960,7 @@ mod tests {
...
@@ -960,7 +960,7 @@ mod tests {
}
}
}
}
fn
populate_trie
<
'db
,
T
>
(
db
:
&
'db
mut
T
,
root
:
&
'db
mut
H256
,
v
:
&
Vec
<
(
Vec
<
u8
>
,
Vec
<
u8
>
)
>
)
->
TrieDB
<
'db
,
T
>
where
T
:
'db
+
HashDB
{
fn
populate_trie
<
'db
>
(
db
:
&
'db
mut
HashDB
,
root
:
&
'db
mut
H256
,
v
:
&
Vec
<
(
Vec
<
u8
>
,
Vec
<
u8
>
)
>
)
->
TrieDB
<
'db
>
{
let
mut
t
=
TrieDB
::
new
(
db
,
root
);
let
mut
t
=
TrieDB
::
new
(
db
,
root
);
for
i
in
0
..
v
.len
()
{
for
i
in
0
..
v
.len
()
{
let
key
:
&
[
u8
]
=
&
v
[
i
]
.0
;
let
key
:
&
[
u8
]
=
&
v
[
i
]
.0
;
...
@@ -970,7 +970,7 @@ mod tests {
...
@@ -970,7 +970,7 @@ mod tests {
t
t
}
}
fn
unpopulate_trie
<
'a
,
'db
,
T
>
(
t
:
&
mut
TrieDB
<
'db
,
T
>
,
v
:
&
Vec
<
(
Vec
<
u8
>
,
Vec
<
u8
>
)
>
)
where
T
:
'db
+
HashDB
{
fn
unpopulate_trie
<
'a
,
'db
>
(
t
:
&
mut
TrieDB
<
'db
>
,
v
:
&
Vec
<
(
Vec
<
u8
>
,
Vec
<
u8
>
)
>
)
{
for
i
in
v
.iter
()
{
for
i
in
v
.iter
()
{
let
key
:
&
[
u8
]
=
&
i
.0
;
let
key
:
&
[
u8
]
=
&
i
.0
;
t
.remove
(
&
key
);
t
.remove
(
&
key
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment