From: Tara L Andrews Date: Wed, 18 Apr 2012 12:30:02 +0000 (+0200) Subject: retain original order of collation sets X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmatology.git;a=commitdiff_plain;h=6e526d95ab3ff2878cedc28808984d3ec6a16c88 retain original order of collation sets --- diff --git a/lib/Text/Tradition/Parser/Util.pm b/lib/Text/Tradition/Parser/Util.pm index 8a17e7e..de18a6f 100644 --- a/lib/Text/Tradition/Parser/Util.pm +++ b/lib/Text/Tradition/Parser/Util.pm @@ -32,14 +32,13 @@ on the collation graph. sub collate_variants { my( $collation, @reading_sets ) = @_; - # Make sure the reading sets are unique, but keep - # the lemma first. - my $lemma = shift @reading_sets; + # Make sure the reading sets are unique, but retain their ordering. my %unique_sets; - map { $unique_sets{$_} = $_ } @reading_sets; - delete $unique_sets{$lemma}; - my @sets = values %unique_sets; - unshift( @sets, $lemma ); + my @sets; + foreach( @reading_sets ) { + push( @sets, $_ ) unless $unique_sets{$_}; + $unique_sets{$_} = $_; + } # Two different ways to do this, depending on whether we want # transposed reading nodes to be merged into one (producing a