Skip to content

Commit

Permalink
Renamed mmhyph to mapped_hyph
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkthame committed Oct 20, 2019
1 parent e9ff666 commit 04c3f4d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "mmhyph"
name = "mapped_hyph"
description = "Hyphenation using precompiled memory-mapped tables"
version = "0.1.0"
authors = ["Jonathan Kew <[email protected]>"]
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# mmhyph
# mapped_hyph

mmhyph is a reimplementation of the hyphenation algorithm from the
mapped_hyph is a reimplementation of the hyphenation algorithm from the
[libhyphen](https://github.com/hunspell/hyphen) library
that is intended to reduce the in-memory footprint of loaded
hyphenation dictionaries, especially when the same dictionary
may be in use by multiple processes.

To reduce memory footprint, mmhyph uses hyphenation dictionaries that are
To reduce memory footprint, mapped_hyph uses hyphenation dictionaries that are
"precompiled" into a flat, position-independent binary format that is used
directly by the runtime hyphenation functions.
Therefore, dictionaries do not have to be parsed into a dynamic structure in memory;
Expand All @@ -15,16 +15,16 @@ In addition, a compiled dictionary mapped into a shared-memory block
can be made available to multiple processes for no added physical memory cost.

One deliberate simplification compared to libhyphen
is that mmhyph only accepts UTF-8 text and hyphenation dictionaries;
is that mapped_hyph only accepts UTF-8 text and hyphenation dictionaries;
legacy non-Unicode encodings are not supported.

mmhyph has been created primarily for use by Gecko, replacing the use of libhyphen,
mapped_hyph has been created primarily for use by Gecko, replacing the use of libhyphen,
and so its features (and limitations) are based on this use case.
However, it is hoped that it will also be more generally useful.

## Functionality

Currently, mmhyph supports only "standard" hyphenation, where spelling does not
Currently, mapped_hyph supports only "standard" hyphenation, where spelling does not
change around the hyphenation position. At present this is the only kind of
hyphenation supported in Gecko.

Expand All @@ -37,7 +37,7 @@ will panic!() with a "not yet implemented" message if it encounters such a case.
## Licensing

Please see the file named
[LICENSE](https://github.com/jfkthame/mmhyph/blob/master/LICENSE),
[LICENSE](https://github.com/jfkthame/mapped_hyph/blob/master/LICENSE),
or the [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/) license online.

## Documentation
Expand All @@ -46,7 +46,7 @@ TODO

## C and C++ bindings

See the `mmhyph.h` header for C/C++ APIs that can be used to load hyphenation files
See the `mapped_hyph.h` header for C/C++ APIs that can be used to load hyphenation files
and to locate valid hyphenation positions in a word.

## Sample programs
Expand All @@ -56,7 +56,7 @@ See main.rs for a simple example program.
## Compiled dictionaries

A tool to compile dictionary files (`*.dic`) as used by libhyphen
into mmhyph's binary format is not yet included.
into mapped_hyph's binary format is not yet included.

## Release Notes

Expand Down
6 changes: 3 additions & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ extern crate test;
#[macro_use]
extern crate lazy_static;

extern crate mmhyph;
use mmhyph::Hyphenator;
extern crate mapped_hyph;
use mapped_hyph::Hyphenator;

lazy_static! {
static ref WORDS: Vec<String> = {
Expand All @@ -20,7 +20,7 @@ lazy_static! {
fn bench_words(b: &mut test::Bencher) {
b.iter(|| {
let dic_path = "hyph_en_US.hyf";
let hyph = match mmhyph::load_file(dic_path) {
let hyph = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand Down
4 changes: 2 additions & 2 deletions cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ language = "C"

header = "/* This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/. */"
# trailer = "/* Text to put at the end of the generated file */"
include_guard = "mmhyph_h"
autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */"
include_guard = "mapped_hyph_h"
autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually.\n */"
include_version = false
# namespace = "my_namespace"
namespaces = []
Expand Down
9 changes: 5 additions & 4 deletions mmhyph.h → mapped_hyph.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef mmhyph_h
#define mmhyph_h
#ifndef mapped_hyph_h
#define mapped_hyph_h

/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually.
*/

#include <stdbool.h>
#include <stdint.h>
Expand Down Expand Up @@ -37,4 +38,4 @@ const HyphDic *load_hyphenation_file(const char *path);
} // extern "C"
#endif // __cplusplus

#endif /* mmhyph_h */
#endif /* mapped_hyph_h */
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ impl State<'_> {
let transition_offset = if self.is_extended() { 12 } else { 8 };
assert!(self.data.len() == transition_offset + count * 4);
let trans_ptr = &self.data[transition_offset] as *const u8 as *const Transition;
// This is OK because we assert!() above that self.data.len() is large enough
// to accommodate the expected number of Transitions.
unsafe { slice::from_raw_parts(trans_ptr, count) }
}
// Look up the Transition for a given input byte, or None.
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

extern crate mmhyph;
extern crate mapped_hyph;

use mmhyph::Hyphenator;
use mapped_hyph::Hyphenator;

fn main() {
let dic_path = "hyph_en_US.hyf";

let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -32,21 +32,21 @@ fn main() {
println!("{}", dic.hyphenate_word("-x-mailing", '='));
println!("{}", dic.hyphenate_word("-strikeout-", '='));

let dic2 = match mmhyph::load_file("tests/compound.hyf") {
let dic2 = match mapped_hyph::load_file("tests/compound.hyf") {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", "tests/compound.hyf"),
};

println!("{}", dic2.hyphenate_word("motorcycle", '='));

let dic3 = match mmhyph::load_file("tests/rhmin.hyf") {
let dic3 = match mapped_hyph::load_file("tests/rhmin.hyf") {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
println!("{}", dic3.hyphenate_word("övéit", '='));
println!("{}", dic3.hyphenate_word("అంగడిధర", '='));

let dic4 = match mmhyph::load_file("tests/num.hyf") {
let dic4 = match mapped_hyph::load_file("tests/num.hyf") {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", "tests/num.hyf"),
};
Expand Down
28 changes: 14 additions & 14 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
#![feature(test)]

extern crate test;
extern crate mmhyph;
extern crate mapped_hyph;

#[cfg(test)]
mod tests {
use mmhyph::Hyphenator;
use mapped_hyph::Hyphenator;

#[test]
fn basic_tests() {
let dic_path = "hyph_en_US.hyf";
let hyph = match mmhyph::load_file(dic_path) {
let hyph = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -32,7 +32,7 @@ mod tests {
#[test]
fn base() {
let dic_path = "tests/base.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -54,7 +54,7 @@ mod tests {
#[test]
fn compound() {
let dic_path = "tests/compound.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -64,7 +64,7 @@ mod tests {
#[test]
fn compound4() {
let dic_path = "tests/compound4.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -74,7 +74,7 @@ mod tests {
#[test]
fn compound5() {
let dic_path = "tests/compound5.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -84,7 +84,7 @@ mod tests {
#[test]
fn compound6() {
let dic_path = "tests/compound6.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -94,7 +94,7 @@ mod tests {
#[test]
fn settings2() {
let dic_path = "tests/settings2.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -104,7 +104,7 @@ mod tests {
#[test]
fn settings3() {
let dic_path = "tests/settings3.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -114,7 +114,7 @@ mod tests {
#[test]
fn hyphen() {
let dic_path = "tests/hyphen.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -124,7 +124,7 @@ mod tests {
#[test]
fn lhmin() {
let dic_path = "tests/lhmin.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -134,7 +134,7 @@ mod tests {
#[test]
fn rhmin() {
let dic_path = "tests/rhmin.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand All @@ -145,7 +145,7 @@ mod tests {
#[test]
fn num() {
let dic_path = "tests/num.hyf";
let dic = match mmhyph::load_file(dic_path) {
let dic = match mapped_hyph::load_file(dic_path) {
Some(dic) => dic,
_ => panic!("failed to load dictionary {}", dic_path),
};
Expand Down

0 comments on commit 04c3f4d

Please sign in to comment.