code: def _compute_node_truss_levels(graph: nx.Graph) -> dict[str, int]:
      """
      Reference:
          Burkhardt, Paul & Faber, Vance & G. Harris, David. (2018).
          Bounds and algorithms for $k$-truss.
          https://arxiv.org/abs/1806.05523v1
      """
      max_edge_ks = {}
      is_removed = collections.defaultdict(int)
      triangle_counts = {
          edge: len(
              set(graph.neighbors(edge[0]))
              & set(graph.neighbors(edge[1]))
          )
          for edge in graph.edges()
      }
      # rather than iterating over all theoretical values of k
      # let's break out early once all edges have been removed
      # max_edge_k = math.ceil(math.sqrt(len(triangle_counts)))
      # for k in range(1, max_edge_k):
      k = 1
      while True:
          to_remove = collections.deque(
              edge
              for edge, tcount in triangle_counts.items()
              if tcount < k and not is_removed[edge]
          )
          while to_remove:
              edge = to_remove.popleft()
              is_removed[edge] = 1
              for nbr in set(graph.neighbors(edge[0])) & set(
                  graph.neighbors(edge[1])
              ):
                  for node in edge:
                      nbr_edge = (node, nbr)
                      try:
                          triangle_counts[nbr_edge] -= 1
                      except KeyError:
                          # oops, gotta reverse the node ordering on this edge
                          nbr_edge = (nbr, node)
                          triangle_counts[nbr_edge] -= 1
                      if triangle_counts[nbr_edge] == k - 1:
                          to_remove.append(nbr_edge)
                          is_removed[nbr_edge] = 1
              max_edge_ks[edge] = k - 1
          # here's where we break out early, if possible
          if len(is_removed) == len(triangle_counts):
              break
          else:
              k += 1
      max_node_ks = {
          node: max(
              k for edge, k in max_edge_ks.items() if node in edge
          )
          for node in graph.nodes()
      }
      return max_node_ks
  
file_path: textacy/src/textacy/extract/keyterms/scake.py
imports: from __future__ import annotations
  import collections
  import itertools
  from operator import itemgetter
  from typing import Callable, Collection, Counter, Iterable, Optional
  import networkx
  from cytoolz import itertoolz
  from spacy.tokens import Doc, Token
  from ...None import utils
  from ..None import utils
label_desc: Use image node_id 4 for calling a global function with example usage: _compute_node_truss_levels(graph) and returns: max_node_ks