Regina 7.3 Calculation Engine
|
Regina includes support for tight encodings, which are encodings of various data types as short printable strings.
Tight encodings have the following properties:
int
, a long
, or a regina::Integer. Note that this guarantee only extends to types that "conceptually" intend to represent the same broad types of objects, possibly with different limitations. So, for example, there is no guarantee that the integer 7, the rational 7/1, and/or the constant polynomial 7 would encode to the same string.A consequence of the last two points is that, if the type of an object is known in advance, then its value can be recovered from its encoding. However, the encoding does not contain enough information to deduce the type if this is not already known.
Because encodings contain enough information to identify where they end, this means that you can encode a sequence of objects by concatenating the individual encodings with no separators, and (assuming the types of the objects are fixed) this will be enough to guarantee that different sequences likewise have different encodngs.
Tight encodings were originally designed to support perfect hashing (essentially "compressing" data into a short printable string whilst preserving the correctness of equality tests). As a result, they were originally intended to be used only in one direction. However, Regina does provide matching decoding routines if you need to reconstruct objects from their tight encodings.
For native C++ data types where tight encodings and decodings are supported, these are provided in the header utilities/tightencoding.h through overloads of the global functions tightEncoding() and tightDecoding() (which work with strings), and tightEncode() and tightDecode() (which work with input/output streams).
For Regina's own data types where tight encodings and decodings are supported, these are provided through member functions tightEncoding(), tightEncode(), tightDecoding() and tightDecode() within the corresponding classes.