TYPEMAP
optionblk   T_PTROBJ_OPTIONBLK
sparsegraph T_PTROBJ_SPARSEGRAPH
statsblk    T_PTROBJ_STATSBLK
int       * SPECIAL_INT

INPUT
SPECIAL_INT
    $var = malloc( sizeof(int) * (av_len((AV*)SvRV($arg))+1) );
    ssize_t ix_$var;
    for( ix_$var = 0; ix_$var < av_len((AV*)SvRV($arg))+1; ix_$var++ ) {
        $var [ix_$var] = (int)SvIV(*av_fetch((AV*)SvRV($arg), ix_$var, 0));
    }
T_PTROBJ_SPARSEGRAPH
    STMT_START {
        if( SvOK($arg) ) {
            int vertices_$var = (int)SvIV(*hv_fetch((HV*)SvRV($arg), \"nv\", 2, 0));
            int edges_$var    = (size_t)SvIV(*hv_fetch((HV*)SvRV($arg), \"nde\", 3, 0));

            SG_INIT( $var );
            SG_ALLOC( $var, vertices_$var, edges_$var, \"malloc\" );

            $var.nde = edges_$var;
            $var.nv  = vertices_$var;

            SV *v = (SV*)*hv_fetch((HV*)SvRV($arg), \"v\", 1, 0);
            SV *d = (SV*)*hv_fetch((HV*)SvRV($arg), \"d\", 1, 0);
            SV *e = (SV*)*hv_fetch((HV*)SvRV($arg), \"e\", 1, 0);

            size_t ix_$var;
            for( ix_$var = 0; ix_$var < $var.vlen; ix_$var++ ) {
                $var.v[ix_$var] = (size_t)SvIV(*av_fetch((AV*)SvRV(v), ix_$var, 0));
            }
            for( ix_$var = 0; ix_$var < $var.dlen; ix_$var++ ) {
                $var.d[ix_$var] = (int)SvIV(*av_fetch((AV*)SvRV(d), ix_$var, 0));
            }
            for( ix_$var = 0; ix_$var < $var.elen; ix_$var++ ) {
                $var.e[ix_$var] = (int)SvIV(*av_fetch((AV*)SvRV(e), ix_$var, 0));
            }
        }
    } STMT_END
T_PTROBJ_OPTIONBLK
    DEFAULTOPTIONS_SPARSEGRAPH( new_$var );
    $var = new_$var;
    $var.defaultptn = FALSE;
    if( SvOK($arg) ) {
        if( hv_exists((HV*)SvRV($arg), \"getcanon\", 8) ) {
            $var.getcanon = TRUE;
        }
    }