Skip to content

Commit

Permalink
Merge branch 'refresh-2020'
Browse files Browse the repository at this point in the history
  • Loading branch information
pearfalse committed Sep 22, 2020
2 parents 32cb91c + 54ffea6 commit 21bd7eb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "bitterlemon"
version = "0.2.2"
edition = "2018"
version = "0.2.3"
authors = ["Simon Harris <simon@pearfalse.com>"]
description = "An RLE-based encoder and decoder for bit streams."
license = "MIT"
Expand Down
15 changes: 7 additions & 8 deletions src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Run {
}
}

fn size_mut<'a>(&'a mut self) -> &'a mut u8 {
fn size_mut(&mut self) -> &mut u8 {
match *self {
Run::Set(ref mut x) => x,
Run::Clear(ref mut x) => x,
Expand Down Expand Up @@ -143,7 +143,7 @@ impl<S: Iterator<Item=bool>> RunIterator<S> {
fn from_bits(source: S) -> RunIterator<S> {
RunIterator {
state: None,
source: source
source,
}
}
}
Expand Down Expand Up @@ -304,7 +304,7 @@ impl RunHoldingExtensions for RunHolding {
}

fn unshift_bit(&mut self, ptr: &mut u8) -> u8 {
let mut head_run = self.get_mut(*ptr as usize).unwrap();
let head_run = self.get_mut(*ptr as usize).unwrap();
let r = head_run.bit();

let head_size = head_run.size_mut();
Expand Down Expand Up @@ -379,16 +379,15 @@ impl<S: Iterator<Item=Run>> WithFrames<S> {
WithFrames {
runs: RunHolding::new(),
mode: WithFramesMode::Filling,
source: source,
source,
next_run: None,
}
}

fn next_should_expand_frame(&mut self) -> bool {
// never expand a frame we're flushing
match self.mode {
WithFramesMode::FlushingFrame(_, _) => { return false; },
_ => {}
if matches!(self.mode, WithFramesMode::FlushingFrame(_, _)) {
return false;
}

let run_size = self.next_run.unwrap().size();
Expand Down Expand Up @@ -432,7 +431,7 @@ impl<S: Iterator<Item=Run>> WithFrames<S> {
Some(WithFramesMode::FlushingFrame(0, frame_size))
)
}
else if let Some(_) = self.next_run {
else if self.next_run.is_some() {
// expecting to fill a frame, but was told not to do it here
// move the run out instead
let moved_run = self.next_run.take().unwrap();
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
//! // With standard bit packing, this takes 17 bytes
//! let tmp = &[true, false];
//! let input = iter::repeat(true).take(50)
//! .chain(iter::repeat(false).take(51))
//! .chain(tmp.iter().cloned().cycle().take(33));
//! .chain(iter::repeat(false).take(51))
//! .chain(tmp.iter().cloned().cycle().take(33));
//!
//! let output : Vec<_> = bitterlemon::encode(input).collect();
//! // Bitterlemon gets this down to 8 bytes
//! assert_eq!(b"\xf2\xb3\x21\xaa\xaa\xaa\xaa\x80", output.as_slice());
//!
//! let decoded : Result<Vec<_>, _>
//! = bitterlemon::decode(output.iter().map(|&b| b)).collect();
//! let decoded : Result<Vec<_>, _> = bitterlemon::decode(output.iter().map(|&b| b)).collect();
//! assert!(decoded.is_ok());
//! let decoded = decoded.unwrap();
//! assert_eq!(134, decoded.len());
Expand Down
12 changes: 6 additions & 6 deletions src/test_encode_round_trip.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Encodes a boolean stream, then decodes it, checking that the output matches the input

extern crate arrayvec;
extern crate random;
use arrayvec;
use random::Source;

use test_encode_round_trip::random::Source;

use encode;
use decode;
use crate::{
encode,
decode,
};

fn from_digits(s: &'static [u8]) -> Vec<bool> {
s.iter().map(|&c| c == b'1').collect()
Expand Down

0 comments on commit 21bd7eb

Please sign in to comment.