UNPKG

@thi.ng/rle-pack

Version:

Binary run-length encoding packer w/ flexible repeat bit widths and a naive RLE encoder/decoder for arrays of arbitrary typed values

33 lines 1.22 kB
import type { Predicate2 } from "@thi.ng/api"; /** * Performs basic RLE encoding on the given `src` array(like) input, using the * optional `equiv` predicate to determine if the current value is a repetition * of an earlier one (i.e consecutive values are considered repetitions as long * as that predicate returns true). The default predicate is using `===` for * comparison. Returns RLE result array of `[value1, count1, value2, count2...]` * * @example * ```ts tangle:../export/encode-simple.ts * import { encodeSimple } from "@thi.ng/rle-pack"; * * const src = [..."aaaaaabbbbaaaxyxxx"]; * * console.log(src); * // ["a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "a", "a", "a", "x", "y", "x", "x", "x"] * * console.log(encodeSimple(src)); * // ["a", 6, "b", 4, "a", 3, "x", 1, "y", 1, "x", 3] * ``` * * @param src * @param equiv */ export declare const encodeSimple: <T = any>(src: ArrayLike<T>, equiv?: Predicate2<T>) => any[]; /** * Reverse op of {@link encodeSimple}. Takes an RLE array and returns restored * original version. Throws an error if `src.length` is not even. * * @param src */ export declare const decodeSimple: (src: any[]) => any[]; //# sourceMappingURL=simple.d.ts.map