From 2ce44da34b4b61558c7438f8e1a2db2e48d22196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B3=84=EB=8B=98?= Date: Thu, 30 Apr 2015 13:48:36 +0900 Subject: [PATCH] v1.8 --- changelog.rst | 7 +++++++ docs/reference/index.rst | 1 + docs/reference/math.rst | 10 ++++++++++ ufp/__init__.py | 2 +- ufp/list.py | 11 +++++++++++ ufp/math.py | 22 ++++++++++++++++++++++ 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100755 docs/reference/math.rst create mode 100755 ufp/math.py diff --git a/changelog.rst b/changelog.rst index bb45674..10bd160 100644 --- a/changelog.rst +++ b/changelog.rst @@ -1,6 +1,13 @@ 변경사항 ============== +v1.8 +------- + ++ ufp.math 모듈 추가함. [`tb69wn6127`_] ++ ufp.math 모듈에 rshift함수 추가함. [`tb69wn6127`_] ++ ufp.list 모듈에 preallocate 함수 추가함. [`tb69wn6127`_] + v1.7.1 ------- diff --git a/docs/reference/index.rst b/docs/reference/index.rst index 5ef2ed8..2067078 100644 --- a/docs/reference/index.rst +++ b/docs/reference/index.rst @@ -11,6 +11,7 @@ dict path pdf + math list descriptor random diff --git a/docs/reference/math.rst b/docs/reference/math.rst new file mode 100755 index 0000000..802daf6 --- /dev/null +++ b/docs/reference/math.rst @@ -0,0 +1,10 @@ +.. py:module:: ufp.math +.. py:currentmodule:: ufp.math + +:py:mod:`math` 모듈 +========================== + +.. automodule:: ufp.math + :members: + :undoc-members: + :show-inheritance: diff --git a/ufp/__init__.py b/ufp/__init__.py index 924b39c..5cfff11 100755 --- a/ufp/__init__.py +++ b/ufp/__init__.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, absolute_import __title__ = 'ufp' -__version__ = '1.7.1' +__version__ = '1.8' __author__ = '별님' __author_email__ = 'w7dn1ng75r@gmail.com' __license__ = 'GPL v3' diff --git a/ufp/list.py b/ufp/list.py index c5db135..4147a10 100755 --- a/ufp/list.py +++ b/ufp/list.py @@ -3,6 +3,17 @@ from __future__ import unicode_literals, absolute_import, division, print_function +def preallocate(size, value=None): + """ + size 만큼의 길이를 가진 list를 반환합니다. 리스트의 내용은 value로 채워집니다. + + :param size: 할당 할 크기. + :type size: int + :param value: 초기화 할 값. + :return: size만큼 할당 된 list. + """ + return size * [value] + def chunks(list, step): """ list를 step 단위로 묶어 yield합니다. diff --git a/ufp/math.py b/ufp/math.py new file mode 100755 index 0000000..f55068e --- /dev/null +++ b/ufp/math.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- + +from __future__ import unicode_literals, absolute_import, division, print_function + +def urshift(val, n): + """ + 부호 없이 식을 비트 단위로 오른쪽으로 이동합니다. + + 자바스크립트의 >>> 연산자와 같은 역할을 합니다. 예를 들어 '(-1000) >>> 3'는 'ufp.math.rshift(-1000, 3)'와 같습니다. + + .. 참조 : http://stackoverflow.com/questions/5832982/how-to-get-the-logical-right-binary-shift-in-python + + :param val: 식 + :param n: 비트 수 + :return: 부호 없이 식을 비트 단위로 오른쪽으로 이동한 결과 값. + """ + if val >= 0: + return val >> n + else: + return ( val + 0x100000000 ) >> n + pass