Algorithm-MarkovChain-GHash

 view release on metacpan or  search on metacpan

GHash.pm  view on Meta::CPAN

See L<Algorithm::MarkovChain> for full details

=head1 DESCRIPTION

This module implements glib storage for Algorithm::MarkovChain.

You'll need C<glib> installed to make this happy.

=head1 HISTORY

This was originally written using Inline, but never released due to
lack of round tuits.  Recently a tuit supply arrived so I converted it
into XS to reduce dependencies.

=head1 BUGS

None known, maybe after I write some tests.

=head1 AUTHOR

Richard Clamp <richardc@unixbeard.net>

GHash.xs  view on Meta::CPAN


   g_hash_table_foreach(im->dictionary, free_key, NULL);
   g_hash_table_foreach(im->chains, free_chain, NULL);
   g_hash_table_destroy(im->dictionary);
   g_hash_table_destroy(im->chains);
   g_free(im);
}


void 
increment_seen(obj, stub, original_next)
    SV* obj;
    char *stub;
    char *original_next;
  CODE:
{
    IM* im       = (IM*) SvIV(phash_value(SvRV(obj), "_cstuff"));
    chain_t* stubs = g_hash_table_lookup(im->chains, stub);
    int count;

    char* next = g_hash_table_lookup(im->dictionary, original_next);

    /* printf("increment_seen: '%s' '%s'\n", stub, original_next); */

    if (!next) {
        next = g_strdup(original_next);
        g_hash_table_insert(im->dictionary, next, next);
    }

    if (!stubs) {
        char* sep = SvPV_nolen(phash_value(SvRV(obj), "seperator"));
        char* s;
        int len = 1;

        for (s = stub; s = strstr(s, sep); s += strlen(sep)) len++;
        if (len > im->longest) {



( run in 1.066 second using v1.01-cache-2.11-cpan-1c8d708658b )