anchor.diff:      end,
       PL).
   
  -aggr(Inds,List) ->
  +aggr(IndexTags,List) ->
  +  Inds = [tag2index(T) || T <- IndexTags],
     lists:foldl(mkaggfun(Inds),[],lists:sort(mksortfun(Inds),List)).
  +
  +columns() -> [what,allocd,used,frac].
  +indices() -> [allocator,instance,group,type,info].
  +
  +column2index(X) -> x2index(X,columns()).
  +tag2index(X) -> x2index(X,indices()).
  +
  +x2index(X,Xs) -> x2index(X,Xs,1).
  +x2index(X,[X|_],N) -> N;
  +x2index(X,[_|Xs],N) -> x2index(X,Xs,N+1).
   
   mkaggfun(Inds) ->
     fun({K,V},[]) -> [{mknewkey(K,Inds),V}];
  
positive.code: %%% Created : 21 Aug 2014 by  <masse@klarna.com>
  
  %% @doc
  %% @end
  
  -module('atop').
  
negative.code: -export([aggregate/0,aggregate/1,aggregate/2]).
  
  aggregate() ->
    aggregate(indices()--[instance]).
  aggregate(AggregateIndices) ->
    aggregate(AggregateIndices,[]).
  aggregate(AggregateIndices,FilterTags) ->
    aggr(
      AggregateIndices,
      filter(
        FilterTags,
        getallocdata())).
  
  allocs() ->
    allocs(allocd).
  allocs(SortCol) ->
    allocs(SortCol,[allocator,group]).
  allocs(SortCol,AggregateIndices) ->
    printh(AggregateIndices,columns()),
    lists:foreach(
      fun print/1,
      lists:reverse(
        lists:keysort(
          column2index(SortCol),
          lists:foldl(
            fun present/2,
            [],
            filter(
              [size],
              aggr(
                AggregateIndices++[type,info],
                getallocdata())))))).
  
  printh(AggInds,Cols) ->
    io:fwrite("~-33w~8w~8w~8w~n",[AggInds]++tl(Cols)).
  print({K,T,U,F}) ->
    io:fwrite("~-33w~8.2f~8.2f~8.2f~n",[K,T,U,F]).
  
  