예제 #1
0
		public GridNode Item(int x, int y)
		{
			GridNode node = new GridNode(x, y);

			//Get the index on the y axis
			int index = mYList.BinarySearch(node, mComparerY);
			if (index < 0) return null;

			//Get the x arraylist
			ArrayList xList = (ArrayList) mYList[index];

			index = xList.BinarySearch(node, mComparerX);
			if (index < 0) return null;

			return (GridNode) xList[index];
		}
예제 #2
0
		public virtual void Add(GridNode node)
		{
			//Get the index on the y axis
			int index = mYList.BinarySearch(node, mComparerY);
			
			//If not found, add a new x list with a new item
			if (index < 0)
			{
				ArrayList xList = new ArrayList();
				xList.Add(node);
				mYList.Insert(~index, xList); //Insert the node at the correct index which is the bitwise complement
				return;
			}

			//Get the x arraylist
			ArrayList x = (ArrayList) mYList[index];

			index = x.BinarySearch(node, mComparerX);
			if (index < 0) 
			{
				x.Insert(~index, node); //Insert the node at the correct index
			}
		}
예제 #3
0
		// Push an object onto the PQ
		// Returns the index in the list where the object is _now_. This will change when objects are taken from or put onto the PQ.
		public int Push(GridNode O)
		{
			int p = InnerList.Count, p2;

			InnerList.Add(O); // E[p] = O
		
			while (true)
			{
				if (p==0) break;
				p2 = (p-1) / 2;
			
				if (OnCompare(p, p2) < 0)
				{
					SwitchElements(p, p2);
					p = p2;
				}
				else
				{
					break;
				}
			}

			return p;
		}
예제 #4
0
		public void Update(GridNode node)
		{
			//Get the index of the node into i
			int i = InnerList.BinarySearch(node);
			if (i < 0) return;

			int p = i,pn;
			int p1, p2;
			
			while (true)
			{
				if(p==0) break;
				p2 = (p-1)/2;
				
				if(OnCompare(p,p2) < 0)
				{
					SwitchElements(p,p2);
					p = p2;
				}
				else
				{
					break;
				}
			}

			if (p < i) return;
			
			while (true)
			{
				pn = p;
				p1 = 2*p+1;
				p2 = 2*p+2;
				if (InnerList.Count > p1 && OnCompare(p,p1) > 0) p = p1;
				if (InnerList.Count > p2 && OnCompare(p,p2) > 0) p = p2;
				
				if(p==pn) break;
				SwitchElements(p,pn);
			}
		}