A Matlab Version
Just to show it's not very complicated:
function [ S ] = M_sketch(n, d, b)
S.num_buckets = 1+floor(b*d*(1+log(n)));
S.level = 1 + random('geo', 1-1/b, n);
S.sign_flip = randi(2, n)*2 - 3;
S.hash = randi(S.num_buckets, n);
end
function [ Sy ] = M_sketch_apply( S, y)
Sy = zeros(max(level), S.num_buckets);
for i=1:length(y)
li = S.level(i);
hi = S.hash(i);
Sy(li, hi) = Sy(li, hi) + y(i)*S.sign_flip(i);
end;
end
function [ est ] = M_sketch_eval( Sy, b, G )
est = 0;
for i=1:size(Sy,1)
est = est + (b^(i-1))*sum(G(Sy(i,:)));
end