header_adjacency.m 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. function [A,H,f2H] = header_adjacency(files)
  2. % HEADER_ADJACENCY given a list of .cpp/.h files find all <igl/*.h> header
  3. % files and determine mutual inclusions.
  4. %
  5. % Inputs:
  6. % files list of .cpp/.h files
  7. % Outputs:
  8. % A adjacency matrix so that A(i,j) is the number of mutual includes for
  9. % H(i) and H(j)
  10. % H list of unique headers
  11. %
  12. % Example:
  13. % files = textscan([ ...
  14. % ls('/some/dir/*.cpp') ...
  15. % ls('/some/dir/*.h')],'%s', 'delimiter', '\n' );
  16. % files = files{1};
  17. % [A,H] = header_adjacency(files);
  18. %
  19. mH = containers.Map();
  20. f2HI = [];
  21. f2HJ = [];
  22. for f = 1:numel(files)
  23. if isempty(regexp(files{f},'include/igl/[^/]*$'))
  24. fH = regexp(fileread(files{f}),'<igl/([^.]*.h)>','tokens');
  25. else
  26. fH = regexp(fileread(files{f}),'"([^.]*.h)"','tokens');
  27. end
  28. fH = [fH{:}]';
  29. for h = 1:numel(fH)
  30. h_str = fH{h};
  31. if ~mH.isKey(h_str)
  32. mH(h_str) = mH.size(1) + 1;
  33. end
  34. f2HI = [f2HI(:); f];
  35. f2HJ = [f2HJ(:); mH(h_str)];
  36. end
  37. end
  38. f2H = sparse(f2HI,f2HJ,1,numel(files),mH.size(1));
  39. A = f2H'*f2H;
  40. % diagonal is not interesting
  41. A = A - diag(diag(A));
  42. keys = mH.keys;
  43. values = mH.values;
  44. values = [values{:}];
  45. [~,I] = sort(values);
  46. H = keys(I);
  47. end