import hashlib


def hash_ecfp(ecfp, size):
  """
  Returns an int < size representing given ECFP fragment.

  Input must be a string. This utility function is used for various
  ECFP based fingerprints.

  Parameters
  ----------
  ecfp: str
    String to hash. Usually an ECFP fragment.
  size: int, optional (default 1024)
    Hash to an int in range [0, size) 
  """
  ecfp = ecfp.encode('utf-8')
  md5 = hashlib.md5()
  md5.update(ecfp)
  digest = md5.hexdigest()
  ecfp_hash = int(digest, 16) % (size)
  return (ecfp_hash)