# Path: opc/utils/prof.py
# def timefunc(f, reference=False):
#     global records
# 
#     records[f.__name__] = Record(f.__name__, reference)
# 
#     @wraps(f)
#     def f_timer(*args, **kwargs):
#         global active
# 
#         if not active:
#             return f(*args, **kwargs)
# 
#         start = time.time()
#         result = f(*args, **kwargs)
#         end = time.time()
# 
#         records[f.__name__].addTime(end-start)
# 
#         return result
# 
#     return f_timer


from random import random
from opc.utils.prof import timefunc

# implementation of a linear feedback shift register generator that gives us
# n-bits of pseudo-random values, completing the entire sequence before
# repeating.

# polynomials required to calculate a n-bit lsfr. Higher bits are
# available, just not included here yet.
poly = {
    2:  (2, 1),
    3:  (3, 2),
    4:  (4, 3),
    5:  (5, 3),
    6:  (6, 5),
    7:  (7, 6),
    8:  (8, 6, 5, 4),
    9:  (9, 5),
    10: (10, 7),
    11: (11, 9),
    12: (12, 11, 14),
    13: (13, 12, 11, 8),
    14: (14, 13, 12, 2),
    15: (15, 14),
    16: (16, 14, 13, 11),
    }


def bit(value, bit):
    return (value >> bit) & 1



# Path: opc/utils/prof.py
# def timefunc(f, reference=False):
#     global records
# 
#     records[f.__name__] = Record(f.__name__, reference)
# 
#     @wraps(f)
#     def f_timer(*args, **kwargs):
#         global active
# 
#         if not active:
#             return f(*args, **kwargs)
# 
#         start = time.time()
#         result = f(*args, **kwargs)
#         end = time.time()
# 
#         records[f.__name__].addTime(end-start)
# 
#         return result
# 
#     return f_timer


# Path: art/utils/lfsr.py
from random import random
from opc.utils.prof import timefunc


# implementation of a linear feedback shift register generator that gives us
# n-bits of pseudo-random values, completing the entire sequence before
# repeating.

# polynomials required to calculate a n-bit lsfr. Higher bits are
# available, just not included here yet.
poly = {
    2:  (2, 1),
    3:  (3, 2),
    4:  (4, 3),
    5:  (5, 3),
    6:  (6, 5),
    7:  (7, 6),
    8:  (8, 6, 5, 4),
    9:  (9, 5),
    10: (10, 7),
    11: (11, 9),
    12: (12, 11, 14),
    13: (13, 12, 11, 8),
    14: (14, 13, 12, 2),
    15: (15, 14),
    16: (16, 14, 13, 11),
    }


def bit(value, bit):
    return (value >> bit) & 1



@timefunc