<commit_before>my role Baggy does QuantHash {
    has %!elems; # key.WHICH => (key,value)

    method PAIR(\key) { Pair.new(key, my Int $ = 0 ) }
    method SANITY(%elems --> Nil) {
        my @toolow;
        for %elems -> $p {
            my $pair  := $p.value;
            my $value := $pair.value;
            @toolow.push( $pair.key ) if $value <  0;
            %elems.DELETE-KEY($p.key) if $value <= 0;
        }
        fail "Found negative values for {@toolow} in {self.^name}" if @toolow;
    }
    multi method new(Baggy: +@args) {
        my %elems;
        for @args {
            (%elems{.WHICH} //= self.PAIR($_)).value++
        } 
        nqp::create(self).BUILD(%elems)
    }
    method new-from-pairs(*@pairs) {
        my %elems;
        for @pairs {
            when Pair {
                (%elems.AT-KEY(.key.WHICH) //= self.PAIR(.key)).value += .value;
            }
            default {
                (%elems.AT-KEY(.WHICH) //= self.PAIR($_)).value++;
            }
        }
        self.SANITY(%elems);
        nqp::create(self).BUILD(%elems)
    }

    method default(--> Int) { 0 }

    multi method pairs(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            method pull-one() {
                $!hash-iter
                  ?? nqp::iterval(nqp::shift($!hash-iter))
                  !! IterationEnd
            }
            method push-all($target) {
                $target.push(nqp::iterval(nqp::shift($!hash-iter)))
                  while $!hash-iter;
                IterationEnd
            }
        }.new(%!elems))
    }
    multi method keys(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            method pull-one() {
                $!hash-iter
                  ?? nqp::iterval(nqp::shift($!hash-iter)).key
                  !! IterationEnd
            }
            method push-all($target) {
                $target.push(nqp::iterval(nqp::shift($!hash-iter)).key)
                  while $!hash-iter;
                IterationEnd
            }
        }.new(%!elems))
    }
    multi method kv(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            has Mu $!value;

            method pull-one() is raw {
                if $!value.DEFINITE {
                    my \tmp  = $!value;
                    $!value := Mu;
                    tmp
                }
                elsif $!hash-iter {
                    my \tmp =
                      nqp::decont(nqp::iterval(nqp::shift($!hash-iter)));
                    $!value := nqp::getattr(tmp,Pair,'$!value');
                    nqp::getattr(tmp,Pair,'$!key')
                }
                else {
                    IterationEnd
                }
            }
            method push-all($target) {
                while $!hash-iter {
                    my \tmp =
                      nqp::decont(nqp::iterval(nqp::shift($!hash-iter)));
                    $target.push(nqp::getattr(tmp,Pair,'$!key'));
                    $target.push(nqp::getattr(tmp,Pair,'$!value'));
                }
                IterationEnd
            }
        }.new(%!elems))
    }
    multi method values(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            method pull-one() is raw {
                $!hash-iter
                    ?? nqp::getattr(nqp::decont(
                         nqp::iterval(nqp::shift($!hash-iter))),Pair,'$!value')
                    !! IterationEnd
            }
            method push-all($target) {
                $target.push(nqp::getattr(nqp::decont(
                  nqp::iterval(nqp::shift($!hash-iter))),Pair,'$!value'
                )) while $!hash-iter;
                IterationEnd
            }
        }.new(%!elems))
    }
    multi method antipairs(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            method pull-one() {
                if $!hash-iter {
                    my \tmp = nqp::iterval(nqp::shift($!hash-iter));
                    Pair.new(tmp.value, tmp.key)
                }
                else {
                    IterationEnd
                }
            }
            method push-all($target) {
                while $!hash-iter {
                    my \tmp = nqp::iterval(nqp::shift($!hash-iter));
                    $target.push(Pair.new(tmp.value, tmp.key));
                }
                IterationEnd
            }
        }.new(%!elems))
    }
    method kxxv(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            has Mu $!key;
            has int $!times;

            method pull-one() is raw {
                if $!times {
                    $!times = $!times - 1;
                    $!key
                }<commit_msg>Baggy keys/values/pairs/kv get push-exactly<commit_after>my role Baggy does QuantHash {
    has %!elems; # key.WHICH => (key,value)

    method PAIR(\key) { Pair.new(key, my Int $ = 0 ) }
    method SANITY(%elems --> Nil) {
        my @toolow;
        for %elems -> $p {
            my $pair  := $p.value;
            my $value := $pair.value;
            @toolow.push( $pair.key ) if $value <  0;
            %elems.DELETE-KEY($p.key) if $value <= 0;
        }
        fail "Found negative values for {@toolow} in {self.^name}" if @toolow;
    }
    multi method new(Baggy: +@args) {
        my %elems;
        for @args {
            (%elems{.WHICH} //= self.PAIR($_)).value++
        } 
        nqp::create(self).BUILD(%elems)
    }
    method new-from-pairs(*@pairs) {
        my %elems;
        for @pairs {
            when Pair {
                (%elems.AT-KEY(.key.WHICH) //= self.PAIR(.key)).value += .value;
            }
            default {
                (%elems.AT-KEY(.WHICH) //= self.PAIR($_)).value++;
            }
        }
        self.SANITY(%elems);
        nqp::create(self).BUILD(%elems)
    }

    method default(--> Int) { 0 }

    multi method pairs(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            method pull-one() {
                $!hash-iter
                  ?? nqp::iterval(nqp::shift($!hash-iter))
                  !! IterationEnd
            }
            method push-exactly($target, int $n) {
                my int $done;
                while $!hash-iter {
                    $target.push(nqp::iterval(nqp::shift($!hash-iter)));
                    return $done unless ($done = $done + 1) < $n;
                }
                IterationEnd
            }
            method push-all($target) {
                $target.push(nqp::iterval(nqp::shift($!hash-iter)))
                  while $!hash-iter;
                IterationEnd
            }
        }.new(%!elems))
    }
    multi method keys(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            method pull-one() {
                $!hash-iter
                  ?? nqp::iterval(nqp::shift($!hash-iter)).key
                  !! IterationEnd
            }
            method push-exactly($target, int $n) {
                my int $done;
                while $!hash-iter {
                    $target.push(nqp::iterval(nqp::shift($!hash-iter)).key);
                    return $done unless ($done = $done + 1) < $n;
                }
                IterationEnd
            }
            method push-all($target) {
                $target.push(nqp::iterval(nqp::shift($!hash-iter)).key)
                  while $!hash-iter;
                IterationEnd
            }
        }.new(%!elems))
    }
    multi method kv(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            has Mu $!value;

            method pull-one() is raw {
                if $!value.DEFINITE {
                    my \tmp  = $!value;
                    $!value := Mu;
                    tmp
                }
                elsif $!hash-iter {
                    my \tmp =
                      nqp::decont(nqp::iterval(nqp::shift($!hash-iter)));
                    $!value := nqp::getattr(tmp,Pair,'$!value');
                    nqp::getattr(tmp,Pair,'$!key')
                }
                else {
                    IterationEnd
                }
            }
            method push-exactly($target, int $n) {
                my int $done;
                while $!hash-iter {
                    my \tmp =
                      nqp::decont(nqp::iterval(nqp::shift($!hash-iter)));
                    $target.push(nqp::getattr(tmp,Pair,'$!key'));
                    $target.push(nqp::getattr(tmp,Pair,'$!value'));
                    return $done unless ($done = $done + 1) < $n;
                }
                IterationEnd
            }
            method push-all($target) {
                while $!hash-iter {
                    my \tmp =
                      nqp::decont(nqp::iterval(nqp::shift($!hash-iter)));
                    $target.push(nqp::getattr(tmp,Pair,'$!key'));
                    $target.push(nqp::getattr(tmp,Pair,'$!value'));
                }
                IterationEnd
            }
        }.new(%!elems))
    }
    multi method values(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            method pull-one() is raw {
                $!hash-iter
                    ?? nqp::getattr(nqp::decont(
                         nqp::iterval(nqp::shift($!hash-iter))),Pair,'$!value')
                    !! IterationEnd
            }
            method push-exactly($target, int $n) {
                my int $done;
                while $!hash-iter {
                    $target.push(nqp::getattr(nqp::decont(
                      nqp::iterval(nqp::shift($!hash-iter))),Pair,'$!value'));
                    return $done unless ($done = $done + 1) < $n;
                }
                IterationEnd
            }
            method push-all($target) {
                $target.push(nqp::getattr(nqp::decont(
                  nqp::iterval(nqp::shift($!hash-iter))),Pair,'$!value'
                )) while $!hash-iter;
                IterationEnd
            }
        }.new(%!elems))
    }
    multi method antipairs(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            method pull-one() {
                if $!hash-iter {
                    my \tmp = nqp::iterval(nqp::shift($!hash-iter));
                    Pair.new(tmp.value, tmp.key)
                }
                else {
                    IterationEnd
                }
            }
            method push-exactly($target, int $n) {
                my int $done;
                while $!hash-iter {
                    my \tmp = nqp::iterval(nqp::shift($!hash-iter));
                    $target.push(Pair.new(tmp.value, tmp.key));
                    return $done unless ($done = $done + 1) < $n;
                }
                IterationEnd
            }
            method push-all($target) {
                while $!hash-iter {
                    my \tmp = nqp::iterval(nqp::shift($!hash-iter));
                    $target.push(Pair.new(tmp.value, tmp.key));
                }
                IterationEnd
            }
        }.new(%!elems))
    }
    method kxxv(Baggy:D:) {
        Seq.new(class :: does Rakudo::Internals::MapIterator {
            has Mu $!key;
            has int $!times;

            method pull-one() is raw {
                if $!times {
                    $!times = $!times - 1;
                    $!key
                }
{'fraction_non_alphanumeric': 0.1479516395581456, 'fraction_numerical': 0.0013046881795250936, 'mean_word_length': 1.181369759059002, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1500923', 'n_tokens_mistral': 3591, 'n_tokens_neox': 3347, 'n_words': 558}