Dolda2000 GitWeb
/
didex.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
61b6554
)
Added index type for case-folded strings.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Mon, 6 Apr 2015 01:46:35 +0000
(
03:46
+0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Mon, 6 Apr 2015 01:46:35 +0000
(
03:46
+0200)
didex/index.py
patch
|
blob
|
blame
|
history
diff --git
a/didex/index.py
b/didex/index.py
index
65b1b12
..
c2c55b6
100644
(file)
--- a/
didex/index.py
+++ b/
didex/index.py
@@
-2,7
+2,7
@@
import struct, contextlib, math
from . import db, lib
from .db import bd, txnfun, dloopfun
from . import db, lib
from .db import bd, txnfun, dloopfun
-__all__ = ["maybe", "t_int", "t_uint", "t_dbid", "t_float", "t_str", "ordered"]
+__all__ = ["maybe", "t_int", "t_uint", "t_dbid", "t_float", "t_str", "
t_casestr", "
ordered"]
deadlock = bd.DBLockDeadlockError
notfound = bd.DBNotFoundError
deadlock = bd.DBLockDeadlockError
notfound = bd.DBNotFoundError
@@
-29,6
+29,14
@@
class simpletype(object):
return cls(lambda ob: struct.pack(fmt, ob),
lambda dat: struct.unpack(fmt, dat)[0])
return cls(lambda ob: struct.pack(fmt, ob),
lambda dat: struct.unpack(fmt, dat)[0])
+class foldtype(simpletype):
+ def __init__(self, encode, decode, fold):
+ super().__init__(encode, decode)
+ self.fold = fold
+
+ def compare(self, a, b):
+ return super().compare(self.fold(a), self.fold(b))
+
class maybe(object):
def __init__(self, bk):
self.bk = bk
class maybe(object):
def __init__(self, bk):
self.bk = bk
@@
-138,6
+146,8
@@
t_dbid = t_uint
t_float = simpletype.struct(">d")
t_float.compare = floatcmp
t_str = simpletype((lambda ob: ob.encode("utf-8")), (lambda dat: dat.decode("utf-8")))
t_float = simpletype.struct(">d")
t_float.compare = floatcmp
t_str = simpletype((lambda ob: ob.encode("utf-8")), (lambda dat: dat.decode("utf-8")))
+t_casestr = foldtype((lambda ob: ob.encode("utf-8")), (lambda dat: dat.decode("utf-8")),
+ (lambda st: st.lower()))
class index(object):
def __init__(self, db, name, datatype):
class index(object):
def __init__(self, db, name, datatype):