-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Since the solution is now specific to Python, I suggest continuing on the pysqlite/APSW mailing list - http://itsystementwicklung.de/cgi-bin/mailman/listinfo/list-pysqlite and http://news.gmane.org/gmane.comp.python.db.pysqlite.user
Le Hyaric Bruno wrote: > def blob_and(b1,b2): > op1 = str(b1) > op2 = str(b2) > i = 0 > result = str() > for char in op1: > result = result + chr(ord(char) & ord(op2[i])) > i = i + 1 > return buffer(result) A few things wrong with this. There is no need to convert the parameters to str - you can iterate over the buffers directly. That is a horrendous way of doing string concatenation :-) Lastly this code assumes that the parameters are exactly the same length - it will throw an exception if b2 is shorter than b1 and ignore any part of b2 that is longer than b1! This code is closer to being conceptually right although there many optimisations that can be done: def blob_byte_and(left, right): if left is None or right is None: return 0 return left & right def blob_byte_or(left, right): if left is None: return right if right is None: return left return left | right def blob_operate(method, left, right): result=array.array('B', [a for a in map(method, [ord(x) for x in left], [ord(y) for y in right])]) return buffer(result) Example use: blob_operate(blob_byte_and, b1, b2) If you are using Python 2.5+ then you can replace all the [] with () which will drastically cut down on memory usage. If performance is at all an issue then you'd get the best bang for the buck by coding the functions in C which won't require round trips through Python data types or iteration over them. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkpnVPsACgkQmOOfHg372QSVWQCghE/usAqCb4i/uwAzLbN4VJxC FRgAn21WSl0O9mUsROfCS3mQr/3g7XaC =AohF -----END PGP SIGNATURE----- _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users