Guest User

Untitled

a guest
Apr 14th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package luce.tools{
  2.    
  3.     public class Collapser{
  4.  
  5.         // [1,2,3,4, , ,5,6, ,7, , , ,8, ]
  6.         // becomes
  7.         // [1,2,3,4,8,7,5,6]
  8.         public static function collapseVectorFast( v:Vector ):void{
  9.             var end:int = v.length,
  10.                 front:int = 0;
  11.             while( end > front ){
  12.                 while( end > 0 && v[--end] == null ) null;
  13.                 while( front < v.length && v[front] != null ) front++;
  14.                 v[front] = v[end];
  15.             }
  16.             v.length = end + 1;
  17.         }
  18.        
  19.        
  20.         // [1,2,3,4, , ,5,6, ,7, , , ,8, ]
  21.         // becomes
  22.         // [1,2,3,4,5,6,7,8]
  23.         public static function collapseVectorOrdered( v:Array ):void{
  24.             var here:int = 0,
  25.                 from:int = 0;
  26.             while( here < v.length && v[here] != v ) from = ++here + 1;
  27.             while( from < v.length )
  28.                 if( v[from] == null ) from++;
  29.                 else v[here++] = v[from++];
  30.             v.length = from;
  31.         }
  32.        
  33.        
  34.        
  35.         // [1,2,3,4, , ,5,6, ,7, , , ,8, ]
  36.         // becomes
  37.         // [1,2,3,4,8,7,5,6, , , , , , , ]
  38.         public static function collapseArrayFast( v:Array ):void{
  39.             var end:int = v.length,
  40.                 front:int = 0;
  41.             while( end > front ){
  42.                 while( end > 0 && v[--end] == null ) null;
  43.                 while( front < v.length && v[front] != null ) front++;
  44.                 v[front] = v[end];
  45.             }
  46.         }
  47.        
  48.         // [1,2,3,4, , ,5,6, ,7, , , ,8, ]
  49.         // becomes
  50.         // [1,2,3,4,5,6,7,8, , , , , , , ]
  51.         public static function collapseArrayOrdered( v:Vector ):void{
  52.             var here:int = 0,
  53.                 from:int = 0;
  54.             while( here < v.length && v[here] != v ) from = ++here + 1;
  55.             while( from < v.length )
  56.                 if( v[from] == null ) from++;
  57.                 else v[here++] = v[from++];
  58.            
  59.         }
  60.        
  61.     }
  62.    
  63. }
Add Comment
Please, Sign In to add comment