Exemplo n.º 1
0
def display_cache(cache):

    table = Table(
        num_cols=len(cache), width=TABLE_WIDTH, alignment='center')
    table.title = 'Cache'

    cache_set_names = sorted(cache.keys())
    # A cache containing only one set is considered a fully associative cache
    if len(cache) != 1:
        # Display set names in table header if cache is not fully associative
        table.header[:] = cache_set_names

    # Add to table the cache entries for each block
    table.rows.append([])
    for index in cache_set_names:
        blocks = cache[index]
        table.rows[0].append(
            ' '.join(','.join(map(str, entry['data'])) for entry in blocks))

    print(table)