compression of strings into curly braces



People when authoring technical papers often write things like:

email: {foo,bar}@domain.edu

If I'm in the bash shell on unix, I might write this snippet check a
bunch of hostnames for their system load, e.g.

for host in host{1,2,3}; do rsh $host uptime; done

so this brace usage is very expressive and convenient and easy to use
to expand a string into a set of related members. I'm currently
interested in going the other direction. e.g. given a list of strings
like

host1.domain.com
host2.domain.com
host3.domain.com

as input to a program, how is it possible to turn this into
host{1,2,3}.domain.com? it would seem that this really requires a
compression algorithm. ultimately with this transformation you are
run-length encoding, as plain text, contiguous stretches of multiple
elements which are similar, while the variances are grouped into sets
with curly braces (we can assume there are no { } or , characters in
the input, so they can be used to represent sets).

Has anyone seen this problem before? Does it have a name? In this
case, I am indeed looking to compress a list of hostnames into a short
but readable list, but would enjoy looking at a general solution. note
it gets trickier if you get this set as input:

host1.domain1.com
host2.domain1.com
host3.domain1.com
host1.mydomain2.com
host2.mydomain2.com
host3.mydomain2.com

in this case, the 2 obvious groups differ in multiple places so it
seems you need as output:

host{1,2,3}.domain1.com host{1,2,3}.mydomain2.com

but the set

host1.domain1.com
host2.domain1.com
host3.domain1.com
host1.domain2.com
host2.domain2.com
host3.domain2.com

can be turned into host{1,2,3}.domain{1,2}.com

thanks for any insight or recognition of this problem. or pointers to
libraries or algorithms which have solved this.

.



Relevant Pages

  • Re: String concatenation performance
    ... > into one string for use over multiple lines of code. ... Running the sample many times via an internal loop. ... in a container and that container is using system resources along with the ...
    (comp.lang.javascript)
  • Re: issue with runing Select query with condition using code
    ... You can then apply it as the Filter of a form, or the WhereCondition of OpenReport, or build the whole SQL string and apply it to the SQL property of a QueryDef. ... Splitmight be useful for parsing multiple elements in a text box into an array. ... Be sure to use the correct delimiter around the values, i.e. " for strings, # for dates, and no delimiter for numeric values. ... I'm trying to use the DoCmd.open query statement to run a Select query. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Introducing Python to others
    ... A simple class example and a class example showing multiple ... Simple string manipulation example ... Lists, dictionaries and sets ... Advanced Python features: ...
    (comp.lang.python)
  • Re: What am I doing wrong?
    ... This will force the variant type so that it is either NaN or one of the ... since it always does that I only use parseInt() if I need the filed to ... >>I always will multiple a string by one to force it to either become ...
    (microsoft.public.scripting.jscript)
  • Re: How much lossless compression is possible in images?
    ... There are binary strings ... Suppose B is such a string, ... compression algorithm which encodes B as a single 1 bit, ...
    (sci.math)

Loading