+sub lc_minmatch_hash {
+ # given a list, provide a reverse lookup of case-insensitive minimal
+ # values for each label in the list
+ my $whatever = shift;
+ my @orig_labels = @_;
+ my @labels = map { lc $_ } @orig_labels;
+ my $cc = 1;
+ my %minmatch;
+ while (@labels) {
+ my %scratch;
+ foreach my $i (0 .. $#labels) {
+ my $str = $labels[$i];
+ my $chrs = substr($str, 0, $cc);
+ $scratch{$chrs} ||= [];
+ push(@{$scratch{$chrs}}, $i);
+ }
+ my @keep_i;
+ foreach (keys %scratch) {
+ if (@{$scratch{$_}} == 1) {
+ $minmatch{$_} = $orig_labels[$scratch{$_}[0]];
+ }
+ else {
+ push(@keep_i, @{$scratch{$_}});
+ }
+ }
+ @labels = @labels[@keep_i];
+ @orig_labels = @orig_labels[@keep_i];
+ ++$cc;
+ }
+ \%minmatch;
+}
+