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