<commit_before>my class X::Hash::Store::OddNumber { ... }

my class EnumMap does Iterable does Associative { # declared in BOOTSTRAP
    # my class EnumMap is Iterable is Cool {
    #   has Mu $!storage;

    method new(*@args) {
        my %h := nqp::create(self);
        %h.STORE(@args) if @args;
        %h;
    }

    multi method Bool(EnumMap:D:) {
        nqp::p6bool(nqp::defined($!storage) && nqp::elems($!storage));
    }
    method elems(EnumMap:D:) {
        nqp::p6box_i(nqp::defined($!storage) && nqp::elems($!storage));
    }

    multi method ACCEPTS(EnumMap:D: Any $topic) {
        self.EXISTS-KEY($topic.any);
    }

    multi method ACCEPTS(EnumMap:D: Cool:D $topic) {
        self.EXISTS-KEY($topic);
    }

    multi method ACCEPTS(EnumMap:D: Positional $topic) {
        self.EXISTS-KEY($topic.any);
    }

    multi method ACCEPTS(EnumMap:D: Regex $topic) {
        so self.keys.any.match($topic);
    }

    multi method EXISTS-KEY(EnumMap:D: Str:D \key) {
        nqp::p6bool(
            nqp::defined($!storage)
            && nqp::existskey($!storage, nqp::unbox_s(key))
        )
    }
    multi method EXISTS-KEY(EnumMap:D: \key) {
        nqp::p6bool(
            nqp::defined($!storage)
            && nqp::existskey($!storage, nqp::unbox_s(key.Str))
        )
    }

    multi method perl(EnumMap:D:) {
        self.^name
          ~ '.new('
          ~ self.pairs.sort.map({.perl}).join(', ')
          ~ ')';
    }

    method iterator(EnumMap:) { self.pairs.iterator }
    method list(EnumMap:) { self.pairs.list }

    # XXX GLR implement these iterators
    multi method keys(EnumMap:D:) {
        nqp::die('Hash keys iterator NYI in GLR')
    }
    multi method kv(EnumMap:D:) {
        nqp::die('Hash kv iterator NYI in GLR')
    }
    multi method values(EnumMap:D:) {
        nqp::die('Hash values iterator NYI in GLR')
    }
    multi method pairs(EnumMap:D:) {
        nqp::die('Hash pairs iterator NYI in GLR')
    }
    multi method antipairs(EnumMap:D:) {
        nqp::die('Hash antipairs iterator NYI in GLR')
    }
    multi method invert(EnumMap:D:) {
        nqp::die('Hash invert iterator NYI in GLR')
    }

    multi method AT-KEY(EnumMap:D: \key) is rw {
        my str $skey = nqp::unbox_s(key.Str);
        nqp::defined($!storage) && nqp::existskey($!storage, $skey)
          ?? nqp::atkey($!storage, $skey)
          !! Any
    }

    # XXX GLR
    method STORE(\to_store) {
        nqp::die('hash store NYI after GLR');
        #my $items = (to_store,).flat.eager;
        #$!storage := nqp::hash();
        #
        #while $items {
        #    my Mu $x := $items.shift;
        #    if nqp::istype($x,Enum) { self.STORE_AT_KEY($x.key, $x.value) }
        #    elsif nqp::istype($x,EnumMap) and !nqp::iscont($x) {
        #        for $x.list { self.STORE_AT_KEY(.key, .value) }
        #    }
        #    elsif $items { self.STORE_AT_KEY($x, $items.shift) }
        #    else {
        #        nqp::istype($x,Failure)
        #          ?? $x.throw
        #          !! X::Hash::Store::OddNumber.new.throw;
        #    }
        #}
        #self
    }

    proto method STORE_AT_KEY(|) is rw { * }
    multi method STORE_AT_KEY(Str \key, Mu \value) is rw {
        nqp::defined($!storage) ||
            nqp::bindattr(self, EnumMap, '$!storage', nqp::hash());
        nqp::bindkey($!storage, nqp::unbox_s(key), value)
    }
    multi method STORE_AT_KEY(\key, Mu \value) is rw {
        nqp::defined($!storage) ||
            nqp::bindattr(self, EnumMap, '$!storage', nqp::hash());
        nqp::bindkey($!storage, nqp::unbox_s(key.Str), value)
    }

    method Capture(EnumMap:D:) {
        my $cap := nqp::create(Capture);
        nqp::bindattr($cap, Capture, '$!hash', $!storage);
        $cap
    }

    method FLATTENABLE_LIST() { nqp::list() }<commit_msg>Re-implement storing into a hash.<commit_after>my class X::Hash::Store::OddNumber { ... }

my class EnumMap does Iterable does Associative { # declared in BOOTSTRAP
    # my class EnumMap is Iterable is Cool {
    #   has Mu $!storage;

    method new(*@args) {
        my %h := nqp::create(self);
        %h.STORE(@args) if @args;
        %h;
    }

    multi method Bool(EnumMap:D:) {
        nqp::p6bool(nqp::defined($!storage) && nqp::elems($!storage));
    }
    method elems(EnumMap:D:) {
        nqp::p6box_i(nqp::defined($!storage) && nqp::elems($!storage));
    }

    multi method ACCEPTS(EnumMap:D: Any $topic) {
        self.EXISTS-KEY($topic.any);
    }

    multi method ACCEPTS(EnumMap:D: Cool:D $topic) {
        self.EXISTS-KEY($topic);
    }

    multi method ACCEPTS(EnumMap:D: Positional $topic) {
        self.EXISTS-KEY($topic.any);
    }

    multi method ACCEPTS(EnumMap:D: Regex $topic) {
        so self.keys.any.match($topic);
    }

    multi method EXISTS-KEY(EnumMap:D: Str:D \key) {
        nqp::p6bool(
            nqp::defined($!storage)
            && nqp::existskey($!storage, nqp::unbox_s(key))
        )
    }
    multi method EXISTS-KEY(EnumMap:D: \key) {
        nqp::p6bool(
            nqp::defined($!storage)
            && nqp::existskey($!storage, nqp::unbox_s(key.Str))
        )
    }

    multi method perl(EnumMap:D:) {
        self.^name
          ~ '.new('
          ~ self.pairs.sort.map({.perl}).join(', ')
          ~ ')';
    }

    method iterator(EnumMap:) { self.pairs.iterator }
    method list(EnumMap:) { self.pairs.list }

    # XXX GLR implement these iterators
    multi method keys(EnumMap:D:) {
        nqp::die('Hash keys iterator NYI in GLR')
    }
    multi method kv(EnumMap:D:) {
        nqp::die('Hash kv iterator NYI in GLR')
    }
    multi method values(EnumMap:D:) {
        nqp::die('Hash values iterator NYI in GLR')
    }
    multi method pairs(EnumMap:D:) {
        nqp::die('Hash pairs iterator NYI in GLR')
    }
    multi method antipairs(EnumMap:D:) {
        nqp::die('Hash antipairs iterator NYI in GLR')
    }
    multi method invert(EnumMap:D:) {
        nqp::die('Hash invert iterator NYI in GLR')
    }

    multi method AT-KEY(EnumMap:D: \key) is rw {
        my str $skey = nqp::unbox_s(key.Str);
        nqp::defined($!storage) && nqp::existskey($!storage, $skey)
          ?? nqp::atkey($!storage, $skey)
          !! Any
    }

    # XXX GLR
    method STORE(\to_store) {
        my \iter = nqp::istype(to_store, Iterable)
            ?? to_store.iterator
            !! to_store.list.iterator;
        $!storage := nqp::hash();
        until (my Mu $x := iter.pull-one) =:= IterationEnd {
            if nqp::istype($x,Enum) {
                self.STORE_AT_KEY($x.key, $x.value)
            }
            elsif nqp::istype($x, EnumMap) and !nqp::iscont($x) {
                for $x.list { self.STORE_AT_KEY(.key, .value) }
            }
            elsif (my Mu $y := iter.pull-one) !=:= IterationEnd {
                self.STORE_AT_KEY($x, $y)
            }
            else {
                nqp::istype($x,Failure)
                  ?? $x.throw
                  !! X::Hash::Store::OddNumber.new.throw;
            }
        }
        self
    }

    proto method STORE_AT_KEY(|) is rw { * }
    multi method STORE_AT_KEY(Str \key, Mu \value) is rw {
        nqp::defined($!storage) ||
            nqp::bindattr(self, EnumMap, '$!storage', nqp::hash());
        nqp::bindkey($!storage, nqp::unbox_s(key), value)
    }
    multi method STORE_AT_KEY(\key, Mu \value) is rw {
        nqp::defined($!storage) ||
            nqp::bindattr(self, EnumMap, '$!storage', nqp::hash());
        nqp::bindkey($!storage, nqp::unbox_s(key.Str), value)
    }

    method Capture(EnumMap:D:) {
        my $cap := nqp::create(Capture);
        nqp::bindattr($cap, Capture, '$!hash', $!storage);
        $cap
    }

    method FLATTENABLE_LIST() { nqp::list() }
{'fraction_non_alphanumeric': 0.16411378555798686, 'fraction_numerical': 0.0010297335564422706, 'mean_word_length': 2.1662591687041566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '70995', 'n_tokens_mistral': 2816, 'n_tokens_neox': 2733, 'n_words': 527}