X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/bb5c23a4b4d9e74be11097381ba20a903e6ad1a2..dfb915d33e3733296899366ee27ba1344743c3e5:/catacomb/__init__.py diff --git a/catacomb/__init__.py b/catacomb/__init__.py index 02e19d3..bb7703e 100644 --- a/catacomb/__init__.py +++ b/catacomb/__init__.py @@ -549,6 +549,7 @@ class _tmp: def __repr__(me): return '%s(%d)' % (_clsname(me), me.default) def check(me, sz): return True def best(me, sz): return sz + def pad(me, sz): return sz _augment(KeySZAny, _tmp) class _tmp: @@ -565,11 +566,15 @@ class _tmp: pp.pretty(me.max); pp.text(','); pp.breakable() pp.pretty(me.mod) pp.end_group(ind, ')') - def check(me, sz): return me.min <= sz <= me.max and sz % me.mod == 0 + def check(me, sz): return me.min <= sz <= me.max and sz%me.mod == 0 def best(me, sz): if sz < me.min: raise ValueError, 'key too small' elif sz > me.max: return me.max - else: return sz - (sz % me.mod) + else: return sz - sz%me.mod + def pad(me, sz): + if sz > me.max: raise ValueError, 'key too large' + elif sz < me.min: return me.min + else: sz += me.mod; return sz - sz%me.mod _augment(KeySZRange, _tmp) class _tmp: @@ -591,6 +596,12 @@ class _tmp: if found < i <= sz: found = i if found < 0: raise ValueError, 'key too small' return found + def pad(me, sz): + found = -1 + for i in me.set: + if sz <= i and (found == -1 or i < found): found = i + if found < 0: raise ValueError, 'key too large' + return found _augment(KeySZSet, _tmp) ###--------------------------------------------------------------------------