From 9981ff277fb9f5b01771176250267574782d59f9 Mon Sep 17 00:00:00 2001 From: lash Date: Mon, 31 Jan 2022 09:33:21 +0000 Subject: [PATCH] Fix faulty module name in test, enforce cursor on have --- CHANGELOG | 2 ++ setup.cfg | 27 +++++++++++++++++++ setup.py | 3 +++ {schiz => shep}/__init__.py | 0 {schiz => shep}/error.py | 0 {schiz => shep}/state.py | 52 +++++++++++++++++++++++-------------- tests/test_report.py | 4 +-- tests/test_state.py | 6 ++--- 8 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 setup.cfg create mode 100644 setup.py rename {schiz => shep}/__init__.py (100%) rename {schiz => shep}/error.py (100%) rename {schiz => shep}/state.py (73%) diff --git a/CHANGELOG b/CHANGELOG index 7a0cb66..999e100 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,4 @@ +- 0.0.2 + * Fix rename module name errors - 0.0.1 * Add bases states and aliases diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..b3b36e3 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,27 @@ +[metadata] +name = shep +version = 0.0.1 +description = Multi-state key value stores using bitmaskings +author = Louis Holbrook +author_email = dev@holbrook.no +url = https://git.defalsify.org/python-shep +keywords = + dict + queue +classifiers = + Programming Language :: Python :: 3 + Operating System :: OS Independent + Development Status :: 3 - Alpha + Topic :: Software Development :: Libraries + Intended Audience :: Developers + License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+) +# Topic :: Blockchain :: EVM +license = GPL3 +licence_files = + LICENSE + +[options] +include_package_data = True +python_requires = >= 3.6 +packages = + shep diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6068493 --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +from setuptools import setup + +setup() diff --git a/schiz/__init__.py b/shep/__init__.py similarity index 100% rename from schiz/__init__.py rename to shep/__init__.py diff --git a/schiz/error.py b/shep/error.py similarity index 100% rename from schiz/error.py rename to shep/error.py diff --git a/schiz/state.py b/shep/state.py similarity index 73% rename from schiz/state.py rename to shep/state.py index 7e3b508..076f1bd 100644 --- a/schiz/state.py +++ b/shep/state.py @@ -3,7 +3,7 @@ import enum import logging # local imports -from schiz.error import ( +from shep.error import ( StateExists, StateInvalid, ) @@ -44,30 +44,25 @@ class State: return k - def __check_cover(self, v): - z = 0 - c = 1 - for i in range(self.__bits): - if c & v > 0: - if self.__reverse.get(c) == None: - raise StateInvalid(v) - c <<= 1 - return c == v - - - def __check_value(self, v): + def __check_valid(self, v): v = int(v) if self.__reverse.get(v): raise StateValueExists(v) + return v + + + def __check_value(self, v): + v = self.__check_valid(v) if v > self.__limit: raise OverflowError(v) return v - def __check(self, k, v): - k = self.__check_name(k) - v = self.__check_value(v) - return (k, v,) + def __check_value_cursor(self, v): + v = self.__check_valid(v) + if v > 1 << self.__c: + raise StateInvalid(v) + return v def __set(self, k, v): @@ -78,15 +73,16 @@ class State: def add(self, k): v = 1 << self.__c - (k, v) = self.__check(k, v) + k = self.__check_name(k) + v = self.__check_value(v) self.__set(k, v) def alias(self, k, v): - (k, v) = self.__check(k, v) + k = self.__check_name(k) + v = self.__check_value_cursor(v) if self.__is_pure(v): raise ValueError('use add to add pure values') - self.__check_cover(v) self.__set(k, v) @@ -100,3 +96,19 @@ class State: l.append(k) l.sort() return l + + + def have(self, v): + r = [] + m = self.__reverse.get(k) + if m != None: + r.append(m) + c = 1 + for i in range(self.__bits): + if v & c > 0: + self.__check_value_cursor(c) + k = self.__reverse[c] + r.append(k) + c <<= 1 + + return r diff --git a/tests/test_report.py b/tests/test_report.py index 2263ab1..7732c84 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -2,8 +2,8 @@ import unittest # local imports -from schiz import State -from schiz.error import ( +from shep import State +from shep.error import ( StateExists, StateInvalid, ) diff --git a/tests/test_state.py b/tests/test_state.py index 82fde3c..09d7d01 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -2,8 +2,8 @@ import unittest # local imports -from schiz import State -from schiz.error import ( +from shep import State +from shep.error import ( StateExists, StateInvalid, ) @@ -65,7 +65,7 @@ class TestState(unittest.TestCase): def test_alias_nopure(self): states = State(3) with self.assertRaises(ValueError): - states.alias('foo', 4) + states.alias('foo', 1) def test_alias_cover(self):