[padb-devel] [padb] r190 committed - Switch from using compress to rng_convert_to_user() in all cases...

codesite-noreply at google.com codesite-noreply at google.com
Sun Sep 6 10:10:33 BST 2009


Revision: 190
Author: apittman
Date: Sun Sep  6 02:09:39 2009
Log: Switch from using compress to rng_convert_to_user() in all cases
and remove the compress and comp functions at the same time.

http://code.google.com/p/padb/source/detail?r=190

Modified:
  /branches/cleanup/src/padb

=======================================
--- /branches/cleanup/src/padb	Sun Sep  6 01:55:49 2009
+++ /branches/cleanup/src/padb	Sun Sep  6 02:09:39 2009
@@ -1612,8 +1612,8 @@
          $are = $have;
      }

-    $ret .=
-      sprintf( "Group $members %s$sstr $are $str.\n", compress(@identical)  
);
+    $ret .= sprintf( "Group $members %s$sstr $are $str.\n",
+        rng_convert_to_user( rng_create_from_array(@identical) ) );

      return $ret;
  }
@@ -2054,32 +2054,6 @@
      debug_log( 'tree', $ref, 'Complete tree' );
      return _show_tree( $ref, undef, "" );
  }
-
-# This function is used to process the line tags, it changes fab0 fab1  
fab10 into
-# fab[0-1,10].
-sub compress {
-    my %rng  = comp(@_);
-    my @list = ();
-
-    # comp returns a hash of arrays, the hash keys are the machines names
-    # eg "fab" or "fabi", the arrays have zero or more elements in each one
-    # specifies a node-spec.  If there is only one element in the array and
-    # it doesn't contain a "-" then don't put square braces around the list
-    # contents
-
-    local $" = ",";    # "
-
-    @list = map {
-        $_
-          . (
-            @{ $rng{$_} } > 1 || ${ $rng{$_} }[0] =~ /-/
-            ? "[@{$rng{$_}}]"
-            : "@{$rng{$_}}"
-          )
-    } sort keys %rng;
-
-    return wantarray ? @list : "@list";
-}

  # sortn:
  #
@@ -2090,33 +2064,6 @@
      map { $$_[0] }
        sort { ( $$a[1] || 0 ) <=> ( $$b[1] || 0 ) } map { [ $_, /(\d*)$/ ]  
} @_;
  }
-
-sub comp {
-    my (%i) = ();
-    my (%s) = ();
-
-    # turn off warnings here to avoid perl complaints about
-    # uninitialized values for members of %i and %s
-    local ($^W) = 0;
-    push(
-        @{
-            $s{ $$_[0] }[
-              (
-                  $s{ $$_[0] }[ $i{ $$_[0] } ]
-                    [ $#{ $s{ $$_[0] }[ $i{ $$_[0] } ] } ] == ( $$_[1] - 1  
)
-              ) ? $i{ $$_[0] } : ++$i{ $$_[0] }
-            ]
-          },
-        ( $$_[1] )
-    ) for map { [/(.*?)(\d*)$/] } sortn(@_);
-
-    for my $key ( keys %s ) {
-        @{ $s{$key} } =
-          map { $#$_ > 0 ? "$$_[0]-$$_[$#$_]" : @{$_} } @{ $s{$key} };
-    }
-
-    return %s;
-}

   
###############################################################################
  #
@@ -3135,16 +3082,17 @@
      } elsif ($compress) {
          foreach my $tag ( sort { $a <=> $b } ( keys %$lines ) ) {
              next if ( !defined( $lines->{$tag} ) );
-            my @identical = ();
+            my $rng = rng_create_empty();
+            rng_add_value( $rng, $tag );
              foreach my $tag2 ( keys %$lines ) {
                  next if ( $tag2 eq $tag );
                  if ( cmp_list( \@{ $lines->{$tag} }, \@{ $lines->{$tag2} }  
) ) {
-                    push @identical, $tag2;
+                    rng_add_value( $rng, $tag2 );
                      delete( $lines->{$tag2} );
                  }
              }
              print("----------------\n");
-            printf "%s\n", join q{,}, compress( @identical, $tag );
+            printf "%s\n", rng_convert_to_user($rng);
              print("----------------\n");
              foreach my $data ( @{ $lines->{$tag} } ) {
                  print("$data\n");
@@ -3228,16 +3176,17 @@

          foreach my $tag ( sort { $a <=> $b } ( keys %$lines ) ) {
              next if ( !defined( $lines->{$tag} ) );
-            my @identical = ();
+            my $rng = rng_create_empty();
+            rng_add_value( $rng, $tag );
              foreach my $tag2 ( keys %$lines ) {
                  next if ( $tag2 eq $tag );
                  if ( cmp_list( \@{ $lines->{$tag} }, \@{ $lines->{$tag2} }  
) ) {
-                    push @identical, $tag2;
+                    rng_add_value( $rng, $tag2 );
                      delete( $lines->{$tag2} );
                  }
              }
              print("----------------\n");
-            printf "%s\n", join( ",", compress( @identical, $tag ) );
+            printf "%s\n", rng_convert_to_user($rng);
              print("----------------\n");
              foreach my $data ( @{ $lines->{$tag} } ) {
                  print("$data\n");




More information about the padb-devel mailing list