+void
+scale(SV *csv, SV *sv)
+PROTOTYPE: $;$
+PREINIT:
+ HV *hv, *res;
+ HE *key;
+ SV *val;
+ NV c = 1;
+CODE:
+ if (!SvOK(sv))
+ XSRETURN_UNDEF;
+ if (SvOK(csv))
+ c = SvNV(csv);
+ res = newHV();
+ if (!SvROK(sv)) {
+ val = newSVnv(c);
+ if (!hv_store_ent(res, sv, val, 0))
+ SvREFCNT_dec(val);
+ } else {
+ hv = (HV *) SvRV(sv);
+ if (!hv_iterinit(hv)) {
+ val = newSVnv(c);
+ if (!hv_store(res, "0", 1, val, 0))
+ SvREFCNT_dec(val);
+ } else {
+ hv_iterinit(hv);
+ while (key = hv_iternext(hv)) {
+ val = newSVnv(SvNV(HeVAL(key)) * c);
+ if (!hv_store_ent(res, HeSVKEY_force(key), val, HeHASH(key)))
+ SvREFCNT_dec(val);
+ }
+ }
+ }
+ ST(0) = sv_2mortal(newRV_noinc((SV *) res));
+ XSRETURN(1);
+