% merge_equal_perm( p1, p2, pp1, pp2) - check path_index equality for merging, for K > 1
%
% p1 and p2 are path_index vectors.
% pp1 and pp2 are perm_index vectors.
%
function r = merge_equal_perm( p1, p2, pp1, pp2)

global K;
global combos;
global DEBUG;
global MM_max;

ZZ...

% if( DEBUG) disp('merge_equal'), p1, p2, end;

n = length(p1);

r = 0;		% return value

% last index <= MM_max must be equal
%
for i=n:-1:1
  if( p1(i) ~= p2(i))
    return;
  end
  if( p1(i) <= MM_max)
    break;
  end
end

count = 0;	% count mismatches

for j=1:i-1
  if( p1(j) ~= p2(j))
    count = count + 1;
  end
end

% less than 2 mismatches ==>> equal
%
if( count < 2)
  r = 1;
end
