NAME

String::Super - Compactor for superstrings

VERSION

version v0.01

SYNOPSIS

use String::Super;

my String::Super $super = String::Super->new;

my $idx = $super->add_blob('Hello World!');
my $idx = $super->add_utf8('Hello World!');
my $res = $super->result;
my $off = $super->offset(index => $idx);

This module tries to find the smallest superstring of a set of strings. That is the smallest string that contains all the given strings. As this is not a easy problem to solve this module tries to balance calculation complexity with result size.

Finding the smallest superstring is a common problem that has many applications. It can be used as part of optimising executable sizes, as part of compression algorithms, string matching and analysis.

The general workflow is to prepare the input data and serialise them into blobs (the substrings), adding them to an object of this module, asking the module to do it's magic, and then collecting both the result and the offset for each blob into the result.

Data such as unicode strings, or other objects need to be encoded. This module works on raw 8 bit blobs (unless otherwise noted). It is also totally 8 bit/binary safe.

METHODS

new

my String::Super $super = String::Super->new;

Creates a new instance. Currently no options are supported.

This constructor dies on any error.

add_blob

my $first_index = $super->add_blob(@blobs);

Adds a number of blobs. A blob is any binary (8-bit) byte-string.

Objects (reference etc.) must not be passed. Perl (unicode) strings must be encoded to the target character set before used with this method. Use "add_utf8" for strings.

The index of the first inserted blob is returned. If more than one blob is inserted the index is incremented by one for each blob.

This method dies on any error.

add_utf8

my $first_index = $super->add_utf8(@strings);

Adds a number of strings, encoding them as UTF-8. The method is otherwise identical to "add_blob".

compact

$super->compact;

This method compacts the string (calculates the resulting superstring). If the string is already compacted this method does nothing. Nothing is returned.

This method dies on any error.

result

my $res = $super->result;

This method returns the resulting superstring as a blob. It takes no options.

If the string is not yet compacted "compact" is automatically called. This method dies on any error.

offset

my $off = $super->offset(index => $idx);
# or:
my @off = $super->offset(index => $idx0, index => $idx1);

This method returns the offset into the result (see "result") for the given type-value pairs.

Each pair consists of the type and a value for that type to ask for.

Currently the following types are defined:

index

The value is an index as returned by "add_blob".

If the string is not yet compacted "compact" is automatically called. This method dies on any error.

AUTHOR

Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2025 by Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)