Finish 2000-03-27 00:00:00 UTC

linetest_salt

by G Hunyadi

Status: Failed
Results: []

Based on: Salt12 (diff)

Comments
Please login or create a profile.
Code
function Sequence = GFD4(Segments)

[nSegs, lSegs] = size(Segments);

[sums is]  = sort( Segments * rand(lSegs,1) )  ;
sums(nSegs+1) = 0;
Segments = Segments(is(diff(sums)~=0),:);
[nSegs, lSegs] = size(Segments);

theSegments = cell(nSegs, 1);

for index = 1:nSegs;
   theSegments{index} = Segments(index, :);
end
copySegments = theSegments;

EndPart = 2-lSegs:0;
for matchLength = lSegs-1:-1:1
   Segments(:, 1) = [];
   for leftSeg = theSegs
      Match = find(strncmp(Segments(leftSeg, :), copySegments, matchLength));
      if Match
         Select = Match(1);
         rightSeg = theSegs(Select);
         if rightSeg == leftSeg 
            if length(Match) > 1 % Rare case
               temp = Match(Match ~= Select);
               Select = temp(1);
               rightSeg = theSegs(Select); 
               
               theSegments{rightSeg} = [theSegments{leftSeg} theSegments{rightSeg}(1+matchLength:end)];
               i = find(theSegs == leftSeg);
               theSegs(i) = [];
               if length(theSegs) == 1 
                  Sequence = [theSegments{theSegs}];
                  return;
               end
               copySegments(Select) = copySegments(i);
               copySegments(i) = [];
               end
         else
            theSegments{rightSeg} = [theSegments{leftSeg} theSegments{rightSeg}(1+matchLength:end)];
            i = find(theSegs == leftSeg);
            theSegs(i) = [];
            if length(theSegs) == 1 
               Sequence = [theSegments{theSegs}];
               return;
            end
            copySegments(Select) = copySegments(i);
            copySegments(i) = [];
         end
      end
   end
   EndPart(1) = [];   
end
Sequence = [theSegments{theSegs}];