- my ($i, $k, $bug) = @_;
-
- my $cnt = 0;
- if (exists $index{$i}->{"count $k"}) {
- $cnt = unpack 'N', $index{$i}->{"count $k"};
- }
- $index{$i}->{"count $k"} = (pack 'N', 1+$cnt);
- my $which = $cnt - ($cnt % 100);
- $index{$i}->{"$which $k"} = '' unless defined $index{$i}->{"$which $k"};
- $index{$i}->{"$which $k"} .= (pack 'N', $bug);
+ my ($index, $bug, @values) = @_;
+
+ if (exists $indexes->{reverse}{"$index $bug"}) {
+ # We do this insanity to work around a "feature" in MLDBM
+ for my $key (@{$indexes->{reverse}{"$index $bug"}}) {
+ my $temp = $indexes->{$index}{$key};
+ delete $temp->{$bug};
+ $indexes->{$index}{$key} = $temp;
+ $indexes->{$index}{"count $key"}--;
+ }
+ delete $indexes->{reverse}{"$index $bug"};
+ }
+ for my $key (@values) {
+ $indexes->{$index}->{"count $key"}++;
+ # We do this insanity to work around a "feature" in MLDBM
+ my $temp = $indexes->{$index}->{$key};
+ $temp->{$bug} = 1;
+ $indexes->{$index}->{$key} = $temp;
+ }
+ $indexes->{reverse}{"$index $bug"} = [@values];