mirror of
https://github.com/KrisKennaway/ii-vision.git
synced 2024-12-21 05:30:20 +00:00
Memoize hamming_weight to optimize runtime
This commit is contained in:
parent
6de5f1797d
commit
a8688a6a7e
@ -1,12 +1,13 @@
|
||||
"""Screen module represents Apple II video display."""
|
||||
|
||||
from collections import defaultdict
|
||||
import functools
|
||||
import enum
|
||||
from typing import Set, Iterator, Union, Tuple
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
@functools.lru_cache(None)
|
||||
def hamming_weight(n: int) -> int:
|
||||
"""Compute hamming weight of 8-bit int"""
|
||||
n = (n & 0x55) + ((n & 0xAA) >> 1)
|
||||
|
Loading…
Reference in New Issue
Block a user