[metapost] memory problem

Stephan Hennig mailing_list at arcor.de
Mon May 8 00:06:24 CEST 2006


Denis.Roegel at loria.fr schrieb:

> Stefan's initial (and perhaps non realistic) example

For a realistic example: the following code draws a binary tree of depth
3 (15 nodes) and runs for seconds! Running time for drawing a tree of
depth 4 with a tremendous number of 31 nodes is beyond my tolerance.
Could people in the 80ies perhaps have saved years waiting for fonts
being rendered if MetaFont's code were a bit more optimized? :)

Regards,
Stephan Hennig


input metaobj
prologues := 1;

numeric nodes[];
numeric tree[];

def buildTree(expr i, dp) =
begingroup
  if dp > 0:
    buildTree(2i, dp-1);
    buildTree(2i+1, dp-1);
    newBox.nodes[i](decimal i);
    newTree.tree[i](nodes[i])(tree[2i], tree[2i+1]);
  else:
    newBox.tree[i](decimal i);
  fi
endgroup;
enddef;

setObjectDefaultOption("Box")("dx")(10bp);
setObjectDefaultOption("Box")("dy")(5bp);
setObjectDefaultOption("Box")("rbox_radius")(2mm);

depth := 3;
beginfig(1);
  buildTree(1, depth);
  tree[1].sw = origin;
  drawObj(tree[1]);
endfig;
end


More information about the metapost mailing list