code: private IntIntHashMap computeInlinkCount(final FSA fsa) {
      IntIntHashMap inlinkCount = new IntIntHashMap();
      BitSet visited = new BitSet();
      IntStack nodes = new IntStack();
      nodes.push(fsa.getRootNode());
  
      while (!nodes.isEmpty()) {
        final int node = nodes.pop();
        if (visited.get(node))
          continue;
  
        visited.set(node);
  
        for (int arc = fsa.getFirstArc(node); arc != 0; arc = fsa.getNextArc(arc)) {
          if (!fsa.isArcTerminal(arc)) {
            final int target = fsa.getEndNode(arc);
            inlinkCount.putOrAdd(target, 1, 1);
            if (!visited.get(target))
              nodes.push(target);
          }
        }
      }
  
      return inlinkCount;
    }
docs: Compute in-link count for each state.