I am new to ZOPE, so maybe this question is too simple: I would like to use a BTRee (OOBTree) to store information. For one type of sub-branch, I would like to use a continuous series of integers as keys: dbroot['SE_HMI']={ '2003' : { 'jrl' : { 0 : <a tuple of data>}} dbroot['SE_HMI']={ '2003' : { 'jrl' : { 1 : <a tuple of data>}} dbroot['SE_HMI']={ '2003' : { 'jrl' : { 2 : <a tuple of data>}} ... and so on ... all other branches besides 'jrl' will have string keys. I read in the ZODB,ZEO programming guide (www.zope.org/Wikis/ZODB/guide/) that you should only use objects of a SINGLE type as keys. I could write a generator, that would create strings, by counting from 0 to 255, however, that would destroy the sort order, because 'ABX' would sort before 'X', allthough it would represent a much larger number. Since the frequency of expected accesses will increase with the count (because the later records will be accessed more frequently), I expect that performance would be lower as the keys would end up in an unsorted manner. The same problem occurs with strings representing numbers, due to the sort order: cmp('123','2') , cmp(123,2) , "/" , cmp('ABX','X') (-1, 1, '/', -1) Does anybody have any experience with this problem ?
On Fri, Oct 31, 2003 at 05:41:12PM +0900, Harm_Kirchhoff@mail.digital.co.jp wrote:
I am new to ZOPE, so maybe this question is too simple:
I would like to use a BTRee (OOBTree) to store information. For one type of sub-branch, I would like to use a continuous series of integers as keys:
dbroot['SE_HMI']={ '2003' : { 'jrl' : { 0 : <a tuple of data>}} dbroot['SE_HMI']={ '2003' : { 'jrl' : { 1 : <a tuple of data>}} dbroot['SE_HMI']={ '2003' : { 'jrl' : { 2 : <a tuple of data>}} ... and so on ...
all other branches besides 'jrl' will have string keys.
I read in the ZODB,ZEO programming guide (www.zope.org/Wikis/ZODB/guide/) that you should only use objects of a SINGLE type as keys.
I could write a generator, that would create strings, by counting from 0 to 255, however, that would destroy the sort order, because 'ABX' would sort before 'X', allthough it would represent a much larger number.
Pad with zeroes and it'll sort numerically. Like this:
import string keys = [string.zfill(str(i), 3) for i in range(255)] keys.sort() keys[:15] ['000', '001', '002', '003', '004', '005', '006', '007', '008', '009', '010', '011', '012', '013', '014'] keys[-10:] ['245', '246', '247', '248', '249', '250', '251', '252', '253', '254']
-- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's ULTRA MAN! (random hero from isometric.spaceninja.com)
Harm_Kirchhoff@mail.digital.co.jp wrote at 2003-10-31 17:41 +0900:
I am new to ZOPE, so maybe this question is too simple:
I would like to use a BTRee (OOBTree) to store information. For one type of sub-branch, I would like to use a continuous series of integers as keys:
dbroot['SE_HMI']={ '2003' : { 'jrl' : { 0 : <a tuple of data>}} dbroot['SE_HMI']={ '2003' : { 'jrl' : { 1 : <a tuple of data>}} dbroot['SE_HMI']={ '2003' : { 'jrl' : { 2 : <a tuple of data>}} ... and so on ...
all other branches besides 'jrl' will have string keys.
I read in the ZODB,ZEO programming guide (www.zope.org/Wikis/ZODB/guide/) that you should only use objects of a SINGLE type as keys.
Mixing keys may no longer be a problem for Python 2.3. Python 2.3 compares objects of different types first by type name and then by id. This is a persistent order and could be used in BTrees. However, Python does not specify ordering. Later Python version may change the ordering and this would corrupt your BTrees. -- Dieter
participants (3)
-
Dieter Maurer -
Harm_Kirchhoff@mail.digital.co.jp -
Paul Winkler