Skip to content

Commit

Permalink
Merge pull request #100 from bltavares/bumps
Browse files Browse the repository at this point in the history
Bump to random-access-storage 3.0.0 and other deps
  • Loading branch information
bltavares authored Mar 3, 2020
2 parents a3aa858 + 51c35d8 commit f7af79a
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 205 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ cache: cargo
rust: stable

before_script:
- rustup component add rustfmt-preview
- rustup component add clippy-preview
- rustup component add rustfmt
- rustup component add clippy
- cargo fmt --version
- cargo clippy --version
- rustup update nightly

script:
- cargo fmt -- --check
- cargo +nightly check --all-targets
- cargo build --verbose
- cargo test --verbose
- cargo clippy
- cargo clippy -- -D clippy::all
30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ edition = "2018"

[dependencies]
blake2-rfc = "0.2.18"
byteorder = "1.3.2"
ed25519-dalek = "0.9.1"
failure = "0.1.5"
flat-tree = "4.1.0"
lazy_static = "1.3.0"
byteorder = "1.3.4"
ed25519-dalek = "1.0.0-pre.3"
failure = "0.1.6"
flat-tree = "5.0.0"
lazy_static = "1.4.0"
memory-pager = "0.9.0"
merkle-tree-stream = "0.11.0"
pretty-hash = "0.4.0"
rand = "0.6.0"
random-access-disk = "0.8.0"
random-access-memory = "1.0.0"
random-access-storage = "2.0.0"
sha2 = "0.8.0"
merkle-tree-stream = "0.12.0"
pretty-hash = "0.4.1"
rand = "0.7.3"
random-access-disk = "1.0.0"
random-access-memory = "1.1.0"
random-access-storage = "3.0.0"
sha2 = "0.8.1"
sleep-parser = "0.8.0"
sparse-bitfield = "0.11.0"
tree-index = "0.5.0"
tree-index = "0.6.0"

[dev-dependencies]
quickcheck = "0.8.5"
data-encoding = "2.1.2"
quickcheck = "0.9.2"
data-encoding = "2.2.0"
remove_dir_all = "0.5.2"
tempfile = "3.1.0"
async-std = "1.5.0"
6 changes: 3 additions & 3 deletions examples/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct BookShelf {
#[derive(Debug)]
struct BookShelfIterator<'b> {
/// Keeps track which index we're currently at.
pub cursor: usize,
pub cursor: u64,
/// Borrow of the Bookshelf we're going to iterate over.
pub inner: &'b BookShelf,
}
Expand All @@ -35,10 +35,10 @@ impl<'b> iter::Iterator for BookShelfIterator<'b> {
let cursor = self.cursor;
self.cursor += 1;

if cursor >= self.inner.books.len() {
if cursor >= self.inner.books.len() as u64 {
None
} else {
Some(&self.inner.books[cursor])
Some(&self.inner.books[cursor as usize])
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
#[derive(Debug, PartialEq, Clone)]
pub struct Audit {
/// The number of valid blocks identified
pub valid_blocks: usize,
pub valid_blocks: u64,
/// The number of invalid blocks identified
pub invalid_blocks: usize,
pub invalid_blocks: u64,
}

impl Audit {
/// Access the `valid_blocks` field from the proof.
pub fn valid_blocks(&self) -> usize {
pub fn valid_blocks(&self) -> u64 {
self.valid_blocks
}

/// Access the `invalid_blocks` field from the proof.
pub fn invalid_blocks(&self) -> usize {
pub fn invalid_blocks(&self) -> u64 {
self.invalid_blocks
}
}
37 changes: 19 additions & 18 deletions src/bitfield/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use super::Bitfield;
/// Iterate over a bitfield.
#[derive(Debug)]
pub struct Iterator<'a> {
start: usize,
end: usize,
index_end: usize,
pos: Option<usize>,
start: u64,
end: u64,
index_end: u64,
pos: Option<u64>,
byte: u8,
bitfield: &'a mut Bitfield,
}
Expand All @@ -27,7 +27,7 @@ impl<'a> Iterator<'a> {
}

/// Grow the bitfield if needed.
pub fn range(&mut self, start: usize, end: usize) {
pub fn range(&mut self, start: u64, end: u64) {
self.start = start;
self.end = end;
self.index_end = 2 * ((end + 31) / 32);
Expand All @@ -38,7 +38,7 @@ impl<'a> Iterator<'a> {
}

/// Seek to `offset`
pub fn seek(&mut self, mut offset: usize) -> &mut Self {
pub fn seek(&mut self, mut offset: u64) -> &mut Self {
offset += self.start;
// FIXME This is fishy. Offset and start is unsigned, so `offset < self.start` can only
// be true when the previous addition overflows. The overflow would cause a panic, so,
Expand All @@ -58,50 +58,51 @@ impl<'a> Iterator<'a> {
let pos = offset / 8;
self.pos = Some(pos);

self.byte = self.bitfield.data.get_byte(pos) | self.bitfield.masks.data_iterate[o];
self.byte = self.bitfield.data.get_byte(pos as usize)
| self.bitfield.masks.data_iterate[o as usize];

self
}

pub fn next(&mut self) -> Option<usize> {
pub fn next(&mut self) -> Option<u64> {
let mut pos = self.pos?;

let mut free = self.bitfield.masks.next_data_0_bit[self.byte as usize];

while free == -1 {
pos += 1;
self.byte = self.bitfield.data.get_byte(pos);
self.byte = self.bitfield.data.get_byte(pos as usize);
free = self.bitfield.masks.next_data_0_bit[self.byte as usize];

if free == -1 {
pos = self.skip_ahead(pos)?;

self.byte = self.bitfield.data.get_byte(pos);
self.byte = self.bitfield.data.get_byte(pos as usize);
free = self.bitfield.masks.next_data_0_bit[self.byte as usize];
}
}
self.pos = Some(pos);

self.byte |= self.bitfield.masks.data_iterate[free as usize + 1];

let n = 8 * pos + free as usize;
let n = 8 * pos + free as u64;
if n < self.end {
Some(n)
} else {
None
}
}

pub fn skip_ahead(&mut self, start: usize) -> Option<usize> {
pub fn skip_ahead(&mut self, start: u64) -> Option<u64> {
let bitfield_index = &self.bitfield.index;
let tree_end = self.index_end;
let iter = &mut self.bitfield.iterator;
let o = start & 3;

iter.seek(2 * (start / 4));

let mut tree_byte =
bitfield_index.get_byte(iter.index()) | self.bitfield.masks.index_iterate[o];
let mut tree_byte = bitfield_index.get_byte(iter.index() as usize)
| self.bitfield.masks.index_iterate[o as usize];

while self.bitfield.masks.next_index_0_bit[tree_byte as usize] == -1 {
if iter.is_left() {
Expand All @@ -120,7 +121,7 @@ impl<'a> Iterator<'a> {
}
}

tree_byte = bitfield_index.get_byte(iter.index());
tree_byte = bitfield_index.get_byte(iter.index() as usize);
}

while iter.factor() > 2 {
Expand All @@ -130,15 +131,15 @@ impl<'a> Iterator<'a> {
iter.right_child();
}

tree_byte = bitfield_index.get_byte(iter.index());
tree_byte = bitfield_index.get_byte(iter.index() as usize);
}

let mut free = self.bitfield.masks.next_index_0_bit[tree_byte as usize];
if free == -1 {
free = 4;
}

let next = iter.index() * 2 + free as usize;
let next = iter.index() * 2 + free as u64;

if next <= start {
Some(start + 1)
Expand All @@ -148,7 +149,7 @@ impl<'a> Iterator<'a> {
}
}

fn right_span(iter: &flat_tree::Iterator) -> usize {
fn right_span(iter: &flat_tree::Iterator) -> u64 {
iter.index() + iter.factor() / 2 - 1
}

Expand Down
Loading

0 comments on commit f7af79a

Please sign in to comment.