Jim Fulton wrote:
Right, but to manage the integer ids, we need to be able to turn objects
into keys, since many objects are not valid keys.  The key reference
framework provides a way to generate keys from objects.  The key reference
adapter for persistent objects has the extremely inconvenient property
that you can't compute a key reference for a persistent object until
it has been added to a database.  Key references based on guids wouldn't
have this negative property.


Oh, now I see where GUIDs came in. I would instead propose to make key references not dependent on OIDs. I would just define a light-weight way of generating lots of guaranteed-unique IDs. Something like this, perhaps (this particular implementation requires Python 2.4):

NUM_ID_BITS = 64
BIGGEST_ID = (2 << (NUM_ID_BITS + 1) - 1)
NUM_TIME_BITS = 48
BIGGEST_TIME = (2 << (NUM_TIME_BITS + 1) - 1)

def getTime():
    result = int(time.time()*1000)
    assert result <= BIGGEST_TIME
    return result

def ids():
    last_time = None
    while True:
        current_time = getTime()
        if current_time != last_time:
            counter = 0
        else:
            counter += 1

        result = current_time << (NUM_ID_BITS-NUM_TIME_BITS) | counter
        assert result <= BIGGEST_ID
        yield result
        last_time = current_time

getId = ids().next

This give you as many unique IDs you could need, but the resulting ID would have to be stored on the object, just like the GUID would.
--
Benji York
Sr. Software Engineer
Zope Corporation
_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to