How can I achieve fast and effective String compression in Actionscript 3?

I have an Object which stores pairs for a find and replace that I perform on up to 1500 Strings at a time.

The Object is populated with pairs using a method that will accept a String and then store this as a property with the value being an automatically assigned base 36 number, like this:

function addShort(long:String):void
{
    _pairs[long] = _nextShort;
}

_nextShort returns an automatically incremented value being the subject of .toString(36), so running the above a few times might make _pairs look like this:

_pairs:Object = {
    "class": "0",
    "testing.objects.TestBlock": "1",
    "skin.x": "2",
    "skin.y": "3",
    ...........
    "someString": "az1"
};

This Object could realistically end up being really large, having over a couple hundred pairs stored.

I then have a method that will take a "long" String (which will include the Strings I've given to addShort() previously) and return a new String where these have been replaced with their respective short value.

The method looks like this:

public function shorten(long:String):String
{
    for(var i:String in _pairs)
        long = long.split(i).join(_pairs[i]);

    return long;
}

Nice an simple, however in my mind I foresee a massive problem in a case where I might want to "shorten" 2000+ Strings and the _pairs Object has at the same time has over 500 pairs.

That ends up being 1,000,000 iterations all up which obviously doesn't seem very efficient at all.

How can I improve this process significantly?

Answers


Based on comments from @kapep I realized what I needed is actually a compression library that will do this work for me.

I stumbled across an LZW compression class within a package called Calista which works great.

I did notice that the compression was really slow, which is understandable, but if there are any suggestions for something quicker I'm open to them.


Need Your Help

Stack two UIImages to one

objective-c ios uiimage core-graphics

I'm searching for a way to stack two UIImages. I don't want to simply merge them (add one above another), i rather want to stack their pixel values.

INSERT-ing multiple rows

sql-server-2008 stored-procedures insert

I have the following sql code. Is it guaranteed that MyTable is going to be sorted by MyTable.data? Basically the question is - if I am inserting multiple rows with one INSERT statement, can other

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.