function minhash_signatures=calculate_all_minhash(K)
  % the input matrix K is a characteristic matrix
  % its number of rows equals the number of possible items
  % its number of columns equals the number of sets represented

  [n_items, n_sets] = size(K);
  permutations = perms(1:n_items);
  minhash_signatures = Inf*ones(size(permutations, 1), n_sets);

  for perm_id=1:size(permutations, 1)
    % systematically generate all possible row index permutations
    % this is highly inefficient and we normally randomly rample from them
    permutation = permutations(perm_id,:);
    % perform the physical row pertmutations
    % this is also highly inefficient, in reality we use virtual row permutations
    permuted_K = K(permutation, :);
    for row_id=1:n_items
      for s=find(permuted_K(row_id,:)==1)
        minhash_signatures(perm_id, s) = min(row_id, minhash_signatures(perm_id, s));
      endfor
    endfor
    fprintf('====row permutation %d====\n', perm_id)
    display(permutation)
    display(minhash_signatures(perm_id, :))
  end
endfunction
