Skip to content

Commit

Permalink
[pdsl_core] Implement Flush for storage::{Value, Vec, HashMap, Stash}
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Jan 23, 2019
1 parent 577e964 commit 97696ec
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pdsl_core/src/storage/cell/sync_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl<T> parity_codec::Decode for SyncCell<T> {

impl<T> Flush for SyncCell<T>
where
T: parity_codec::Codec,
T: parity_codec::Encode,
{
fn flush(&mut self) {
if self.cache.is_dirty() {
Expand Down
12 changes: 12 additions & 0 deletions pdsl_core/src/storage/collections/hash_map/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::storage::{
chunk::SyncChunk,
Setup,
Allocator,
Flush,
};
use crate::hash;

Expand Down Expand Up @@ -85,6 +86,17 @@ impl<K, V> Setup for HashMap<K, V> {
}
}

impl<K, V> Flush for HashMap<K, V>
where
K: parity_codec::Encode,
V: parity_codec::Encode,
{
fn flush(&mut self) {
self.len.flush();
self.entries.flush();
}
}

impl<K, V> parity_codec::Encode for HashMap<K, V> {
fn encode_to<W: parity_codec::Output>(&self, dest: &mut W) {
self.len.encode_to(dest);
Expand Down
13 changes: 13 additions & 0 deletions pdsl_core/src/storage/collections/stash/stash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::storage::{
Key,
chunk::SyncChunk,
Allocator,
Flush,
};

use parity_codec::{Encode, Decode};
Expand Down Expand Up @@ -74,6 +75,18 @@ impl<'a, T> Values<'a, T> {
}
}

impl<T> Flush for Stash<T>
where
T: parity_codec::Encode,
{
fn flush(&mut self) {
self.next_vacant.flush();
self.len.flush();
self.max_len.flush();
self.entries.flush();
}
}

impl<'a, T> Iterator for Values<'a, T>
where
T: parity_codec::Codec
Expand Down
11 changes: 11 additions & 0 deletions pdsl_core/src/storage/collections/vec/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
self,
chunk::SyncChunk,
Allocator,
Flush,
},
};

Expand Down Expand Up @@ -71,6 +72,16 @@ impl<'a, T> Iter<'a, T> {
}
}

impl<T> Flush for Vec<T>
where
T: parity_codec::Encode,
{
fn flush(&mut self) {
self.len.flush();
self.cells.flush();
}
}

impl<'a, T> Iterator for Iter<'a, T>
where
T: parity_codec::Codec
Expand Down
2 changes: 1 addition & 1 deletion pdsl_core/src/storage/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ where

impl<T> Flush for Value<T>
where
T: parity_codec::Codec + Unpin,
T: parity_codec::Encode + Unpin,
{
fn flush(&mut self) {
self.cell.flush()
Expand Down

0 comments on commit 97696ec

Please sign in to comment.