import json


def already_run(db, configuration):
    """Checks whether the given configuration is already present in the database"""
    configuration = configuration.copy()
    configuration['threads'] = configuration.get('threads', 1)
    configuration['params']['threads'] = configuration.get('threads', 1)
    configuration['params'] = json.dumps(configuration['params'], sort_keys=True)
    res = db.execute("""
    SELECT rowid FROM main 
    WHERE dataset = :dataset
      AND workload = :workload
      AND threads = :threads
      AND k = :k
      AND algorithm = :algorithm
      AND params = :params
    """, configuration).fetchall()
    return len(res) > 0