Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package luce.tools{
- public class Collapser{
- // [1,2,3,4, , ,5,6, ,7, , , ,8, ]
- // becomes
- // [1,2,3,4,8,7,5,6]
- public static function collapseVectorFast( v:Vector ):void{
- var end:int = v.length,
- front:int = 0;
- while( end > front ){
- while( end > 0 && v[--end] == null ) null;
- while( front < v.length && v[front] != null ) front++;
- v[front] = v[end];
- }
- v.length = end + 1;
- }
- // [1,2,3,4, , ,5,6, ,7, , , ,8, ]
- // becomes
- // [1,2,3,4,5,6,7,8]
- public static function collapseVectorOrdered( v:Array ):void{
- var here:int = 0,
- from:int = 0;
- while( here < v.length && v[here] != v ) from = ++here + 1;
- while( from < v.length )
- if( v[from] == null ) from++;
- else v[here++] = v[from++];
- v.length = from;
- }
- // [1,2,3,4, , ,5,6, ,7, , , ,8, ]
- // becomes
- // [1,2,3,4,8,7,5,6, , , , , , , ]
- public static function collapseArrayFast( v:Array ):void{
- var end:int = v.length,
- front:int = 0;
- while( end > front ){
- while( end > 0 && v[--end] == null ) null;
- while( front < v.length && v[front] != null ) front++;
- v[front] = v[end];
- }
- }
- // [1,2,3,4, , ,5,6, ,7, , , ,8, ]
- // becomes
- // [1,2,3,4,5,6,7,8, , , , , , , ]
- public static function collapseArrayOrdered( v:Vector ):void{
- var here:int = 0,
- from:int = 0;
- while( here < v.length && v[here] != v ) from = ++here + 1;
- while( from < v.length )
- if( v[from] == null ) from++;
- else v[here++] = v[from++];
- }
- }
- }
Add Comment
Please, Sign In to add comment