Not so recursive method annoyance fix

Posted By Thaylin on February 11, 2009

Ok just first of all, I would like to point out that the method in my previous post was in all actuality not a recursive method. It loops through objects in that class but not the same object consecutive times.. my bad.

On that note. Thanks to Hudson Ansley on the flashcodersny blog for pointing out that I could instead of using an array to loop through and what not I could instead use a Dictionary object. Here is the final fixed code:

?View Code ACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
public function addNeighborToDictionary(item:CityOnMap):void
{
	if(this.neighborsDict[item]==undefined)
	 {
	 	this.neighborsDict[item] = item;
	 	for (var key:Object in item.neighborsDict)
	 	{
	 		CityOnMap(item.neighborsDict[key]).addNeighborToDictionary(this)
	 	}
	 	item.neighborsDict[this] = this;
 
	 }
}

This is not only much shorter code, but in a list of 159 properties it cut down the time by approx. 200ms.
At 84 items there was no real noticeable difference in time with both methods clocking in at about 350ms. With 159 items with identical number of neighbors, it starts to get noticeable with the neighbors Array method taking approx. 600-700 ms while the neighbors Dictionary method completed in approx. 300-350 ms.

I can only imagine that as the items increase in number the difference would continue to rise.


Comments

2 Responses to “Not so recursive method annoyance fix”

  1. LARRY says:


    CheapTabletsOnline.Com. Canadian Health&Care.Best quality drugs.No prescription online pharmacy.Special Internet Prices. Low price drugs. Order drugs online

    Buy:Petcam (Metacam) Oral Suspension.Accutane.100% Pure Okinawan Coral Calcium.Human Growth Hormone.Mega Hoodia.Retin-A.Nexium.Zyban.Lumigan.Synthroid.Zovirax.Prevacid.Prednisolone.Valtrex.Actos.Arimidex….

  2. CODY says:


    CheapTabletsOnline.Com. Canadian Health&Care.Special Internet Prices.Best quality drugs.No prescription online pharmacy. No prescription drugs. Order pills online

    Buy:SleepWell.Zetia.Ventolin.Nymphomax.Buspar.Advair.Lasix.Wellbutrin SR.Aricept.Amoxicillin.Benicar.Seroquel.Cozaar.Lipothin.Female Cialis.Zocor.Prozac.Lipitor.Acomplia.Female Pink Viagra….

Leave a Reply