home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / Frizzle_fraz.swf / scripts / mx / managers / layoutClasses / PriorityQueue.as
Encoding:
Text File  |  2008-09-26  |  6.1 KB  |  220 lines

  1. package mx.managers.layoutClasses
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.DisplayObjectContainer;
  5.    import mx.core.IChildList;
  6.    import mx.core.IRawChildrenContainer;
  7.    import mx.core.mx_internal;
  8.    import mx.managers.ILayoutManagerClient;
  9.    
  10.    use namespace mx_internal;
  11.    
  12.    public class PriorityQueue
  13.    {
  14.       
  15.       mx_internal static const VERSION:String = "2.0.1.0";
  16.        
  17.       
  18.       private var maxPriority:int = -1;
  19.       
  20.       private var arrayOfArrays:Array;
  21.       
  22.       private var minPriority:int = 0;
  23.       
  24.       public function PriorityQueue()
  25.       {
  26.          arrayOfArrays = [];
  27.          minPriority = 0;
  28.          maxPriority = -1;
  29.          super();
  30.       }
  31.       
  32.       public function addObject(param1:Object, param2:int) : void
  33.       {
  34.          if(!arrayOfArrays[param2])
  35.          {
  36.             arrayOfArrays[param2] = [];
  37.          }
  38.          arrayOfArrays[param2].push(param1);
  39.          if(maxPriority < minPriority)
  40.          {
  41.             minPriority = maxPriority = param2;
  42.          }
  43.          else
  44.          {
  45.             if(param2 < minPriority)
  46.             {
  47.                minPriority = param2;
  48.             }
  49.             if(param2 > maxPriority)
  50.             {
  51.                maxPriority = param2;
  52.             }
  53.          }
  54.       }
  55.       
  56.       public function removeSmallest() : Object
  57.       {
  58.          var _loc1_:Object = null;
  59.          _loc1_ = null;
  60.          if(minPriority <= maxPriority)
  61.          {
  62.             while(!arrayOfArrays[minPriority] || arrayOfArrays[minPriority].length == 0)
  63.             {
  64.                ++minPriority;
  65.                if(minPriority > maxPriority)
  66.                {
  67.                   return null;
  68.                }
  69.             }
  70.             _loc1_ = arrayOfArrays[minPriority].shift();
  71.             while(!arrayOfArrays[minPriority] || arrayOfArrays[minPriority].length == 0)
  72.             {
  73.                ++minPriority;
  74.                if(minPriority > maxPriority)
  75.                {
  76.                   break;
  77.                }
  78.             }
  79.          }
  80.          return _loc1_;
  81.       }
  82.       
  83.       public function removeLargestChild(param1:ILayoutManagerClient) : Object
  84.       {
  85.          var _loc2_:Object = null;
  86.          var _loc3_:int = 0;
  87.          var _loc4_:int = 0;
  88.          var _loc5_:int = 0;
  89.          _loc2_ = null;
  90.          _loc3_ = maxPriority;
  91.          _loc4_ = param1.nestLevel;
  92.          while(_loc4_ <= _loc3_)
  93.          {
  94.             if(Boolean(arrayOfArrays[_loc3_]) && arrayOfArrays[_loc3_].length > 0)
  95.             {
  96.                _loc5_ = 0;
  97.                while(_loc5_ < arrayOfArrays[_loc3_].length)
  98.                {
  99.                   if(contains(DisplayObject(param1),arrayOfArrays[_loc3_][_loc5_]))
  100.                   {
  101.                      _loc2_ = arrayOfArrays[_loc3_][_loc5_];
  102.                      arrayOfArrays[_loc3_].splice(_loc5_,1);
  103.                      return _loc2_;
  104.                   }
  105.                   _loc5_++;
  106.                }
  107.                _loc3_--;
  108.             }
  109.             else
  110.             {
  111.                if(_loc3_ == maxPriority)
  112.                {
  113.                   --maxPriority;
  114.                }
  115.                _loc3_--;
  116.                if(_loc3_ < _loc4_)
  117.                {
  118.                   break;
  119.                }
  120.             }
  121.          }
  122.          return _loc2_;
  123.       }
  124.       
  125.       public function isEmpty() : Boolean
  126.       {
  127.          return minPriority > maxPriority;
  128.       }
  129.       
  130.       public function removeLargest() : Object
  131.       {
  132.          var _loc1_:Object = null;
  133.          _loc1_ = null;
  134.          if(minPriority <= maxPriority)
  135.          {
  136.             while(!arrayOfArrays[maxPriority] || arrayOfArrays[maxPriority].length == 0)
  137.             {
  138.                --maxPriority;
  139.                if(maxPriority < minPriority)
  140.                {
  141.                   return null;
  142.                }
  143.             }
  144.             _loc1_ = arrayOfArrays[maxPriority].shift();
  145.             while(!arrayOfArrays[maxPriority] || arrayOfArrays[maxPriority].length == 0)
  146.             {
  147.                --maxPriority;
  148.                if(maxPriority < minPriority)
  149.                {
  150.                   break;
  151.                }
  152.             }
  153.          }
  154.          return _loc1_;
  155.       }
  156.       
  157.       public function removeSmallestChild(param1:ILayoutManagerClient) : Object
  158.       {
  159.          var _loc2_:Object = null;
  160.          var _loc3_:int = 0;
  161.          var _loc4_:int = 0;
  162.          _loc2_ = null;
  163.          _loc3_ = param1.nestLevel;
  164.          while(_loc3_ <= maxPriority)
  165.          {
  166.             if(Boolean(arrayOfArrays[_loc3_]) && arrayOfArrays[_loc3_].length > 0)
  167.             {
  168.                _loc4_ = 0;
  169.                while(_loc4_ < arrayOfArrays[_loc3_].length)
  170.                {
  171.                   if(contains(DisplayObject(param1),arrayOfArrays[_loc3_][_loc4_]))
  172.                   {
  173.                      _loc2_ = arrayOfArrays[_loc3_][_loc4_];
  174.                      arrayOfArrays[_loc3_].splice(_loc4_,1);
  175.                      return _loc2_;
  176.                   }
  177.                   _loc4_++;
  178.                }
  179.                _loc3_++;
  180.             }
  181.             else
  182.             {
  183.                if(_loc3_ == minPriority)
  184.                {
  185.                   ++minPriority;
  186.                }
  187.                _loc3_++;
  188.                if(_loc3_ > maxPriority)
  189.                {
  190.                   break;
  191.                }
  192.             }
  193.          }
  194.          return _loc2_;
  195.       }
  196.       
  197.       public function removeAll() : void
  198.       {
  199.          arrayOfArrays.splice(0);
  200.          minPriority = 0;
  201.          maxPriority = -1;
  202.       }
  203.       
  204.       private function contains(param1:DisplayObject, param2:DisplayObject) : Boolean
  205.       {
  206.          var _loc3_:IChildList = null;
  207.          if(param1 is IRawChildrenContainer)
  208.          {
  209.             _loc3_ = IRawChildrenContainer(param1).rawChildren;
  210.             return _loc3_.contains(param2);
  211.          }
  212.          if(param1 is DisplayObjectContainer)
  213.          {
  214.             return DisplayObjectContainer(param1).contains(param2);
  215.          }
  216.          return param1 == param2;
  217.       }
  218.    }
  219. }
  220.