Debian Codegraph @

third_party/rust/mapped_hyph/README.md

raw
1 # mapped_hyph
2
3 mapped_hyph is a reimplementation of the hyphenation algorithm from the
4 [libhyphen](https://github.com/hunspell/hyphen) library
5 that is intended to reduce the in-memory footprint of loaded
6 hyphenation dictionaries, especially when the same dictionary
7 may be in use by multiple processes.
8
9 To reduce memory footprint, mapped_hyph uses hyphenation dictionaries that are
10 "precompiled" into a flat, position-independent binary format that is used
11 directly by the runtime hyphenation functions.
12 Therefore, dictionaries do not have to be parsed into a dynamic structure in memory;
13 the files can simply be mmap'd into the address space and immediately used.
14 In addition, a compiled dictionary mapped into a shared-memory block
15 can be made available to multiple processes for no added physical memory cost.
16
17 One deliberate simplification compared to libhyphen
18 is that mapped_hyph only accepts UTF-8 text and hyphenation dictionaries;
19 legacy non-Unicode encodings are not supported.
20
21 mapped_hyph has been created primarily for use by Gecko, replacing the use of libhyphen,
22 and so its features (and limitations) are based on this use case.
23 However, it is hoped that it will also be more generally useful.
24
25 ## Functionality
26
27 Currently, mapped_hyph supports only "standard" hyphenation, where spelling does not
28 change around the hyphenation position. At present this is the only kind of
29 hyphenation supported in Gecko.
30
31 The compiled hyphenation dictionary format includes provision for replacement
32 strings and indexes, as used by libhyphen to support non-standard hyphenations
33 (e.g. German "Schiffahrt" -> "Schiff-fahrt"), but the `find_hyphen_values` function
34 will ignore any such hyphenation positions it finds.
35 (None of the hyphenation dictionaries shipping with Firefox includes such rules.)
36
37 ## Licensing
38
39 mapped_hyph is dual licensed under the Apache-2.0 and MIT licenses;
40 see the file COPYRIGHT.
41
42 ## Documentation
43
44 Use `cargo doc --open` to view (admittedly brief) documentation generated from
45 comments in the source.
46
47 ## C and C++ bindings
48
49 See src/ffi.rs for C/C++ APIs that can be used to load hyphenation files
50 and to locate valid hyphenation positions in a word.
51
52 ## Sample programs
53
54 See main.rs for a simple example program.
55
56 ## Compiled dictionaries
57
58 The `hyf_compile` tool is used to generate `.hyf` files for mapped_hyph
59 from standard `.dic` (or `.pat`) files as used by libhyphen, LibreOffice, etc.
60
61 (A compiled version of the `hyph_en_US` dictionary from libhyphen is currently
62 included here, as it is handy for testing purposes.)
63
64 ## Release Notes
65
66 ### 0.4.0
67
68 * Added a boolean `compress` param to the pattern compiler to control whether
69 it attempts to compress the compiled table by merging duplicate states (which
70 takes significant extra time).
71
72 * Added FFI functions to compile hyphenation tables from a file path or a buffer,
73 intended for use from Gecko.
74
75 ### 0.3.0
76
77 * Switched from MPL2 to Apache2/MIT dual license.
78
79 * Misc bug-fixes and optimizations.
80
81 ### 0.2.0
82
83 * Implemented a hyphenation table compiler in the `builder` submodule,
84 and `hyf_compile` command-line tool.
85
86 * Moved C-callable API functions into an `ffi` submodule.
87
88 ### 0.1.0
89
90 * Initial release.