public NFCompressedGraph buildGraph() {
    for (String nodeType : graphSpec.getNodeTypes()) {
      NFBuildGraphNodeList nodeOrdinals = buildGraphNodeCache.getNodes(nodeType);
      addNodeType(nodeType, nodeOrdinals);
    }

    return new NFCompressedGraph(
        graphSpec,
        modelHolder,
        graphBuffer.getData(),
        graphBuffer.length(),
        compressedGraphPointers);
  }
  private void addNodeType(String nodeType, NFBuildGraphNodeList nodes) {
    NFNodeSpec nodeSpec = graphSpec.getNodeSpec(nodeType);
    long ordinalPointers[] = new long[nodes.size()];

    for (int i = 0; i < nodes.size(); i++) {
      NFBuildGraphNode node = nodes.get(i);
      if (node != null) {
        ordinalPointers[i] = graphBuffer.length();
        serializeNode(node, nodeSpec);
      } else {
        ordinalPointers[i] = -1;
      }
    }

    compressedGraphPointers.addPointers(nodeType, ordinalPointers);
  }