code: def hash_path(
      path,
      algorithm="blake2b",
      suffix_len=None,
      num_orig_chars=None,
      constant_len=False,
  ):
      # pylint: disable=missing-function-docstring
      path = Path(path)
      if suffix_len is None:
          suffix_len = len(path.suffix)
      stem = str(path.stem)
      replaced_stem = stem.replace(" ", "_")
      replaced_stem = replaced_stem.replace("-", "_")
      filtered_stem = non_word_pattern.sub("", replaced_stem)
      if len(filtered_stem) == len(stem):
          return replaced_stem
  
      path = str(path)
      if algorithm == "blake2b":
          # Using blake2b by default since it is fast and as good as sha-3: https://blake2.net/
          hashstr = hashlib.blake2b(
              path.encode(), digest_size=16
          ).hexdigest()
      elif algorithm == "md5":
          hashstr = hashlib.md5(path.encode()).hexdigest()
      else:
          raise ValueError("Unsupported algorithm {}".format(algorithm))
  
      # 1 for underscore between
      max_orig_chars = PATH_MAXLEN - (len(hashstr) + 1) - suffix_len
  
      orig_take_chars = (
          max_orig_chars
          if num_orig_chars is None
          else min(num_orig_chars, max_orig_chars)
      )
      if orig_take_chars > 0:
          trunc_stem = filtered_stem[:orig_take_chars]
          if num_orig_chars and constant_len:
              trunc_stem = trunc_stem.ljust(orig_take_chars, "_")
          new_stem = "{}_{}".format(trunc_stem, hashstr)
      else:
          new_stem = hashstr
  
      return new_stem
  
file_path: gluon-cv/gluoncv/torch/data/gluoncv_motion_dataset/ingestion/filename_sanitizer.py
imports: import logging
  import os
  import hashlib
  import re
  from pathlib import Path
  import tqdm
  from ..dataset import GluonCVMotionDataset
  from ..utils.serialization_utils import save_json
label_desc: Use image node_id 1 for calling a global function with example usage: hash_path(path, algorithm, suffix_len, num_orig_chars, constant_len) and returns: new_stem, replaced_stem