This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2019 Martin Mroz | |
* | |
* This software may be modified and distributed under the terms | |
* of the MIT license. See the LICENSE file for details. | |
*/ | |
#import <Foundation/Foundation.h> | |
NS_ASSUME_NONNULL_BEGIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MemoryRegion { | |
pub start: u32, | |
pub end: u32, | |
pub buffer: Vec<u8>, | |
pub name: String, | |
} | |
/// I32HEX supports record types: | |
/// - Data | |
/// Specifies up to 255 bytes of data. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* tube_display.c | |
* Project TubeClock/Display | |
* | |
* Created Friday, September 3, 2010 by Martin Mroz. | |
* Copyright (C) 2010 Martin Mroz, All Rights Reserved. | |
*/ | |
#include <avr/pgmspace.h> | |
#include "hardware/tube_display.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn levenshtein_distance(source: &str, target: &str) -> usize { | |
if source.len() == 0 || target.len() == 0 { | |
return std::cmp::max( | |
source.chars().count(), | |
target.chars().count() | |
); | |
} | |
let source_chars: Vec<char> = source.chars().collect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[cfg(test)] | |
mod tests { | |
use super::*; | |
#[test] | |
fn test_flux_over_byte_string() { | |
assert_eq!( | |
flux_over_byte_string("testing one two three".as_bytes()), | |
Some(Flux::new(CharType::NotSpace, 4, 0, CharType::NotSpace)) | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file | wc time | wc mem | wc_rs time | wc_rs mem | |
---|---|---|---|---|---|
empty.txt | 0.00s | 671kB | 0.00s | 786kB | |
big.txt | 0.02s | 1.72MB | 0.01s | 1.53MB | |
huge.txt | 0.32s | 1.72MB | 0.16s | 1.61MB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Computes the flux over the provided input byte string. | |
fn flux_over_byte_string<T>(input: T) -> Option<Flux> | |
where | |
T: AsRef<[u8]> { | |
input.as_ref() | |
.par_iter() | |
.cloned() | |
.map(Flux::from) | |
.fold(|| None, |acc, next| span_opt(acc, Some(next))) | |
.reduce(|| None, |acc, next| span_opt(acc, next)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Computes the flux over the provided input byte string. | |
fn flux_over_byte_string<T>(input: T) -> Option<Flux> | |
where | |
T: AsRef<[u8]> { | |
input.as_ref() | |
.iter() | |
.cloned() | |
.map(Flux::from) | |
.fold(None, |acc, next| span_opt(acc, Some(next))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn span(self, rhs: Flux) -> Self { | |
let words = { | |
// If the span is formed along a non-space to non-space boundary the word count is one less than the sum. | |
if let (CharType::NotSpace, CharType::NotSpace) = (self.rightmost_char_type, rhs.leftmost_char_type) { | |
self.words + rhs.words - 1 | |
} else { | |
self.words + rhs.words | |
} | |
}; | |
Flux::new(self.leftmost_char_type, words, self.lines + rhs.lines, rhs.rightmost_char_type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl From<u8> for Flux { | |
fn from(other: u8) -> Self { | |
if other.is_ascii_whitespace() { | |
// A line-feed is considered an ASCII whitespace character by `is_ascii_whitespace`. | |
let lines = if other == ('\n' as u8) { 1 } else { 0 }; | |
Flux::new(CharType::IsSpace, 0, lines, CharType::IsSpace) | |
} else { | |
Flux::new(CharType::NotSpace, 1, 0, CharType::NotSpace) | |
} | |
} |
NewerOlder