~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
catacomb/__init__.py: Add `KeySZ.pad' method.
[catacomb-python]
/
catacomb
/
__init__.py
diff --git
a/catacomb/__init__.py
b/catacomb/__init__.py
index
02e19d3
..
bb7703e
100644
(file)
--- 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 __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:
_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, ')')
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
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:
_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
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)
###--------------------------------------------------------------------------
_augment(KeySZSet, _tmp)
###--------------------------------------------------------------------------