Created
February 27, 2014 15:39
-
-
Save VladimirCores/9252516 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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