Index: /gsdl/trunk/perllib/classify/GenericList.pm
===================================================================
--- /gsdl/trunk/perllib/classify/GenericList.pm	(revision 14844)
+++ /gsdl/trunk/perllib/classify/GenericList.pm	(revision 14845)
@@ -307,17 +307,20 @@
 	return;
     }
-    my %OIDtometavalueshash = %{$self->{$metadata_group . ".list"}};
 
     # Create a mapping from metadata value to OID
-    my %metavaluetoOIDhash = ();
-    foreach my $OID (@OIDs) {
-	if ($OIDtometavalueshash{$OID}) {
-	    my @metavalues = @{$OIDtometavalueshash{$OID}};
-	    foreach my $metavalue (@metavalues) {
-		push(@{$metavaluetoOIDhash{$metavalue}}, $OID);
-	    }
-	}
-    }
-    # print STDERR "Number of distinct values: " . scalar(keys %metavaluetoOIDhash) . "\n";
+    my $OID_to_metadata_values_hash_ref = $self->{$metadata_group . ".list"};
+    my %metadata_value_to_OIDs_hash = ();
+    foreach my $OID (@OIDs)
+    {
+	if ($OID_to_metadata_values_hash_ref->{$OID})
+	{
+	    my @metadata_values = @{$OID_to_metadata_values_hash_ref->{$OID}};
+	    foreach my $metadata_value (@metadata_values)
+	    {
+		push(@{$metadata_value_to_OIDs_hash{$metadata_value}}, $OID);
+	    }
+	}
+    }
+    # print STDERR "Number of distinct values: " . scalar(keys %metadata_value_to_OIDs_hash) . "\n";
 
     # Partition the values (if necessary)
@@ -325,23 +328,23 @@
     if ($partition_type_within_level =~ /^per_letter$/i) {
 	# Generate one hlist for each letter
-	my @sortedmetavalues = $self->sort_metadata_values_array(keys(%metavaluetoOIDhash));
-	my %metavaluetoOIDsubhash = ();
-
-	my $lastpartition = substr($sortedmetavalues[0], 0, 1);
-	foreach my $metavalue (@sortedmetavalues) {
-	    my $metavaluepartition = substr($metavalue, 0, 1);
+	my @sortedmetadata_values = $self->sort_metadata_values_array(keys(%metadata_value_to_OIDs_hash));
+	my %metadata_value_to_OIDs_subhash = ();
+
+	my $lastpartition = substr($sortedmetadata_values[0], 0, 1);
+	foreach my $metadata_value (@sortedmetadata_values) {
+	    my $metadata_valuepartition = substr($metadata_value, 0, 1);
 
 	    # Is this the start of a new partition?
-	    if ($metavaluepartition ne $lastpartition) {
-		$self->add_hlist_partition(\@metadata_groups, $classifier_node, $lastpartition, \%metavaluetoOIDsubhash);
-		%metavaluetoOIDsubhash = ();
-		$lastpartition = $metavaluepartition;
-	    }
-
-	    $metavaluetoOIDsubhash{$metavalue} = $metavaluetoOIDhash{$metavalue};	    
+	    if ($metadata_valuepartition ne $lastpartition) {
+		$self->add_hlist_partition(\@metadata_groups, $classifier_node, $lastpartition, \%metadata_value_to_OIDs_subhash);
+		%metadata_value_to_OIDs_subhash = ();
+		$lastpartition = $metadata_valuepartition;
+	    }
+
+	    $metadata_value_to_OIDs_subhash{$metadata_value} = $metadata_value_to_OIDs_hash{$metadata_value};	    
 	}
 
 	# Don't forget to add the last partition
-	$self->add_hlist_partition(\@metadata_groups, $classifier_node, $lastpartition, \%metavaluetoOIDsubhash);
+	$self->add_hlist_partition(\@metadata_groups, $classifier_node, $lastpartition, \%metadata_value_to_OIDs_subhash);
 
 	# The partitions are stored in an HList
@@ -352,23 +355,23 @@
 	# Generate hlists of a certain size
 	my $partition_size_within_level = $self->{$metadata_group . ".partition_size_within_level"};
-	if ($partition_type_within_level =~ /^constant_size$/i && scalar(keys %metavaluetoOIDhash) > $partition_size_within_level) {
-	    my @sortedmetavalues = $self->sort_metadata_values_array(keys(%metavaluetoOIDhash));
+	if ($partition_type_within_level =~ /^constant_size$/i && scalar(keys %metadata_value_to_OIDs_hash) > $partition_size_within_level) {
+	    my @sortedmetadata_values = $self->sort_metadata_values_array(keys(%metadata_value_to_OIDs_hash));
 	    my $itemsdone = 0;
-	    my %metavaluetoOIDsubhash = ();
+	    my %metadata_value_to_OIDs_subhash = ();
 	    my $lastpartitionend = "";
 	    my $partitionstart;
-	    foreach my $metavalue (@sortedmetavalues) {
-		$metavaluetoOIDsubhash{$metavalue} = $metavaluetoOIDhash{$metavalue};
+	    foreach my $metadata_value (@sortedmetadata_values) {
+		$metadata_value_to_OIDs_subhash{$metadata_value} = $metadata_value_to_OIDs_hash{$metadata_value};
 		$itemsdone++;
-		my $itemsinpartition = scalar(keys %metavaluetoOIDsubhash);
+		my $itemsinpartition = scalar(keys %metadata_value_to_OIDs_subhash);
 
 		# Is this the start of a new partition?
 		if ($itemsinpartition == 1) {
-		    $partitionstart = $self->generate_partition_start($metavalue, $lastpartitionend, $self->{"partition_name_length"});
+		    $partitionstart = $self->generate_partition_start($metadata_value, $lastpartitionend, $self->{"partition_name_length"});
 		}
 
 		# Is this the end of the partition?
-		if ($itemsinpartition == $partition_size_within_level || $itemsdone == @sortedmetavalues) {
-		    my $partitionend = $self->generate_partition_end($metavalue, $partitionstart, $self->{"partition_name_length"});
+		if ($itemsinpartition == $partition_size_within_level || $itemsdone == @sortedmetadata_values) {
+		    my $partitionend = $self->generate_partition_end($metadata_value, $partitionstart, $self->{"partition_name_length"});
 		    my $partitionname = $partitionstart;
 		    if ($partitionend ne $partitionstart) {
@@ -376,6 +379,6 @@
 		    }
 
-		    $self->add_hlist_partition(\@metadata_groups, $classifier_node, $partitionname, \%metavaluetoOIDsubhash);
-		    %metavaluetoOIDsubhash = ();
+		    $self->add_hlist_partition(\@metadata_groups, $classifier_node, $partitionname, \%metadata_value_to_OIDs_subhash);
+		    %metadata_value_to_OIDs_subhash = ();
 		    $lastpartitionend = $partitionend;
 		}
@@ -388,5 +391,5 @@
 	# Otherwise just add all the values to a VList
 	else {
-	    $self->add_vlist(\@metadata_groups, $classifier_node, \%metavaluetoOIDhash);
+	    $self->add_vlist(\@metadata_groups, $classifier_node, \%metadata_value_to_OIDs_hash);
 	}
     }
@@ -423,18 +426,18 @@
 {
     my $self = shift(@_);
-    my $metavalue = shift(@_);
+    my $metadata_value = shift(@_);
     my $lastpartitionend = shift(@_);
     my $partition_name_length = shift(@_);
 
     if ($partition_name_length) {
-	return substr($metavalue, 0, $partition_name_length);
-    }
-
-    my $partitionstart = substr($metavalue, 0, 1);
+	return substr($metadata_value, 0, $partition_name_length);
+    }
+
+    my $partitionstart = substr($metadata_value, 0, 1);
     if ($partitionstart le $lastpartitionend) {
-	$partitionstart = substr($metavalue, 0, 2);
+	$partitionstart = substr($metadata_value, 0, 2);
 	# Give up after three characters
 	if ($partitionstart le $lastpartitionend) {
-	    $partitionstart = substr($metavalue, 0, 3);
+	    $partitionstart = substr($metadata_value, 0, 3);
 	}
     }
@@ -447,20 +450,20 @@
 {
     my $self = shift(@_);
-    my $metavalue = shift(@_);
+    my $metadata_value = shift(@_);
     my $partitionstart = shift(@_);
     my $partition_name_length = shift(@_);
 
     if ($partition_name_length) {
-	return substr($metavalue, 0, $partition_name_length);
-    }
-
-    my $partitionend = substr($metavalue, 0, length($partitionstart));
+	return substr($metadata_value, 0, $partition_name_length);
+    }
+
+    my $partitionend = substr($metadata_value, 0, length($partitionstart));
     if ($partitionend gt $partitionstart) {
-	$partitionend = substr($metavalue, 0, 1);
+	$partitionend = substr($metadata_value, 0, 1);
 	if ($partitionend le $partitionstart) {
-	    $partitionend = substr($metavalue, 0, 2);
+	    $partitionend = substr($metadata_value, 0, 2);
 	    # Give up after three characters
 	    if ($partitionend le $partitionstart) {
-		$partitionend = substr($metavalue, 0, 3);
+		$partitionend = substr($metadata_value, 0, 3);
 	    }
 	}
@@ -477,5 +480,5 @@
     my $classifier_node = shift(@_);
     my $partitionname = shift(@_);
-    my %metavaluetoOIDhash = %{shift(@_)};
+    my $metadata_value_to_OIDs_hash_ref = shift(@_);
 
     # Create an hlist partition
@@ -485,5 +488,5 @@
 
     # Add the children to the hlist partition
-    $self->add_vlist(\@metadata_groups, \%child_classifier_node, \%metavaluetoOIDhash);
+    $self->add_vlist(\@metadata_groups, \%child_classifier_node, $metadata_value_to_OIDs_hash_ref);
     push(@{$classifier_node->{'contains'}}, \%child_classifier_node);
 }
@@ -495,5 +498,5 @@
     my @metadata_groups = @{shift(@_)};
     my $classifier_node = shift(@_);
-    my %metavaluetoOIDhash = %{shift(@_)};
+    my $metadata_value_to_OIDs_hash_ref = shift(@_);
 
     my $metadata_group = shift(@metadata_groups);
@@ -501,6 +504,7 @@
 
     # Create an entry in the vlist for each value
-    foreach my $metavalue ($self->sort_metadata_values_array(keys(%metavaluetoOIDhash))) {
-	my @OIDs = @{$metavaluetoOIDhash{$metavalue}};
+    foreach my $metadata_value ($self->sort_metadata_values_array(keys(%{$metadata_value_to_OIDs_hash_ref})))
+    {
+	my @OIDs = @{$metadata_value_to_OIDs_hash_ref->{$metadata_value}};
 
 	# If there is only one item and 'always_bookshelf' is false, add the item to the list
@@ -510,8 +514,8 @@
 	    # Find the offset of this metadata value
 	    my $offset = 0;
-	    my %OIDtometavalueshash = %{$self->{$metadata_group . ".list"}};
-	    my @metavalues = @{$OIDtometavalueshash{$OID}};
-	    for (my $i = 0; $i < scalar(@metavalues); $i++) {
-		if ($metavalue eq $metavalues[$i]) {
+	    my $OID_to_metadata_values_hash_ref = $self->{$metadata_group . ".list"};
+	    my @metadata_values = @{$OID_to_metadata_values_hash_ref->{$OID}};
+	    for (my $i = 0; $i < scalar(@metadata_values); $i++) {
+		if ($metadata_value eq $metadata_values[$i]) {
 		    $offset = $i;
 		    last;
@@ -523,5 +527,5 @@
 	# Otherwise create a sublist (bookshelf) for the metadata value
 	else {
-	    my %child_classifier_node = ( 'Title' => $self->convert_unicode_string_to_utf8_string($metavalue),
+	    my %child_classifier_node = ( 'Title' => $self->convert_unicode_string_to_utf8_string($metadata_value),
 					  'childtype' => "VList",
 					  'contains' => [] );
@@ -538,8 +542,8 @@
 		my @sort_leaf_nodes_usingmetadata_groups = @{$self->{'sort_leaf_nodes_using_metadata_groups'}};
 		foreach my $sort_leaf_nodes_usingmetaelem (reverse @sort_leaf_nodes_usingmetadata_groups) {
-		    my %OIDtometavalueshash = %{$self->{$sort_leaf_nodes_usingmetaelem . ".list"}};
+		    my $OID_to_metadata_values_hash_ref = $self->{$sort_leaf_nodes_usingmetaelem . ".list"};
 		    # Force a stable sort (Perl 5.6's sort isn't stable)
 		    # !! The [0] bits aren't ideal (multiple metadata values) !! 
-		    @OIDs = @OIDs[ sort { $OIDtometavalueshash{$OIDs[$a]}[0] cmp $OIDtometavalueshash{$OIDs[$b]}[0] || $a <=> $b; } 0..$#OIDs ];
+		    @OIDs = @OIDs[ sort { $OID_to_metadata_values_hash_ref->{$OIDs[$a]}[0] cmp $OID_to_metadata_values_hash_ref->{$OIDs[$b]}[0] || $a <=> $b; } 0..$#OIDs ];
 		}
 
