package ucharset
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=2f91039a754ba7030ad94c930903936a1df03683123f1e433ef5bb2878a8a388
sha512=cdc19455b6f8d38b9c93efe8be0b631fca4274970d1995511d280169e2524ff579ee8133c3b1f686a705d869247ebac145944ebab3d8ec071cf2d9dff15afbc1
Description
A faster, smaller Set.Make(Uchar). Cost follows the run count, not the cardinal: the Alphabetic property is 147,421 codepoints in 761 runs, held in 12KB against 5.6MB, and the whole codespace is 40 bytes against 42.4MB. Alongside the usual set algebra there is a builder for accumulating a class from many fragments, a compiled two-level bitmap trie for membership in an inner loop, partition refinement for derivative classes during DFA construction, and a stable packed encoding for embedding generated tables in source. Surrogates are excluded by construction.
README
ucharset
Character classes for Unicode-aware lexers and regex engines: a faster, smaller Set.Make(Uchar).
Elements are scalar values in the sense of Uchar.t; the surrogate block is excluded by construction, and functions taking raw codepoints reject it.
Install
Not released to opam yet.
opam pin add ucharset https://github.com/enetsee/ucharset.gitExample
let letter = Ucharset.range_char ~lo:'a' ~hi:'z'
let digit = Ucharset.range_char ~lo:'0' ~hi:'9'
let ident = Ucharset.union_list [ letter; digit; Ucharset.singleton_char '_' ]
let () = Format.printf "%a@." Ucharset.pp_class ident
(* {0-9 _ a-z} *)Alongside the usual algebra (union, inter, diff, comp, xor, subset, disjoint) there are four things worth knowing about.
Builder accumulates a set from many fragments, appending in amortized O(1) and canonicalizing once, where repeated union costs O(size) a step.
Lookup compiles a set into a two-level bitmap trie, so membership becomes two loads and a mask, independent of the interval count. Against mem it is roughly 2x faster on a set of a few intervals and ~7x at a thousand, in anything from tens of bytes to a few KB. ascii_table is faster still when the test stays inside ASCII.
Partition computes the common refinement of two partitions as a single merge over the interval endpoints, O(P + Q), where doing it pairwise costs |p| * |q| intersections. It is written for derivative-based DFA construction, where a regex's derivative classes are exactly such a meet; Partition.representatives gives one codepoint per block without building the blocks at all.
Packed encoding serialises a set to a string, six bytes per interval, for embedding generated tables such as Unicode property data in source. The format is stable and part of the interface.
Development
dune build
dune runtest
dune build @doc # _build/default/_doc/_htmlLicense
MIT.
Dev Dependencies (4)
-
odoc
with-doc -
qcheck-alcotest
with-test -
qcheck-core
with-test -
alcotest
with-test
Used by
None
Conflicts
None