Plaster
New
List
Login
common-lisp
default
mrcom
2024.07.02 19:33:43
(defun encode (message &key include-dictionary dictionary (start 0) end key (test #'eql) sort-pred) "Huffman-encode a message, optionally using a pre-calculated code dictionary. The default dictionary is an internally generated canonical-form Huffman encoding. Returns two values, the encoded message and the dictionary used. - `message' is a sequence of coding symbols (symbols in the algorithmic sense, the message's CL type is a sequence of T). - If `include-dictionary' is true then the dictionary tree will be included in an encoded-message preamble, and it will not require an external dictionary for decoding, with these caveats: * Only the ecoding tree is included: codes, code-word lengths, code-to-symbol translations, and the `include-end' and `include-invalid' settings. `unkey' is _not_ included, and will need to be supplied when DECODE is called. * Symbols must be numerically encodable, either natively (e.g. integers, strings and characters) or via a `key' function. - `dictionary' is an optional encoding dictionary. If not supplied then one will be generated from `message'. - `start' and `end' optionally specify a specific sub-sequence of `message'. The first element of the result message corresponds to the message[start]. - The following keys, `key', `test', and `sort-pred' are only used if a `dictionary' was not supplied and one is being auto-generated. See MAKE-DICTIONARY for their definitions. Returns two values. The first is a BIT-VECTOR of the encoded (possibly sub-sequence of) `message'. The second is the coding dictionary used, either `dictionary' or the auto-generated one. An error will be signaled if there is a symbol in `message' which is not in the supplied `dictionary', and either the dictionary did not have `include-invalid' specified or the symbol cannot be numerically encoded."
Raw
Annotate
Repaste