def hashes(ds):
    """
    Creates a map of hashes to files and folders.
    """
    folds = [ds]
    hashes = {}
    fmap = {'files': {}, 'folders': {ds['folderid']: ds}}
    while len(folds) > 0:
        fold = folds.pop(0)
        for f in fold['contents']:
            if f['isfolder']:
                fmap['folders'][f['folderid']] = f
                folds.append(f)
            elif 'hash' in f:
                fmap['files'][f['fileid']] = f
                if f['hash'] not in hashes:
                    hashes[f['hash']] = []
                hashes[f['hash']].append(f)
    return hashes, fmap
