Skip to content

Instantly share code, notes, and snippets.

@VladimirCores
Created February 27, 2014 15:39
Show Gist options
  • Save VladimirCores/9252516 to your computer and use it in GitHub Desktop.
Save VladimirCores/9252516 to your computer and use it in GitHub Desktop.
package utils.lookuplist
{
/**
* Fast alternative to array ot dictionary
* @author Thomas John
* http://blog.open-design.be/2014/02/14/benchmarks-dictionary-vs-object-vs-array-vs-lookuplist/
*/
public class LookupList
{
public var itemFirst:LookupListItem;
public var itemLast:LookupListItem;
public function LookupList()
{
}
public function addObjectForKey(key:String, object:Object):void
{
var item:LookupListItem = new LookupListItem();
item.key = key;
item.value = object;
if (itemLast)
{
item.prev = itemLast;
itemLast.next = item;
itemLast = item;
}
else
{
itemFirst = item;
itemFirst = item;
}
}
public function getValueForKey(key:String):Object
{
var item:LookupListItem;
for (item = itemFirst; item; item = item.next)
{
if ( item.key == key ) return item.value;
}
return null;
}
}
public class LookupListItem
{
public var prev:LookupListItem;
public var next:LookupListItem;
public var key:String;
public var value:Object;
public function LookupListItem()
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment