Forum Topic: AS3 list

(73 views • 3 replies)

This topic is 1 page long.

<< < > >>
None

Disarray-yarrasiD

Reply To Post Reply & Quote

Posted at: 5/3/09 12:53 PM

Disarray-yarrasiD DARK LEVEL 09

Sign-Up: 11/14/04

Posts: 1,474

Does anyone know if there a native list class in as3 that permits constant time addition and removal operations, or am I going to have to make my own?

BBS Signature

None

Deathcon7

Reply To Post Reply & Quote

Posted at: 5/3/09 01:03 PM

Deathcon7 NEUTRAL LEVEL 21

Sign-Up: 10/01/03

Posts: 5,870

Unfortunately, this is the only list in flash:

http://livedocs.adobe.com/flash/9.0/Acti onScriptLangRefV3/fl/controls/List.html

Linked list is something different.


None

Disarray-yarrasiD

Reply To Post Reply & Quote

Posted at: 5/3/09 01:38 PM

Disarray-yarrasiD DARK LEVEL 09

Sign-Up: 11/14/04

Posts: 1,474

At 5/3/09 01:03 PM, Deathcon7 wrote: Unfortunately, this is the only list in flash:

http://livedocs.adobe.com/flash/9.0/Acti onScriptLangRefV3/fl/controls/List.html

Linked list is something different.

Well thats pretty shitty...

anyway here is a quick little node class that I whipped up in about 20 minutes that offers what I was talking about.:

package  
{
	/**
	 * For some reason the makers of as3 decided not to include a friggin simple linked list class
	 * that allows traversing and constant time addition and removal operations. Does not include an
	 * itterator, but its set up so that it doesn't need one.
	 * @author  TheYarrasid
	 * @version 5/3/2009
	 */
	public class Node 
	{
		public function Node(aPreviousNode:Node, aObject:Object) 
		{
			previousNode = aPreviousNode;
			object = aObject;
			if (hasPrevious())
			{
				previousNode.addNext(this);
			}
		}
		
		public function addNext(aNextNode:Node):void
		{
			nextNode = aNextNode;
		}
		
		public function addPrevious(aPreviousNode:Node):void
		{
			previousNode = aPreviousNode;
		}
		public function hasNext():Boolean
		{
			return nextNode != null;
		}
		
		public function hasPrevious():Boolean
		{
			return previousNode != null;
		}
		
		public function getObject():Object
		{
			return object;
		}
		
		public function previous():Node
		{
			return previousNode;
		}
		
		public function next():Node
		{
			return nextNode;
		}
		
		public function removeNode():void
		{
			if (hasPrevious())
			{
				previousNode.addNext(nextNode);
			}
			if (hasNext())
			{
				nextNode.addPrevious(previousNode);
			}
		}
		var previousNode:Node;
		var nextNode:Node;
		var object:Object;
	}
}
BBS Signature

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 5/3/09 02:10 PM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,427

Who says arrays aren't constant-time? :p
Of course, lists have the advantage when operations are in the middle of the sequence.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


All times are Eastern Standard Time (GMT -5) | Current Time: 06:44 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!